import { useState, useEffect } from 'react'; import { supabase } from '@/integrations/supabase/client'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Badge } from '@/components/ui/badge'; import { Loader2 } from 'lucide-react'; import { format } from 'date-fns'; import { handleError } from '@/lib/errorHandler'; import { AuditLogEntry } from '@/types/database'; export function ProfileAuditLog() { const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetchAuditLogs(); }, []); const fetchAuditLogs = async () => { try { const { data, error } = await supabase .from('profile_audit_log') .select(` *, profiles!user_id(username, display_name) `) .order('created_at', { ascending: false }) .limit(50); if (error) throw error; setLogs((data || []) as AuditLogEntry[]); } catch (error: unknown) { handleError(error, { action: 'Load audit logs' }); } finally { setLoading(false); } }; if (loading) { return ( ); } return ( Profile Audit Log User Action Changes Date {logs.map((log) => ( {(log as { profiles?: { display_name?: string; username?: string } }).profiles?.display_name || (log as { profiles?: { username?: string } }).profiles?.username || 'Unknown'} {log.action}
{JSON.stringify(log.changes || {}, null, 2)}
{format(new Date(log.created_at), 'PPpp')}
))}
); }