"use client"; /** * TASK-0133 — Overview tab: org counts + 30-day storage/audit trend + the * effective policy (the plan caps the file size; see the Policies tab to edit * it). Data: `GET /orgs/:orgId/admin/overview`. */ import { useQuery } from "@tanstack/react-query"; import { Database, FileText, NotebookText, User, Users } from "lucide-react"; import { orgAdminApi } from "@/lib/org-admin"; import { Section } from "@/components/settings/settings-shell"; function formatBytes(n: number): string { if (n < 1024) return `${n} B`; const units = ["KB", "MB", "GB", "TB"]; let v = n / 1024; let i = 0; while (v >= 1024 && i < units.length - 1) { v /= 1024; i += 1; } return `${v.toFixed(1)} ${units[i]}`; } /** A tiny inline bar sparkline (no chart library — the org console keeps its * dependencies lean). Pure CSS bars, ARIA-labelled. */ function Sparkline({ points, label, fmt }: { points: { day: string; value: number }[]; label: string; fmt: (n: number) => string }) { const max = Math.max(1, ...points.map((p) => p.value)); return (
{points.map((p) => (
))}
{points[0]?.day ?? ""} {points[points.length - 1]?.day ?? ""}
); } function Stat({ icon: Icon, label, value }: { icon: typeof User; label: string; value: string | number }) { return (
{label}
{value}
); } export function AdminOverviewTab({ orgId }: { orgId: string }) { const q = useQuery({ queryKey: ["orgs", orgId, "admin", "overview"], queryFn: () => orgAdminApi.overview(orgId), retry: false, }); if (q.isLoading) { return

Loading overview…

; } if (q.isError) { return

Could not load the overview.

; } const o = q.data!; return (
({ day: p.day, value: p.bytes }))} label="Storage trend over 30 days" fmt={formatBytes} />
({ day: p.day, value: p.count }))} label="Audit events trend over 30 days" fmt={(n) => String(n)} />
Max file size
{o.policy.maxFileSizeMB ? `${o.policy.maxFileSizeMB} MB` : "plan default"}
2FA
{o.policy.require2FA ? "required" : "off"}
SSO enforced
{o.policy.ssoEnforced ? "on" : "off"}
Guest public share
{o.policy.disableGuestPublicShare ? "disabled" : "allowed"}
External embeds
{o.policy.allowExternalEmbeds ? "allowed" : "disabled"}
Session lifetime
{o.policy.sessionLifetimeHours ? `${o.policy.sessionLifetimeHours} h` : "default"}
); }