diff --git a/src/app/dashboard/privacy/audit/page.tsx b/src/app/dashboard/privacy/audit/page.tsx new file mode 100644 index 0000000..04b3b25 --- /dev/null +++ b/src/app/dashboard/privacy/audit/page.tsx @@ -0,0 +1,102 @@ +'use client'; + +import { useQuery } from '@tanstack/react-query'; +import { apiFetch, type AuditLogEntry } from '../../../../lib/api'; +import { useSession } from '../../../../components/session-provider'; + +function formatAction(action: string): string { + return action.replace(/\./g, ' · ').replace(/_/g, ' '); +} + +function severityColor(action: string): string { + if (action.includes('deleted') || action.includes('removed')) return 'text-signal-danger'; + if (action.includes('created') || action.includes('added')) return 'text-signal-ok'; + if (action.includes('updated') || action.includes('changed') || action.includes('selected')) + return 'text-signal-warn'; + return 'text-ink-faint'; +} + +export default function AuditLogPage() { + const { activeTenant } = useSession(); + const tenantId = activeTenant?.tenantId ?? ''; + + const { data: entries = [], isLoading } = useQuery({ + queryKey: ['audit-log', tenantId], + queryFn: () => apiFetch('/v1/audit-log?limit=200', { tenantId }), + enabled: Boolean(tenantId), + staleTime: 30_000, + }); + + return ( +
+
+

Audit Log

+

+ Toate operațiunile materiale din workspace — imutabil, doar citire. + {entries.length > 0 && ` · Ultimele ${entries.length} înregistrări.`} +

+
+ + {isLoading &&

Se încarcă…

} + + {!isLoading && entries.length === 0 && ( +

+ Nicio înregistrare de audit. Jurnalul se completează automat cu fiecare operațiune. +

+ )} + + {entries.length > 0 && ( +
+
+ + + + + + + + + + + {entries.map((entry, i) => ( + + + + + + + ))} + +
+ Data + + Acțiune + + Resursă + + Actor +
+ {new Date(entry.createdAt).toLocaleString('ro-RO', { + day: '2-digit', + month: '2-digit', + hour: '2-digit', + minute: '2-digit', + })} + + {formatAction(entry.action)} + + {entry.resource} + + {entry.actorId ? entry.actorId.slice(0, 8) + '…' : entry.actorType} +
+
+
+ )} +
+ ); +}