From 6500f90096c6b7bd954c75621a22f9b6f87f8e07 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Fri, 26 Apr 2024 00:38:13 +0800 Subject: [PATCH] feat: add delete feature for pages --- src/client/routes/page/$slug.tsx | 47 ++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/client/routes/page/$slug.tsx b/src/client/routes/page/$slug.tsx index a5938e8..62c5689 100644 --- a/src/client/routes/page/$slug.tsx +++ b/src/client/routes/page/$slug.tsx @@ -1,4 +1,5 @@ import { trpc } from '@/api/trpc'; +import { AlertConfirm } from '@/components/AlertConfirm'; import { CommonHeader } from '@/components/CommonHeader'; import { CommonWrapper } from '@/components/CommonWrapper'; import { ErrorTip } from '@/components/ErrorTip'; @@ -6,10 +7,11 @@ import { Loading } from '@/components/Loading'; import { NotFoundTip } from '@/components/NotFoundTip'; import { MonitorStatusPage } from '@/components/monitor/StatusPage'; import { Button } from '@/components/ui/button'; +import { useEvent } from '@/hooks/useEvent'; import { routeAuthBeforeLoad } from '@/utils/route'; import { useTranslation } from '@i18next-toolkit/react'; import { Link, createFileRoute, useNavigate } from '@tanstack/react-router'; -import { LuEye } from 'react-icons/lu'; +import { LuEye, LuTrash } from 'react-icons/lu'; export const Route = createFileRoute('/page/$slug')({ beforeLoad: routeAuthBeforeLoad, @@ -23,6 +25,29 @@ function PageComponent() { const { data: pageInfo, isLoading } = trpc.monitor.getPageInfo.useQuery({ slug, }); + const trpcUtils = trpc.useUtils(); + + const deletePageMutation = trpc.monitor.deletePage.useMutation(); + + const handleDelete = useEvent(async () => { + if (!pageInfo) { + return; + } + + await deletePageMutation.mutateAsync({ + workspaceId: pageInfo.workspaceId, + id: pageInfo.id, + }); + + trpcUtils.monitor.getAllPages.refetch({ + workspaceId: pageInfo.workspaceId, + }); + + navigate({ + to: '/page', + replace: true, + }); + }); if (!slug) { return ; @@ -42,11 +67,21 @@ function PageComponent() { - - +
+ + + +
} /> }