import { useState } from 'react'; import { FileText, ChevronLeft, ChevronRight, Filter, X, } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Select } from '@/components/ui/select'; import { Skeleton } from '@/components/ui/skeleton'; import { useAuditLog } from '@/hooks/useAdmin'; import { getRelativeTime } from '@/lib/date-utils'; import { cn } from '@/lib/utils'; import { actionColor } from './shared'; const ACTION_TYPES = [ 'admin.user_created', 'admin.role_changed', 'admin.password_reset', 'admin.mfa_disabled', 'admin.mfa_enforce_toggled', 'admin.user_deactivated', 'admin.user_activated', 'admin.sessions_revoked', 'admin.config_updated', 'auth.login_success', 'auth.login_failed', 'auth.setup_complete', 'auth.registration', 'auth.mfa_enforce_prompted', 'connection.request_sent', 'connection.request_cancelled', 'connection.accepted', 'connection.rejected', 'connection.removed', ]; function actionLabel(action: string): string { return action .split('.') .map((p) => p.replace(/_/g, ' ')) .join(' — '); } export default function ConfigPage() { const [page, setPage] = useState(1); const [filterAction, setFilterAction] = useState(''); const PER_PAGE = 25; const { data, isLoading, error } = useAuditLog(page, PER_PAGE, filterAction || undefined); const totalPages = data ? Math.ceil(data.total / PER_PAGE) : 1; return (
Audit Log {data && ( {data.total} entries )}
{/* Filter controls */}
Filter:
{filterAction && ( )}
{isLoading ? (
{Array.from({ length: 8 }).map((_, i) => ( ))}
) : error ? (

Failed to load audit log

{error.message}

) : !data?.entries?.length ? (

No audit entries found.

) : ( <>
{data.entries.map((entry, idx) => ( ))}
Time Actor Action Target IP Detail
{getRelativeTime(entry.created_at)} {entry.actor_username ?? ( system )} {entry.action} {entry.target_username ?? '—'} {entry.ip_address ?? '—'} {entry.detail ?? '—'}
{/* Pagination */} {totalPages > 1 && (
Page {page} of {totalPages}
)} )}
); }