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