From f7dd75dca1e524df5241ad66c2943c07640c6c1b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 5 Apr 2022 12:04:15 +0200 Subject: [PATCH] (ui) refactor form components to use props inheritance --- .../authentication-provider/provider-form.tsx | 2 +- .../components/base/fab-multi-select.tsx | 17 ++++++---- .../javascript/components/base/fab-select.tsx | 17 ++++++---- .../javascript/components/base/rhf-input.tsx | 32 ++++--------------- .../src/javascript/models/form-component.ts | 24 ++++++++++++++ 5 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 app/frontend/src/javascript/models/form-component.ts diff --git a/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx b/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx index cfd6c9d9f..f628f7a92 100644 --- a/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx +++ b/app/frontend/src/javascript/components/authentication-provider/provider-form.tsx @@ -47,7 +47,7 @@ export const ProviderForm: React.FC = ({ action, provider, on return (
- + ); diff --git a/app/frontend/src/javascript/components/base/fab-multi-select.tsx b/app/frontend/src/javascript/components/base/fab-multi-select.tsx index 077b69b39..f17997a95 100644 --- a/app/frontend/src/javascript/components/base/fab-multi-select.tsx +++ b/app/frontend/src/javascript/components/base/fab-multi-select.tsx @@ -1,17 +1,14 @@ import React, { SelectHTMLAttributes } from 'react'; import Select from 'react-select'; import { Controller, Path } from 'react-hook-form'; -import { Control } from 'react-hook-form/dist/types/form'; import { FieldValues } from 'react-hook-form/dist/types/fields'; import { FieldPath } from 'react-hook-form/dist/types/path'; import { FieldPathValue, UnpackNestedValue } from 'react-hook-form/dist/types'; +import { FormControlledComponent } from '../../models/form-component'; -interface FabSelectProps extends SelectHTMLAttributes { +interface FabSelectProps extends SelectHTMLAttributes, FormControlledComponent { id: string, label?: string, - className?: string, - control: Control, - placeholder?: string, options: Array>, valuesDefault?: Array, } @@ -26,9 +23,15 @@ type selectOption = { value: TOptionValue, label: string }; * This component is a wrapper around react-select to use with react-hook-form. * It is a multi-select component. */ -export const FabMultiSelect = ({ id, label, className, control, placeholder, options, valuesDefault }: FabSelectProps) => { +export const FabMultiSelect = ({ id, label, className, control, placeholder, options, valuesDefault, error, rules, disabled }: FabSelectProps) => { + const classNames = ` + fab-multi-select ${className || ''} + ${error && error[id] ? 'is-incorrect' : ''} + ${rules && rules.required ? 'is-required' : ''} + ${disabled ? 'is-disabled' : ''}`; + return ( -