tambahan
This commit is contained in:
@@ -64,9 +64,9 @@ function FlowWaHookList() {
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const setAsDefault = async (id: string, defaultData: any) => {
|
||||
const setAsDefault = async (id: string) => {
|
||||
setLoading(true);
|
||||
const { error } = await apiFetch.api.chatflows.default.put({ id, defaultData });
|
||||
const { error } = await apiFetch.api.chatflows.default.put({ id });
|
||||
if (error) {
|
||||
showNotification({ title: "Error", message: "Failed to set default flow", color: "red" });
|
||||
} else {
|
||||
@@ -99,7 +99,7 @@ function FlowWaHookList() {
|
||||
<Table.Td>{flow.name}</Table.Td>
|
||||
<Table.Td>{flow.type}</Table.Td>
|
||||
<Table.Td>
|
||||
<Checkbox checked={defaultFlow === flow.id} onChange={() => setAsDefault(flow.id, flow)} />
|
||||
<Checkbox checked={defaultFlow === flow.id} onChange={() => setAsDefault(flow.id)} />
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
))}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import apiFetch from "@/lib/apiFetch";
|
||||
import { Card, Skeleton, Stack, Text, Title } from "@mantine/core";
|
||||
import { Card, Pagination, Skeleton, Stack, Text, Title } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import useSWR from "swr";
|
||||
import dayjs from "dayjs";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function WaHookHome() {
|
||||
const [page, setPage] = useState(1);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const { data, error, isLoading, mutate } = useSWR("/wa-hook", apiFetch["wa-hook"].list.get, {
|
||||
refreshInterval: 3000,
|
||||
revalidateOnFocus: true,
|
||||
@@ -37,6 +40,12 @@ export default function WaHookHome() {
|
||||
</Stack>
|
||||
</Card>
|
||||
))}
|
||||
<Pagination
|
||||
value={page}
|
||||
total={totalPages}
|
||||
onChange={setPage}
|
||||
withEdges
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,23 +84,21 @@ const FlowRoute = new Elysia({
|
||||
.put(
|
||||
'/default',
|
||||
async ctx => {
|
||||
const { id, defaultData } = ctx.body
|
||||
const { id } = ctx.body
|
||||
|
||||
const result = await prisma.chatFlows.update({
|
||||
where: {
|
||||
id: "1",
|
||||
},
|
||||
data: {
|
||||
defaultFlow: id,
|
||||
defaultData: defaultData,
|
||||
defaultFlow: id
|
||||
},
|
||||
})
|
||||
return { data: result }
|
||||
},
|
||||
{
|
||||
body: t.Object({
|
||||
id: t.String(),
|
||||
defaultData: t.Any(),
|
||||
id: t.String()
|
||||
}),
|
||||
detail: {
|
||||
summary: "Update default chatflows",
|
||||
|
||||
@@ -106,8 +106,7 @@ const WaHookRoute = new Elysia({
|
||||
createData.answer = {
|
||||
text: result.text,
|
||||
type: "text",
|
||||
flowId: flow.defaultFlow,
|
||||
flow: flow.defaultData,
|
||||
flowId: flow.defaultFlow
|
||||
}
|
||||
|
||||
await prisma.waHook.update({
|
||||
@@ -137,13 +136,17 @@ const WaHookRoute = new Elysia({
|
||||
description: "Menerima pesan dari WhatsApp Webhook"
|
||||
}
|
||||
})
|
||||
.get("/list", async () => {
|
||||
.get("/list", async ({ query }) => {
|
||||
const list = await prisma.waHook.findMany({
|
||||
take: query.limit,
|
||||
skip: query.offset,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const count = await prisma.waHook.count()
|
||||
const result = list.map((item) => ({
|
||||
id: item.id,
|
||||
data: item.data as WAHookMessage,
|
||||
@@ -151,8 +154,13 @@ const WaHookRoute = new Elysia({
|
||||
}))
|
||||
return {
|
||||
list: result,
|
||||
count,
|
||||
};
|
||||
}, {
|
||||
query: t.Object({
|
||||
limit: t.Optional(t.Number({ minimum: 1, maximum: 100, default: 10 })),
|
||||
offset: t.Optional(t.Number({ minimum: 0, default: 0 })),
|
||||
}),
|
||||
detail: {
|
||||
summary: "List WhatsApp Hook",
|
||||
description: "List semua WhatsApp Hook",
|
||||
|
||||
Reference in New Issue
Block a user