Finish bridge generalization

This commit is contained in:
Darren Clarke 2024-04-26 15:49:58 +02:00
parent cb7a3a08dc
commit cca8d03988
93 changed files with 634 additions and 2085 deletions

View file

@ -21,14 +21,15 @@ export const Edit: FC<EditProps> = ({ service, row }) => {
} = 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: Object.fromEntries(
Object.entries(row).filter(([key]) => updateFieldNames.includes(key)),
),
values: updateValues,
};
console.log("initialState", initialState);
const [formState, formAction] = useFormState(updateAction, initialState);
return (
@ -40,11 +41,11 @@ export const Edit: FC<EditProps> = ({ service, row }) => {
>
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
{fields.map((field) => (
<Grid item xs={field.size ?? 6}>
<Grid key={field.name} item xs={field.size ?? 6}>
<TextField
key={field.name}
name={field.name}
label={field.label}
lines={field.lines ?? 1}
required={field.required ?? false}
formState={formState}
helperText={field.helperText}

View file

@ -3,13 +3,12 @@ import { serviceConfig } from "@/app/_lib/config";
import { Edit } from "./_components/Edit";
type PageProps = {
params: { service: string; segment: string[] };
params: { segment: string[] };
};
export default async function Page({
params: { service, segment },
}: PageProps) {
const id = segment?.[0];
export default async function Page({ params: { segment } }: PageProps) {
const service = segment[0];
const id = segment?.[1];
if (!id) return null;