import type { App_RoutingForms_Form } from "@prisma/client"; import type { Dispatch, SetStateAction } from "react"; import { getQueryBuilderConfig } from "../lib/getQueryBuilderConfig"; import isRouterLinkedField from "../lib/isRouterLinkedField"; import type { SerializableForm, Response } from "../types/types"; type Props = { form: SerializableForm; response: Response; setResponse: Dispatch>; }; export default function FormInputFields(props: Props) { const { form, response, setResponse } = props; const queryBuilderConfig = getQueryBuilderConfig(form); return ( <> {form.fields?.map((field) => { if (isRouterLinkedField(field)) { // @ts-expect-error FIXME @hariombalhara field = field.routerField; } const widget = queryBuilderConfig.widgets[field.type]; if (!("factory" in widget)) { return null; } const Component = widget.factory; const optionValues = field.selectText?.trim().split("\n"); const options = optionValues?.map((value) => { const title = value; return { value, title, }; }); return (
{ setResponse((response) => { response = response || {}; return { ...response, [field.id]: { label: field.label, value, }, }; }); }} />
); })} ); }