import type { FormComponentProps } from '../types'; import type { MetaObject } from '@/api/ius/types'; import { mapFieldTypeElement } from '@/config/elements'; import { useFormStore } from '@/store/ius/form'; import { ElementContainer } from '@repo/ui'; import { get, omit } from 'radash'; import { useEffect } from 'react'; function RenderElement({ fieldType, label, max, min = 0, name, visible, ...props }: MetaObject & { readonly name: string }) { const { setValue, validation, values } = useFormStore(); if (!visible) return false; const Element = mapFieldTypeElement[fieldType]; return ( { setValue({ name, value: fieldType === 'CHECKBOX' ? (e.target as HTMLInputElement).checked : e.target.value, }); }} {...props} /> ); } export function Elements({ data, metaData }: FormComponentProps) { const { init } = useFormStore(); useEffect(() => { init(data); }, [data, init]); return ( <>
{(Object.keys(omit(metaData, ['comment'])) as Array).map((name) => ( ))}
); }