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(); + }} + > +