Refactoring
This commit is contained in:
parent
39cfada3e8
commit
dd14dfe72e
41 changed files with 866 additions and 742 deletions
|
|
@ -3,10 +3,10 @@
|
|||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { TextField, Select, MultiValueField } from "ui";
|
||||
import { Create as InternalCreate } from "@/app/_components/Create";
|
||||
import { generateCreateAction } from "@/app/_lib/actions";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
import { FieldDescription } from "@/app/_lib/service";
|
||||
|
||||
type CreateProps = {
|
||||
|
|
@ -15,8 +15,18 @@ type CreateProps = {
|
|||
|
||||
export const Create: FC<CreateProps> = ({ service }) => {
|
||||
const {
|
||||
[service]: { entity, table, displayName, createFields: fields },
|
||||
[service]: { entity, table, displayName, createFields },
|
||||
} = serviceConfig;
|
||||
const fields = createFields.map((field: any) => {
|
||||
const copy = { ...field };
|
||||
Object.keys(copy).forEach((key: any) => {
|
||||
if (typeof copy[key] === "function") {
|
||||
delete copy[key];
|
||||
}
|
||||
});
|
||||
return copy;
|
||||
});
|
||||
|
||||
const createAction = generateCreateAction({ entity, table, fields });
|
||||
const initialState = {
|
||||
message: null,
|
||||
|
|
@ -39,18 +49,37 @@ export const Create: FC<CreateProps> = ({ service }) => {
|
|||
formState={formState}
|
||||
>
|
||||
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
|
||||
{fields.map(
|
||||
{createFields.map(
|
||||
(field) =>
|
||||
!field.hidden && (
|
||||
<Grid key={field.name} item xs={field.size ?? 6}>
|
||||
<TextField
|
||||
name={field.name}
|
||||
label={field.label}
|
||||
lines={field.lines ?? 1}
|
||||
required={field.required ?? false}
|
||||
formState={formState}
|
||||
helperText={field.helperText}
|
||||
/>
|
||||
{field.kind === "select" && (
|
||||
<Select
|
||||
name={field.name}
|
||||
label={field.label}
|
||||
required={field.required ?? false}
|
||||
formState={formState}
|
||||
getOptions={field.getOptions}
|
||||
/>
|
||||
)}
|
||||
{field.kind === "multi" && (
|
||||
<MultiValueField
|
||||
name={field.name}
|
||||
label={field.label}
|
||||
formState={formState}
|
||||
helperText={field.helperText}
|
||||
/>
|
||||
)}
|
||||
{(!field.kind || field.kind === "text") && (
|
||||
<TextField
|
||||
name={field.name}
|
||||
label={field.label}
|
||||
lines={field.lines ?? 1}
|
||||
required={field.required ?? false}
|
||||
formState={formState}
|
||||
helperText={field.helperText}
|
||||
/>
|
||||
)}
|
||||
</Grid>
|
||||
),
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { Selectable } from "kysely";
|
|||
import { Database } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { generateDeleteAction } from "@/app/_lib/actions";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
|
||||
type DetailProps = {
|
||||
service: string;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { db } from "@/app/_lib/database";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
import { Detail } from "./_components/Detail";
|
||||
|
||||
type Props = {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ 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";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
|
||||
type EditProps = {
|
||||
service: string;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { db } from "@/app/_lib/database";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
import { Edit } from "./_components/Edit";
|
||||
|
||||
type PageProps = {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { FC } from "react";
|
|||
import { List as InternalList } from "@/app/_components/List";
|
||||
import type { Selectable } from "kysely";
|
||||
import { Database } from "@/app/_lib/database";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
|
||||
type ListProps = {
|
||||
service: string;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { List } from "./_components/List";
|
||||
import { db } from "@/app/_lib/database";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
import { serviceConfig } from "@/app/_config/config";
|
||||
|
||||
type PageProps = {
|
||||
params: {
|
||||
|
|
@ -11,7 +11,12 @@ type PageProps = {
|
|||
export default async function Page({ params: { segment } }: PageProps) {
|
||||
const service = segment[0];
|
||||
|
||||
if (!service) return null;
|
||||
|
||||
const config = serviceConfig[service];
|
||||
|
||||
if (!config) return null;
|
||||
|
||||
const rows = await db.selectFrom(config.table).selectAll().execute();
|
||||
|
||||
return <List service={service} rows={rows} />;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue