import { Users, UserCheck, UserX, Activity, Smartphone, LogIn, ShieldAlert, } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { useAdminDashboard, useAuditLog } from '@/hooks/useAdmin'; import { getRelativeTime } from '@/lib/date-utils'; import { cn } from '@/lib/utils'; import { StatCard, actionColor } from './shared'; export default function AdminDashboardPage() { const { data: dashboard, isLoading } = useAdminDashboard(); const { data: auditData } = useAuditLog(1, 10); const mfaPct = dashboard ? Math.round(dashboard.mfa_adoption_rate * 100) : null; const disabledUsers = dashboard ? dashboard.total_users - dashboard.active_users : null; return (
{/* Stats grid */}
{isLoading ? ( Array.from({ length: 5 }).map((_, i) => ( )) ) : ( <> } label="Total Users" value={dashboard?.total_users ?? '—'} /> } label="Active Users" value={dashboard?.active_users ?? '—'} iconBg="bg-green-500/10" /> } label="Disabled Users" value={disabledUsers ?? '—'} iconBg="bg-red-500/10" /> } label="Active Sessions" value={dashboard?.active_sessions ?? '—'} iconBg="bg-blue-500/10" /> } label="MFA Adoption" value={mfaPct !== null ? `${mfaPct}%` : '—'} iconBg="bg-purple-500/10" /> )}
{/* Recent logins */}
Recent Logins
{isLoading ? (
{Array.from({ length: 5 }).map((_, i) => ( ))}
) : !dashboard?.recent_logins?.length ? (

No recent logins.

) : (
{dashboard.recent_logins.map((entry, idx) => ( ))}
Username When
{entry.username} {getRelativeTime(entry.last_login_at)}
)}
{/* Recent admin actions */}
Recent Admin Actions
{!auditData?.entries?.length ? (

No recent actions.

) : (
{auditData.entries.slice(0, 10).map((entry, idx) => ( ))}
Action Actor Target When
{entry.action} {entry.actor_username ?? ( system )} {entry.target_username ?? '—'} {getRelativeTime(entry.created_at)}
)}
); }