"use client"; import { useEffect, useState } from "react"; import { useAuth } from "@/hooks/useAuth"; import { api, type Report } from "@/lib/api"; import Sidebar from "@/components/Sidebar"; import { FileText, Download, RefreshCw } from "lucide-react"; export default function ReportsPage() { const { tenantId, role, ready } = useAuth(); const [reports, setReports] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [downloadingId, setDownloadingId] = useState(null); const [snapshotting, setSnapshotting] = useState(false); useEffect(() => { if (!ready || !tenantId) return; api.reports(tenantId) .then(setReports) .catch(e => setError(e.message)) .finally(() => setLoading(false)); }, [ready, tenantId]); async function handleDownload(id: string) { setDownloadingId(id); try { await api.downloadReportPdf(id); } catch (e: any) { setError(e.message || "Download failed"); } finally { setDownloadingId(null); } } async function handleSnapshot() { if (!tenantId) return; setSnapshotting(true); try { await api.downloadPdfSnapshot(tenantId); } catch (e: any) { setError(e.message || "Snapshot failed"); } finally { setSnapshotting(false); } } const canSnapshot = role === "it_admin" || role === "trustos_admin"; return (

Vault Audit Reports

Point-in-time baseline reports and audit deliverables

{canSnapshot && ( )}
{error && (
{error}
)} {loading ? (
) : reports.length === 0 ? (

No audit reports yet

{role === "trustos_admin" ? "Generate the first Vault Audit from the Admin Panel." : "Your TrustOS administrator will publish audit reports here."}

) : (
{reports.map(r => (
{r.is_baseline && ( Baseline )}

{r.title}

{new Date(r.report_date).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" })} {r.baseline_score != null && ` · Score at audit: ${Math.round(r.baseline_score)}`}

{r.executive_summary && (

{r.executive_summary}

)}
))}
)}
); }