tambahan
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import apiFetch from "@/lib/apiFetch";
|
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 { useLocalStorage, useShallowEffect } from "@mantine/hooks";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import { showNotification } from "@mantine/notifications";
|
||||||
|
|
||||||
export default function WaHookHome() {
|
export default function WaHookHome() {
|
||||||
const [page, setPage] = useLocalStorage({
|
const [page, setPage] = useLocalStorage({
|
||||||
@@ -24,11 +25,18 @@ export default function WaHookHome() {
|
|||||||
setPage(data?.data?.list?.length || 1)
|
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 (isLoading) return <Skeleton height={500} />
|
||||||
if (error) return <div>Error: {error.message}</div>
|
if (error) return <div>Error: {error.message}</div>
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Title order={2}>WaHookHome</Title>
|
<Title order={2}>WaHookHome</Title>
|
||||||
|
<Button onClick={reset}>Reset</Button>
|
||||||
{data?.data?.list.map((item) => (
|
{data?.data?.list.map((item) => (
|
||||||
<Card key={item.id}>
|
<Card key={item.id}>
|
||||||
<Stack>
|
<Stack>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Elysia, { t } from "elysia";
|
|||||||
import { prisma } from "../lib/prisma";
|
import { prisma } from "../lib/prisma";
|
||||||
import type { WAHookMessage } from "types/wa_messages";
|
import type { WAHookMessage } from "types/wa_messages";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
async function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeoutMs = 120_000) {
|
async function fetchWithTimeout(input: RequestInfo, init: RequestInit, timeoutMs = 120_000) {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
@@ -165,6 +166,18 @@ const WaHookRoute = new Elysia({
|
|||||||
summary: "List WhatsApp Hook",
|
summary: "List WhatsApp Hook",
|
||||||
description: "List semua 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;
|
export default WaHookRoute;
|
||||||
|
|||||||
Reference in New Issue
Block a user