From 3bf86b3e6e6c5e86cbeb3cd9b7aaa41a53dd5439 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 10 Nov 2024 06:08:22 +0800 Subject: [PATCH] feat: add audit log clear feature --- src/client/routes/settings/auditLog.tsx | 41 ++++++++++++++++++++++--- src/server/trpc/routers/auditLog.ts | 25 ++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/client/routes/settings/auditLog.tsx b/src/client/routes/settings/auditLog.tsx index 2fb4591..a596c7b 100644 --- a/src/client/routes/settings/auditLog.tsx +++ b/src/client/routes/settings/auditLog.tsx @@ -5,8 +5,12 @@ import { CommonWrapper } from '@/components/CommonWrapper'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Empty, List } from 'antd'; import { useMemo, useRef } from 'react'; -import { trpc } from '../../api/trpc'; -import { useCurrentWorkspaceId } from '../../store/user'; +import { + defaultErrorHandler, + defaultSuccessHandler, + trpc, +} from '../../api/trpc'; +import { useCurrentWorkspaceId, useHasAdminPermission } from '../../store/user'; import { CommonHeader } from '@/components/CommonHeader'; import { last } from 'lodash-es'; import { useVirtualizer } from '@tanstack/react-virtual'; @@ -14,6 +18,9 @@ import { useWatch } from '@/hooks/useWatch'; import dayjs from 'dayjs'; import { ColorTag } from '@/components/ColorTag'; import { SimpleVirtualList } from '@/components/SimpleVirtualList'; +import { Button } from '@/components/ui/button'; +import { LuTrash2 } from 'react-icons/lu'; +import { AlertConfirm } from '@/components/AlertConfirm'; export const Route = createFileRoute('/settings/auditLog')({ beforeLoad: routeAuthBeforeLoad, @@ -24,8 +31,9 @@ function PageComponent() { const { t } = useTranslation(); const workspaceId = useCurrentWorkspaceId(); const parentRef = useRef(null); + const hasAdminPermission = useHasAdminPermission(); - const { data, hasNextPage, fetchNextPage, isFetchingNextPage } = + const { data, hasNextPage, fetchNextPage, isFetchingNextPage, refetch } = trpc.auditLog.fetchByCursor.useInfiniteQuery( { workspaceId, @@ -35,6 +43,11 @@ function PageComponent() { } ); + const clearMutation = trpc.auditLog.clear.useMutation({ + onSuccess: defaultSuccessHandler, + onError: defaultErrorHandler, + }); + const allData = useMemo(() => { if (!data) { return []; @@ -69,7 +82,27 @@ function PageComponent() { }); return ( - }> + + {hasAdminPermission && ( + { + clearMutation.mutateAsync({ workspaceId }); + refetch(); + }} + > +