import { IconActivity as Activity, IconWorld as Globe, IconTrendingDown as TrendingDown, IconTrendingUp as TrendingUp, IconUserPlus as UserPlus, IconUsers as Users, } from '@tabler/icons-react'; import { useQuery } from '@tanstack/react-query'; import { useId } from 'react'; import { Area, AreaChart } from 'recharts'; import { PerformanceMetrics } from '@/components/admin/PerformanceMetrics'; import { ServicesStatus } from '@/components/admin/ServicesStatus'; import { SetupProgress } from '@/components/admin/SetupProgress'; import { PageHeader } from '@/components/PageHeader'; import { Card, CardContent, CardDescription, CardHeader } from '@/components/ui/card'; import { ChartContainer } from '@/components/ui/chart'; import { Skeleton } from '@/components/ui/skeleton'; import { apiFetch } from '@/lib/api'; import { cn } from '@/lib/utils'; import { ContentPanel } from '../../components/ContentPanel'; interface StatsResponse { users: { total: number; newThisMonth: number; newLastMonth: number; activeThisMonth: number; activeLastMonth: number; weeklySignups: Array<{ week: string; count: number }>; }; orgs: { total: number; newThisMonth: number; newLastMonth: number; }; } function MiniSparkline({ data }: { data: Array<{ week: string; count: number }> }) { const gradientId = useId(); return ( ); } function KpiCard({ label, value, change, positive, icon: Icon, sparklineData, loading, }: { label: string; value: string; change: string; positive: boolean; icon: React.ComponentType<{ className?: string }>; sparklineData?: Array<{ week: string; count: number }>; loading: boolean; }) { return ( {label} {loading ? ( ) : ( {value} )} {loading ? ( ) : ( {positive ? : } {change} )} {sparklineData && !loading && ( )} ); } function pctChange(now: number, prev: number): string { const pct = ((now - prev) / Math.max(prev, 1)) * 100; return `${pct >= 0 ? '+' : ''}${pct.toFixed(1)}%`; } export default function AdminDashboard() { const { data: stats, isLoading: statsLoading } = useQuery({ queryKey: ['admin', 'stats'], queryFn: async () => { const res = await apiFetch('/api/v1/admin/stats'); if (!res.ok) return null; return res.json() as Promise; }, }); const dash = '—'; return ( <> {/* Setup progress — configure/deploy checklist */} {/* Platform KPIs */} = stats.users.newLastMonth : true} icon={Users} sparklineData={stats?.users.weeklySignups} loading={statsLoading} /> = 0 ? '+' : ''}${stats.users.newThisMonth - stats.users.newLastMonth} vs last month` : dash } positive={stats ? stats.users.newThisMonth >= stats.users.newLastMonth : true} icon={UserPlus} sparklineData={stats?.users.weeklySignups} loading={statsLoading} /> = 0 ? '+' : ''}${stats.users.activeThisMonth - stats.users.activeLastMonth} vs last month` : dash } positive={stats ? stats.users.activeThisMonth >= stats.users.activeLastMonth : true} icon={Activity} loading={statsLoading} /> {/* Infrastructure */} > ); }
{value}