import { useQuery } from "@tanstack/react-query"; import { format } from "date-fns"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { useTranslation } from "react-i18next"; import { Loader2 } from "lucide-react"; interface AuditLog { id: string; userId: string | null; action: string; entityType: string; entityId: string | null; source: string; details: any; createdAt: string; } export function AuditLogsTable() { const { t } = useTranslation(); const { data: logs, isLoading, error } = useQuery({ queryKey: ['/api/admin/audit-logs'], }); if (isLoading) { return
; } if (error) { return
Failed to load audit logs. Please check server logs.
; } return ( {t('settings.auditLogs.title')} {t('settings.auditLogs.description')} {t('settings.auditLogs.table.time')} {t('settings.auditLogs.table.source')} {t('settings.auditLogs.table.action')} {t('settings.auditLogs.table.entity')} {t('settings.auditLogs.table.details')} {logs?.map((log) => ( {new Date(log.createdAt).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'medium' })} {t(`audit.source.${log.source}`, { defaultValue: log.source })} {t(`audit.action.${log.action}`, { defaultValue: log.action })} {t(`audit.entity.${log.entityType}`, { defaultValue: log.entityType })} {log.entityId && {log.entityId}}
                                        {JSON.stringify(log.details, null, 2)}
                                    
))} {(!logs || logs.length === 0) && ( {t('settings.auditLogs.table.empty')} )}
); }