"use client"; import { FC } from "react"; import { useFormState } from "react-dom"; import { Grid } from "@mui/material"; import { TextField } from "ui"; import { Create as InternalCreate } from "@/app/_components/Create"; import { generateCreateAction } from "@/app/_lib/actions"; import { serviceConfig } from "@/app/_lib/config"; import { FieldDescription } from "@/app/_lib/service"; type CreateProps = { service: string; }; export const Create: FC = ({ service }) => { const { [service]: { entity, table, displayName, createFields: fields }, } = serviceConfig; const createAction = generateCreateAction({ entity, table, fields }); const initialState = { message: null, errors: {}, values: fields.reduce( (acc: Record, field: FieldDescription) => { acc[field.name] = field.defaultValue; return acc; }, {}, ), }; const [formState, formAction] = useFormState(createAction, initialState); return ( {fields.map((field) => ( ))} ); };