@@ -19,6 +19,9 @@ import Stack from '@mui/material/Stack';
1919import { Widget } from './Widget' ;
2020import { AccordionHeader } from './AccordionHeader' ;
2121import { Typography } from '@mui/material' ;
22+ import type { Control } from 'react-hook-form' ;
23+ import { type InputsType } from '~/routes/configuration' ;
24+ import { KEY_SEPARATOR } from './constants' ;
2225
2326export type FormItem = { [ key : string ] : string | object | FormItem } ;
2427
@@ -28,8 +31,10 @@ export type FormRestrictions = {
2831
2932interface FormProps extends PropsWithChildren {
3033 sectionTitle : string ;
34+ sectionPrefix : string ;
3135 items : FormItem ;
3236 itemsRestrictions : FormRestrictions ;
37+ control : Control < InputsType > ;
3338}
3439
3540/**
@@ -45,7 +50,23 @@ function isFormRestrictions(obj: FormRestrictions[string]): obj is FormRestricti
4550 return obj instanceof Object && ! ( obj instanceof Array ) ;
4651}
4752
48- export const Form : FC < FormProps > = ( { sectionTitle, items, itemsRestrictions } ) => {
53+ /**
54+ * Form component.
55+ * @param {FormProps } props - The props of the form.
56+ * @param {string } props.sectionTitle - The title of the section.
57+ * @param {string } props.sectionPrefix - The prefix of the section.
58+ * @param {FormItem } props.items - The items of the form.
59+ * @param {FormRestrictions } props.itemsRestrictions - The restrictions of the items.
60+ * @param {Control<InputsType> } props.control - The control of the form.
61+ * @returns {ReactElement } The form component.
62+ */
63+ export const Form : FC < FormProps > = ( {
64+ sectionTitle,
65+ sectionPrefix,
66+ items,
67+ itemsRestrictions,
68+ control,
69+ } ) => {
4970 const [ viewForm , setViewForm ] = useState < boolean > ( true ) ;
5071
5172 const renderItem = useCallback (
@@ -54,11 +75,20 @@ export const Form: FC<FormProps> = ({ sectionTitle, items, itemsRestrictions })
5475 < Form
5576 key = { key }
5677 sectionTitle = { key }
78+ sectionPrefix = { `${ sectionPrefix } ${ KEY_SEPARATOR } ${ key } ` }
5779 items = { items [ key ] as FormItem }
5880 itemsRestrictions = { itemsRestrictions [ key ] as FormRestrictions }
81+ control = { control }
5982 />
6083 ) : (
61- < Widget key = { key } title = { key } type = { value } value = { items [ key ] } />
84+ < Widget
85+ key = { key }
86+ sectionPrefix = { `${ sectionPrefix } ${ KEY_SEPARATOR } ${ key } ` }
87+ label = { key }
88+ type = { value }
89+ value = { items [ key ] }
90+ control = { control }
91+ />
6292 ) ,
6393 [ items , itemsRestrictions ] ,
6494 ) ;
0 commit comments