import { useState } from "react"; import { useTranslation } from "react-i18next"; import { keepPreviousData, useQuery } from "@tanstack/react-query"; import { api, type AdminQuotaRow } from "../lib/api"; import { sinceOf } from "../lib/activityUrlState"; import { formatNumber, quotaActionLabel } from "../lib/format"; import { qk } from "../lib/queryKeys"; import type { Shared } from "./ActivityRuns"; import { Pressable } from "./ui/Pressable"; import { LoadingState, StateMessage } from "./ui/QueryState"; import { SURFACE } from "./ui/surfaces"; // Activity → Quota: the shared YouTube API budget's spend over the page's time range — per day // (Pacific days, as the budget resets), then per account, each opening to its actions. The // account filter narrows both to one account; the text filter has nothing to match here. export default function ActivityQuota({ shared }: { shared: Shared }) { const { t, i18n } = useTranslation(); const lang = i18n.language; const q = useQuery({ queryKey: qk.adminQuota({ window: shared.window, user: shared.user }), queryFn: () => api.adminQuota(sinceOf(shared.window), shared.user), placeholderData: keepPreviousData, }); 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 (
{t("stats.introBefore")} {t("stats.introSystem")} {t("stats.introAfter")}
{q.isError && !data ? (