Add CRUD for other entities

This commit is contained in:
Darren Clarke 2024-04-25 13:36:50 +02:00
parent f87bcc43a5
commit a3e8b89128
64 changed files with 949 additions and 62 deletions

View file

@ -0,0 +1,37 @@
"use client";
import { FC } from "react";
import { useFormState } from "react-dom";
import { Grid } from "@mui/material";
import { TextField } from "ui";
import { User } from "@/app/_lib/database";
import { Edit as InternalEdit } from "@/app/_components/Edit";
import { updateUserAction } from "../../_actions/users";
type EditProps = {
row: User;
};
export const Edit: FC<EditProps> = ({ row }) => {
const initialState = {
message: null,
errors: {},
values: row,
};
const [formState, formAction] = useFormState(updateUserAction, initialState);
return (
<InternalEdit
title={`Edit User: ${row.name}`}
entity="users"
formAction={formAction}
formState={formState}
>
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
<Grid item xs={12}>
<TextField name="name" label="Name" required formState={formState} />
</Grid>
</Grid>
</InternalEdit>
);
};

View file

@ -0,0 +1,24 @@
import { db } from "@/app/_lib/database";
import { Edit } from "./_components/Edit";
export const dynamic = "force-dynamic";
type Props = {
params: { segment: string[] };
};
export default async function Page({ params: { segment } }: Props) {
const id = segment?.[0];
if (!id) return null;
const row = await db
.selectFrom("User")
.selectAll()
.where("id", "=", id)
.executeTakeFirst();
if (!row) return null;
return <Edit row={row} />;
}