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} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export const Detail: FC<DetailProps> = ({ service, row }) => {
|
|||
>
|
||||
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
|
||||
{fields.map((field) => (
|
||||
<Grid item xs={6} key={field.name}>
|
||||
<Grid item xs={field.size ?? 6} key={field.name}>
|
||||
<DisplayTextField
|
||||
name={field.name}
|
||||
label={field.label}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ import { serviceConfig } from "@/app/_lib/config";
|
|||
import { Detail } from "./_components/Detail";
|
||||
|
||||
type Props = {
|
||||
params: { service: string; segment: string[] };
|
||||
params: { segment: string[] };
|
||||
};
|
||||
|
||||
export default async function Page({ params: { service, segment } }: Props) {
|
||||
const id = segment?.[0];
|
||||
export default async function Page({ params: { segment } }: Props) {
|
||||
const service = segment[0];
|
||||
const id = segment?.[1];
|
||||
|
||||
if (!id) return null;
|
||||
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
// write a function that returns the addRecordAction
|
||||
|
||||
export function generateAddRecordAction(
|
||||
entity: string,
|
||||
table: string,
|
||||
fields: string[],
|
||||
) {
|
||||
// The returned function matches the signature of addRecordAction, but uses the parameters from the outer function.
|
||||
return async (currentState: any, formData: FormData) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields,
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const addRecordAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: [
|
||||
"name",
|
||||
"description",
|
||||
"appId",
|
||||
"appSecret",
|
||||
"pageId",
|
||||
"pageAccessToken",
|
||||
],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateFacebookBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: [
|
||||
"name",
|
||||
"description",
|
||||
"appId",
|
||||
"appSecret",
|
||||
"pageId",
|
||||
"pageAccessToken",
|
||||
],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteFacebookBotAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -16,7 +16,7 @@ export const List: FC<ListProps> = ({ service, rows }) => {
|
|||
|
||||
return (
|
||||
<InternalList
|
||||
title={displayName}
|
||||
title={`${displayName}s`}
|
||||
entity={entity}
|
||||
rows={rows}
|
||||
columns={listColumns}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ type ServiceLayoutProps = {
|
|||
};
|
||||
};
|
||||
|
||||
export const ServiceLayout = ({
|
||||
export default function ServiceLayout({
|
||||
children,
|
||||
detail,
|
||||
edit,
|
||||
create,
|
||||
params: { segment },
|
||||
}: ServiceLayoutProps) => {
|
||||
}: ServiceLayoutProps) {
|
||||
const length = segment?.length ?? 0;
|
||||
const isCreate = length === 2 && segment[1] === "create";
|
||||
const isEdit = length === 3 && segment[2] === "edit";
|
||||
|
|
@ -29,4 +29,4 @@ export const ServiceLayout = ({
|
|||
{isCreate && create}
|
||||
</>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
// import { List } from "./_components/List";
|
||||
// import { db } from "@/app/_lib/database";
|
||||
// import { serviceConfig } from "@/app/_lib/config";
|
||||
import { List } from "./_components/List";
|
||||
import { db } from "@/app/_lib/database";
|
||||
import { serviceConfig } from "@/app/_lib/config";
|
||||
|
||||
type PageProps = {
|
||||
params: {
|
||||
service: string;
|
||||
segment: string[];
|
||||
};
|
||||
};
|
||||
|
||||
export default async function Page({ params: { service } }: PageProps) {
|
||||
console.log({ service });
|
||||
export default async function Page({ params: { segment } }: PageProps) {
|
||||
const service = segment[0];
|
||||
|
||||
return <h1> Nice</h1>;
|
||||
// const config = serviceConfig[service];
|
||||
// const rows = await db.selectFrom(config.table).selectAll().execute();
|
||||
const config = serviceConfig[service];
|
||||
const rows = await db.selectFrom(config.table).selectAll().execute();
|
||||
|
||||
// return <List service={service} rows={rows} />;
|
||||
return <List service={service} rows={rows} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
"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 { addFacebookBotAction } from "../../_actions/facebook";
|
||||
|
||||
export const Create: FC = () => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: {
|
||||
name: "",
|
||||
description: "",
|
||||
one: "",
|
||||
},
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
addFacebookBotAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalCreate
|
||||
title="Create Facebook Connection"
|
||||
entity="facebook"
|
||||
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 item xs={6}>
|
||||
<TextField
|
||||
name="appId"
|
||||
label="App ID"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="Get it from Facebook Developer Console"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="appSecret"
|
||||
label="App Secret"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="Get it from Facebook Developer Console"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="pageId"
|
||||
label="Page ID"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="Get it from Facebook Developer Console"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="pageAccessToken"
|
||||
label="Page Access Token"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="Get it from Facebook Developer Console"
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalCreate>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Grid } from "@mui/material";
|
||||
import { DisplayTextField } from "ui";
|
||||
import { FacebookBot } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { deleteFacebookBotAction } from "../../_actions/facebook";
|
||||
|
||||
type DetailProps = {
|
||||
row: FacebookBot;
|
||||
};
|
||||
|
||||
export const Detail: FC<DetailProps> = ({ row }) => (
|
||||
<InternalDetail
|
||||
title={`Facebook Connection: ${row.name}`}
|
||||
entity="facebook"
|
||||
id={row.id}
|
||||
deleteAction={deleteFacebookBotAction}
|
||||
>
|
||||
<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 item xs={6}>
|
||||
<DisplayTextField name="appId" label="App ID" value={row.appId} />
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<DisplayTextField
|
||||
name="appSecret"
|
||||
label="App Secret"
|
||||
value={row.appSecret}
|
||||
copyable
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<DisplayTextField name="pageId" label="Page ID" value={row.pageId} />
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<DisplayTextField
|
||||
name="pageAccessToken"
|
||||
label="Page Access Token"
|
||||
value={row.pageAccessToken}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalDetail>
|
||||
);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("FacebookBot")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Detail row={row} />;
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { FacebookBot } from "@/app/_lib/database";
|
||||
import { Edit as InternalEdit } from "@/app/_components/Edit";
|
||||
import { updateFacebookBotAction } from "../../_actions/facebook";
|
||||
|
||||
type EditProps = {
|
||||
row: FacebookBot;
|
||||
};
|
||||
|
||||
export const Edit: FC<EditProps> = ({ row }) => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: row,
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
updateFacebookBotAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalEdit
|
||||
title={`Edit Facebook Connection: ${row.name}`}
|
||||
entity="facebook"
|
||||
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 item xs={6}>
|
||||
<TextField
|
||||
name="token"
|
||||
label="Token"
|
||||
disabled
|
||||
formState={formState}
|
||||
refreshable
|
||||
helperText="Token used to authenticate requests from Link"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="verifyToken"
|
||||
label="Verify Token"
|
||||
disabled
|
||||
formState={formState}
|
||||
refreshable
|
||||
helperText="Token used to authenticate requests from Facebook"
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="appId"
|
||||
label="App ID"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="App ID of your approved Facebook application"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="appSecret"
|
||||
label="App Secret"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="App Secret of your approved Facebook application"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="pageId"
|
||||
label="Page ID"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="Page ID of the Facebook page that will receive messages"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<TextField
|
||||
name="pageAccessToken"
|
||||
label="Page Access Token"
|
||||
required
|
||||
formState={formState}
|
||||
helperText="Access Token of the Facbook page that will receive messages"
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalEdit>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("FacebookBot")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Edit row={row} />;
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
const entity = "facebook";
|
||||
const table = "FacebookBot";
|
||||
|
||||
export const addFacebookBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: [
|
||||
"name",
|
||||
"description",
|
||||
"appId",
|
||||
"appSecret",
|
||||
"pageId",
|
||||
"pageAccessToken",
|
||||
],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateFacebookBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: [
|
||||
"name",
|
||||
"description",
|
||||
"appId",
|
||||
"appSecret",
|
||||
"pageId",
|
||||
"pageAccessToken",
|
||||
],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteFacebookBotAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { GridColDef } from "@mui/x-data-grid-pro";
|
||||
import { List } from "@/app/_components/List";
|
||||
|
||||
type FacebookBotsListProps = {
|
||||
rows: any[];
|
||||
};
|
||||
|
||||
export const FacebookBotsList: FC<FacebookBotsListProps> = ({ rows }) => {
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "name",
|
||||
headerName: "Name",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "description",
|
||||
headerName: "Description",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "updatedAt",
|
||||
headerName: "Updated At",
|
||||
valueGetter: (value: any) => new Date(value).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<List
|
||||
title="Facebook Connections"
|
||||
entity="facebook"
|
||||
rows={rows}
|
||||
columns={columns}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import { FacebookBotsList } from "./_components/FacebookBotsList";
|
||||
import { db } from "@/app/_lib/database";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const rows = await db.selectFrom("FacebookBot").selectAll().execute();
|
||||
|
||||
return <FacebookBotsList rows={rows} />;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
"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 { addSignalBotAction } from "../../_actions/signal";
|
||||
|
||||
export const Create: FC = () => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: {
|
||||
name: "",
|
||||
description: "",
|
||||
one: "",
|
||||
},
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
addSignalBotAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalCreate
|
||||
title="Create Signal Connection"
|
||||
entity="signal"
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Grid } from "@mui/material";
|
||||
import { DisplayTextField } from "ui";
|
||||
import { SignalBot } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { deleteSignalBotAction } from "../../_actions/signal";
|
||||
|
||||
type DetailProps = {
|
||||
row: SignalBot;
|
||||
};
|
||||
|
||||
export const Detail: FC<DetailProps> = ({ row }) => (
|
||||
<InternalDetail
|
||||
title={`Signal Connection: ${row.name}`}
|
||||
entity="signal"
|
||||
id={row.id}
|
||||
deleteAction={deleteSignalBotAction}
|
||||
>
|
||||
<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>
|
||||
);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("SignalBot")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Detail row={row} />;
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { SignalBot } from "@/app/_lib/database";
|
||||
import { Edit as InternalEdit } from "@/app/_components/Edit";
|
||||
import { updateSignalBotAction } from "../../_actions/signal";
|
||||
|
||||
type EditProps = {
|
||||
row: SignalBot;
|
||||
};
|
||||
|
||||
export const Edit: FC<EditProps> = ({ row }) => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: row,
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
updateSignalBotAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalEdit
|
||||
title={`Edit Signal Connection: ${row.name}`}
|
||||
entity="signal"
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("SignalBot")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Edit row={row} />;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
const entity = "signal";
|
||||
const table = "SignalBot";
|
||||
|
||||
export const addSignalBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name", "description"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateSignalBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteSignalBotAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { GridColDef } from "@mui/x-data-grid-pro";
|
||||
import { List } from "@/app/_components/List";
|
||||
|
||||
type SignalBotsListProps = {
|
||||
rows: any[];
|
||||
};
|
||||
|
||||
export const SignalBotsList: FC<SignalBotsListProps> = ({ rows }) => {
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "name",
|
||||
headerName: "Name",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "phoneNumber",
|
||||
headerName: "Phone Number",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "description",
|
||||
headerName: "Description",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "updatedAt",
|
||||
headerName: "Updated At",
|
||||
valueGetter: (params: any) =>
|
||||
new Date(params.row?.updatedAt).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<List
|
||||
title="Signal Connections"
|
||||
entity="signal"
|
||||
rows={rows}
|
||||
columns={columns}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import { SignalBotsList } from "./_components/SignalBotsList";
|
||||
import { db } from "@/app/_lib/database";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const rows = await db.selectFrom("SignalBot").selectAll().execute();
|
||||
|
||||
return <SignalBotsList rows={rows} />;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
"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 { addUserAction } from "../../_actions/users";
|
||||
|
||||
export const Create: FC = () => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: {
|
||||
name: "",
|
||||
description: "",
|
||||
one: "",
|
||||
},
|
||||
};
|
||||
const [formState, formAction] = useFormState(addUserAction, initialState);
|
||||
|
||||
return (
|
||||
<InternalCreate
|
||||
title="Create User"
|
||||
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>
|
||||
</InternalCreate>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Grid } from "@mui/material";
|
||||
import { DisplayTextField } from "ui";
|
||||
import { User } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { deleteUserAction } from "../../_actions/users";
|
||||
|
||||
type DetailProps = {
|
||||
row: User;
|
||||
};
|
||||
|
||||
export const Detail: FC<DetailProps> = ({ row }) => (
|
||||
<InternalDetail
|
||||
title={`User: ${row.name}`}
|
||||
entity="users"
|
||||
id={row.id}
|
||||
deleteAction={deleteUserAction}
|
||||
>
|
||||
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
|
||||
<Grid item xs={12}>
|
||||
<DisplayTextField name="name" label="Name" value={row.name} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalDetail>
|
||||
);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("User")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Detail row={row} />;
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
"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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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} />;
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
const entity = "users";
|
||||
const table = "User";
|
||||
|
||||
export const addUserAction = async (currentState: any, formData: FormData) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateUserAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteUserAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { GridColDef } from "@mui/x-data-grid-pro";
|
||||
import { List } from "@/app/_components/List";
|
||||
|
||||
type UsersListProps = {
|
||||
rows: any[];
|
||||
};
|
||||
|
||||
export const UsersList: FC<UsersListProps> = ({ rows }) => {
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "name",
|
||||
headerName: "Name",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "email",
|
||||
headerName: "Email",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "emailVerified",
|
||||
headerName: "Verified",
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
|
||||
return <List title="Users" entity="users" rows={rows} columns={columns} />;
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import { UsersList } from "./_components/UsersList";
|
||||
import { db } from "@/app/_lib/database";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const rows = await db.selectFrom("User").selectAll().execute();
|
||||
console.log(rows);
|
||||
|
||||
return <UsersList rows={rows} />;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
"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 { addVoiceLineAction } from "../../_actions/voice";
|
||||
|
||||
export const Create: FC = () => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: {
|
||||
name: "",
|
||||
description: "",
|
||||
one: "",
|
||||
},
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
addVoiceLineAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalCreate
|
||||
title="Create Voice Connection"
|
||||
entity="voice"
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Grid } from "@mui/material";
|
||||
import { DisplayTextField } from "ui";
|
||||
import { VoiceLine } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { deleteVoiceLineAction } from "../../_actions/voice";
|
||||
|
||||
type DetailProps = {
|
||||
row: VoiceLine;
|
||||
};
|
||||
|
||||
export const Detail: FC<DetailProps> = ({ row }) => (
|
||||
<InternalDetail
|
||||
title={`Voice Line: ${row.name}`}
|
||||
entity="voice"
|
||||
id={row.id}
|
||||
deleteAction={deleteVoiceLineAction}
|
||||
>
|
||||
<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>
|
||||
);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("VoiceLine")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Detail row={row} />;
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { VoiceLine } from "@/app/_lib/database";
|
||||
import { Edit as InternalEdit } from "@/app/_components/Edit";
|
||||
import { updateVoiceLineAction } from "../../_actions/voice";
|
||||
|
||||
type EditProps = {
|
||||
row: VoiceLine;
|
||||
};
|
||||
|
||||
export const Edit: FC<EditProps> = ({ row }) => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: row,
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
updateVoiceLineAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalEdit
|
||||
title={`Edit Voice Line: ${row.name}`}
|
||||
entity="voice"
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("VoiceLine")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Edit row={row} />;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
const entity = "voice";
|
||||
const table = "VoiceLine";
|
||||
|
||||
export const addVoiceLineAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateVoiceLineAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteVoiceLineAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { GridColDef } from "@mui/x-data-grid-pro";
|
||||
import { List } from "@/app/_components/List";
|
||||
|
||||
type VoiceBotsListProps = {
|
||||
rows: any[];
|
||||
};
|
||||
|
||||
export const VoiceBotsList: FC<VoiceBotsListProps> = ({ rows }) => {
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "id",
|
||||
headerName: "ID",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "phoneNumber",
|
||||
headerName: "Phone Number",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "createdAt",
|
||||
headerName: "Created At",
|
||||
valueGetter: (params: any) =>
|
||||
new Date(params.row?.createdAt).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "updatedAt",
|
||||
headerName: "Updated At",
|
||||
valueGetter: (params: any) =>
|
||||
new Date(params.row?.updatedAt).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<List
|
||||
title="Voice Connections"
|
||||
entity="voice"
|
||||
rows={rows}
|
||||
columns={columns}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import { VoiceBotsList } from "./_components/VoiceBotsList";
|
||||
import { db } from "@/app/_lib/database";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const rows = await db.selectFrom("VoiceLine").selectAll().execute();
|
||||
|
||||
return <VoiceBotsList rows={rows} />;
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
"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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
"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>
|
||||
);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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} />;
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
"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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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} />;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
const entity = "webhooks";
|
||||
const table = "Webhook";
|
||||
|
||||
export const addWebhookAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateWebhookAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteWebhookAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { GridColDef } from "@mui/x-data-grid-pro";
|
||||
import { List } from "@/app/_components/List";
|
||||
|
||||
type WebhooksListProps = {
|
||||
rows: any[];
|
||||
};
|
||||
|
||||
export const WebhooksList: FC<WebhooksListProps> = ({ rows }) => {
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "id",
|
||||
headerName: "ID",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "phoneNumber",
|
||||
headerName: "Phone Number",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "createdAt",
|
||||
headerName: "Created At",
|
||||
valueGetter: (params: any) =>
|
||||
new Date(params.row?.createdAt).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "updatedAt",
|
||||
headerName: "Updated At",
|
||||
valueGetter: (params: any) =>
|
||||
new Date(params.row?.updatedAt).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<List title="Webhooks" entity="webhooks" rows={rows} columns={columns} />
|
||||
);
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import { WebhooksList } from "./_components/WebhooksList";
|
||||
import { db } from "@/app/_lib/database";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const rows = await db.selectFrom("Webhook").selectAll().execute();
|
||||
console.log(rows);
|
||||
|
||||
return <WebhooksList rows={rows} />;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
"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 { addWhatsappBotAction } from "../../_actions/whatsapp";
|
||||
|
||||
export const Create: FC = () => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: {
|
||||
name: "",
|
||||
description: "",
|
||||
one: "",
|
||||
},
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
addWhatsappBotAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalCreate
|
||||
title="Create WhatsApp Connection"
|
||||
entity="whatsapp"
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import { Create } from "./_components/Create";
|
||||
|
||||
export default function Page() {
|
||||
return <Create />;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { Grid } from "@mui/material";
|
||||
import { DisplayTextField } from "ui";
|
||||
import { WhatsappBot } from "@/app/_lib/database";
|
||||
import { Detail as InternalDetail } from "@/app/_components/Detail";
|
||||
import { deleteWhatsappBotAction } from "../../_actions/whatsapp";
|
||||
|
||||
type DetailProps = {
|
||||
row: WhatsappBot;
|
||||
};
|
||||
|
||||
export const Detail: FC<DetailProps> = ({ row }) => (
|
||||
<InternalDetail
|
||||
title={`WhatsApp Connection: ${row.name}`}
|
||||
entity="whatsapp"
|
||||
id={row.id}
|
||||
deleteAction={deleteWhatsappBotAction}
|
||||
>
|
||||
<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>
|
||||
);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("WhatsappBot")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Detail row={row} />;
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { useFormState } from "react-dom";
|
||||
import { Grid } from "@mui/material";
|
||||
import { TextField } from "ui";
|
||||
import { WhatsappBot } from "@/app/_lib/database";
|
||||
import { Edit as InternalEdit } from "@/app/_components/Edit";
|
||||
import { updateWhatsappBotAction } from "../../_actions/whatsapp";
|
||||
|
||||
type EditProps = {
|
||||
row: WhatsappBot;
|
||||
};
|
||||
|
||||
export const Edit: FC<EditProps> = ({ row }) => {
|
||||
const initialState = {
|
||||
message: null,
|
||||
errors: {},
|
||||
values: row,
|
||||
};
|
||||
const [formState, formAction] = useFormState(
|
||||
updateWhatsappBotAction,
|
||||
initialState,
|
||||
);
|
||||
|
||||
return (
|
||||
<InternalEdit
|
||||
title={`Edit Whatsapp Connection: ${row.name}`}
|
||||
entity="whatsapp"
|
||||
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 item xs={6}>
|
||||
<TextField
|
||||
name="token"
|
||||
label="Token"
|
||||
disabled
|
||||
formState={formState}
|
||||
refreshable
|
||||
helperText="Token used to authenticate requests from Link"
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</InternalEdit>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
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("WhatsappBot")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
return <Edit row={row} />;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
"use server";
|
||||
|
||||
import { addAction, updateAction, deleteAction } from "@/app/_lib/actions";
|
||||
|
||||
const entity = "whatsapp";
|
||||
const table = "WhatsappBot";
|
||||
|
||||
export const addWhatsappBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return addAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateWhatsappBotAction = async (
|
||||
currentState: any,
|
||||
formData: FormData,
|
||||
) => {
|
||||
return updateAction({
|
||||
entity,
|
||||
table,
|
||||
fields: ["name"],
|
||||
currentState,
|
||||
formData,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteWhatsappBotAction = async (id: string) => {
|
||||
return deleteAction({ entity, table, id });
|
||||
};
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import { GridColDef } from "@mui/x-data-grid-pro";
|
||||
import { WhatsappBot } from "@/app/_lib/database";
|
||||
import { List } from "@/app/_components/List";
|
||||
|
||||
type WhatsappListProps = {
|
||||
rows: WhatsappBot[];
|
||||
};
|
||||
|
||||
export const WhatsappList: FC<WhatsappListProps> = ({ rows }) => {
|
||||
const columns: GridColDef[] = [
|
||||
{
|
||||
field: "name",
|
||||
headerName: "Name",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "phoneNumber",
|
||||
headerName: "Phone Number",
|
||||
flex: 1,
|
||||
},
|
||||
{
|
||||
field: "description",
|
||||
headerName: "Description",
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
field: "updatedAt",
|
||||
headerName: "Updated At",
|
||||
valueGetter: (params: any) =>
|
||||
new Date(params.row?.updatedAt).toLocaleString(),
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<List
|
||||
title="WhatsApp Connections"
|
||||
entity="whatsapp"
|
||||
rows={rows}
|
||||
columns={columns}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { ServiceLayout } from "@/app/_components/ServiceLayout";
|
||||
|
||||
export default ServiceLayout;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import { WhatsappList } from "./_components/WhatsappList";
|
||||
import { db } from "@/app/_lib/database";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const rows = await db.selectFrom("WhatsappBot").selectAll().execute();
|
||||
console.log(rows);
|
||||
|
||||
return <WhatsappList rows={rows} />;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue