"use client"; import { useEffect, useState } from "react"; import { useCurrentUser } from "@/hooks/use-current-user"; import { getStats } from "@/lib/api"; import type { StatsResponse } from "@/types/stats"; import { SiteHeader } from "@/components/site-header"; import { Card, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; export default function DashboardPage() { const { hasPermission } = useCurrentUser(); const [stats, setStats] = useState(null); const [error, setError] = useState(null); const canReadStats = hasPermission("stats:read"); useEffect(() => { if (!canReadStats) return; getStats() .then(setStats) .catch((e) => setError(e.message)); }, [canReadStats]); return ( <>
{error &&

{error}

} {canReadStats && ( <>
Total Records {stats ? stats.total_records.toLocaleString() : "--"} Collections {stats ? stats.collections.length : "--"}
{stats && stats.collections.length > 0 && (
Collection Records {stats.collections.map((col) => ( {col.collection} {col.count.toLocaleString()} ))}
)} )}
); }