Add CRUD for other entities
This commit is contained in:
parent
f87bcc43a5
commit
a3e8b89128
64 changed files with 949 additions and 62 deletions
|
|
@ -0,0 +1,44 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { Create as InternalCreate } from "@/app/_components/Create";
|
||||
import { addWebhookAction } from "../../_actions/webhooks";
|
||||
|
||||
export const Create: FC = () => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: {
|
||||
name: "",
|
||||
description: "",
|
||||
one: "",
|
||||
},
|
||||
};
|
||||
const [formState, formAction] = useFormState(addWebhookAction, initialState);
|
||||
|
||||
return (
|
||||
<InternalCreate
|
||||
title="Create Webhook"
|
||||
entity="webhooks"
|
||||
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 item xs={12}>
|
||||
<TextField
|
||||
name="description"
|
||||
label="Description"
|
||||
formState={formState}
|
||||
lines={3}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalCreate>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Grid } from "@mui/material";
|
||||
import { DisplayTextField } from "ui";
|
||||
import { Webhook } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { deleteWebhookAction } from "../../_actions/webhooks";
|
||||
|
||||
type DetailProps = {
|
||||
row: Webhook;
|
||||
};
|
||||
|
||||
export const Detail: FC<DetailProps> = ({ row }) => (
|
||||
<InternalDetail
|
||||
title={`Webhook: ${row.name}`}
|
||||
entity="webhooks"
|
||||
id={row.id}
|
||||
deleteAction={deleteWebhookAction}
|
||||
>
|
||||
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
|
||||
<Grid item xs={12}>
|
||||
<DisplayTextField name="name" label="Name" value={row.name} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<DisplayTextField
|
||||
name="description"
|
||||
label="Description"
|
||||
lines={3}
|
||||
value={row.description}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalDetail>
|
||||
);
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { db } from "@/app/_lib/database";
|
||||
import { Detail } from "./_components/Detail";
|
||||
|
||||
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("Webhook")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Detail row={row} />;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { Webhook } from "@/app/_lib/database";
|
||||
import { Edit as InternalEdit } from "@/app/_components/Edit";
|
||||
import { updateWebhookAction } from "../../_actions/webhooks";
|
||||
|
||||
type EditProps = {
|
||||
row: Webhook;
|
||||
};
|
||||
|
||||
export const Edit: FC<EditProps> = ({ row }) => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: row,
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
updateWebhookAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalEdit
|
||||
title={`Edit Webhook: ${row.name}`}
|
||||
entity="webhooks"
|
||||
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 item xs={12}>
|
||||
<TextField
|
||||
name="description"
|
||||
label="Description"
|
||||
formState={formState}
|
||||
lines={3}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalEdit>
|
||||
);
|
||||
};
|
||||
|
|
@ -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("Webhook")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Edit row={row} />;
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
Loading…
Add table
Add a link
Reference in a new issue