import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { api, type AdminQuotaRow } from "../lib/api"; import { quotaActionLabel } from "../lib/format"; const RANGES = [7, 30, 90] as const; export default function Stats() { const [days, setDays] = useState(30); const q = useQuery({ queryKey: ["admin-quota", days], queryFn: () => api.adminQuota(days), }); const data = q.data; const maxDaily = Math.max(1, ...(data?.daily ?? []).map((d) => d.total)); const grandTotal = (data?.rows ?? []).reduce((s, r) => s + r.total, 0); return (

API quota usage

{RANGES.map((d) => ( ))}

YouTube Data API units attributed by who triggered the spend. System is shared background work (scheduled backfill, enrichment, resync) that isn't tied to one person.

{q.isLoading ? (
Loading…
) : !data ? (
No data.
) : ( <> {/* Daily totals (instance-wide, Pacific days) */}
Daily total ({data.range_days}d · {grandTotal.toLocaleString()} units)
{data.daily.length === 0 ? (
No usage in this range.
) : (
{data.daily.map((d) => (
))}
)}
{/* Per-user breakdown */}
{data.rows.length === 0 ? (
No usage in this range.
) : ( data.rows.map((r) => ( )) )}
)}
); } function UserRow({ row, max }: { row: AdminQuotaRow; max: number }) { const [open, setOpen] = useState(false); const actions = Object.entries(row.by_action).sort((a, b) => b[1] - a[1]); const isSystem = row.user_id === null; return (
{/* Proportion bar */}
{open && actions.length > 0 && (
{actions.map(([action, units]) => (
{quotaActionLabel(action)} {units.toLocaleString()}
))}
)}
); }