"use client"; import { FC } from "react"; import { useFormState } from "react-dom"; import { Grid } from "@mui/material"; import { TextField } from "ui"; import { Selectable } from "kysely"; import { Database } from "@/app/_lib/database"; import { Edit as InternalEdit } from "@/app/_components/Edit"; import { generateUpdateAction } from "@/app/_lib/actions"; import { serviceConfig } from "@/app/_lib/config"; type EditProps = { service: string; row: Selectable; }; export const Edit: FC = ({ service, row }) => { const { [service]: { entity, table, displayName, updateFields: fields }, } = serviceConfig; const updateFieldNames = fields.map((val) => val.name); const updateAction = generateUpdateAction({ entity, table, fields }); const updateValues = Object.fromEntries( Object.entries(row).filter(([key]) => updateFieldNames.includes(key)), ); updateValues.id = row.id; const initialState = { message: null, errors: {}, values: updateValues, }; const [formState, formAction] = useFormState(updateAction, initialState); return ( {fields.map((field) => ( ))} ); };