Finish bridge generalization
This commit is contained in:
parent
cb7a3a08dc
commit
cca8d03988
93 changed files with 634 additions and 2085 deletions
|
|
@ -7,6 +7,7 @@ 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;
|
||||
|
|
@ -16,18 +17,18 @@ export const Create: FC<CreateProps> = ({ service }) => {
|
|||
const {
|
||||
[service]: { entity, table, displayName, createFields: fields },
|
||||
} = serviceConfig;
|
||||
const createFieldNames = fields.map((val) => val.name);
|
||||
const createAction = generateCreateAction({ entity, table, fields });
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: createFieldNames.reduce((acc, key) => {
|
||||
// @ts-expect-error
|
||||
acc[key] = fields[key].defaultValue;
|
||||
return acc;
|
||||
}, {}),
|
||||
values: fields.reduce(
|
||||
(acc: Record<string, any>, field: FieldDescription) => {
|
||||
acc[field.name] = field.defaultValue;
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
),
|
||||
};
|
||||
console.log("initialState", initialState);
|
||||
const [formState, formAction] = useFormState(createAction, initialState);
|
||||
|
||||
return (
|
||||
|
|
@ -39,11 +40,11 @@ export const Create: FC<CreateProps> = ({ service }) => {
|
|||
>
|
||||
<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}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
type PageProps = {
|
||||
params: { service: string };
|
||||
params: { segment: string[] };
|
||||
};
|
||||
|
||||
export default function Page({ params: { service } }: PageProps) {
|
||||
export default function Page({ params: { segment } }: PageProps) {
|
||||
const service = segment[0];
|
||||
|
||||
return <Create service={service} />;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue