This commit is contained in:
bipproduction
2025-10-21 16:28:47 +08:00
parent 3cc04e42c2
commit 026dbe6f9b
2 changed files with 22 additions and 1 deletions

View File

@@ -1,8 +1,9 @@
import apiFetch from "@/lib/apiFetch";
import { Card, Pagination, Skeleton, Stack, Text, Title } from "@mantine/core";
import { Button, Card, Pagination, Skeleton, Stack, Text, Title } from "@mantine/core";
import { useLocalStorage, useShallowEffect } from "@mantine/hooks";
import dayjs from "dayjs";
import useSWR from "swr";
import { showNotification } from "@mantine/notifications";
export default function WaHookHome() {
const [page, setPage] = useLocalStorage({
@@ -24,11 +25,18 @@ export default function WaHookHome() {
setPage(data?.data?.list?.length || 1)
}, [])
async function reset() {
await apiFetch["wa-hook"].reset.post()
mutate()
showNotification({ title: "Success", message: "WhatsApp Hook reset", color: "green" })
}
if (isLoading) return <Skeleton height={500} />
if (error) return <div>Error: {error.message}</div>
return (
<Stack>
<Title order={2}>WaHookHome</Title>
<Button onClick={reset}>Reset</Button>
{data?.data?.list.map((item) => (
<Card key={item.id}>
<Stack>

View File

@@ -2,6 +2,7 @@ import Elysia, { t } from "elysia";
import { prisma } from "../lib/prisma";
import type { WAHookMessage } from "types/wa_messages";
import _ from "lodash";
import dayjs from "dayjs";
async function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeoutMs = 120_000) {
const controller = new AbortController()
@@ -165,6 +166,18 @@ const WaHookRoute = new Elysia({
summary: "List WhatsApp Hook",
description: "List semua WhatsApp Hook",
}
})
.post("/reset", async () => {
await prisma.waHook.deleteMany()
return {
success: true,
message: "WhatsApp Hook reset"
};
}, {
detail: {
summary: "Reset WhatsApp Hook",
description: "Reset semua WhatsApp Hook",
}
});
export default WaHookRoute;