Files
Rafael MelgaçoandClaude Opus 4.7 56a5435914 feat(EPIC-11): admin usage + charts [wave 12]
GET /api/v1/admin/usage: requirePlatformAdmin, service-role aggregation
queries (messages count, ai_invocations count + tokens + cost_cents,
conversations count) by tenant + daily series for last 7/30/90 days.

UI:
- Range selector (7d/30d/90d) + optional tenant filter
- UsageCharts: 3 daily-series charts (messages, AI tokens, AI cost in
  BRL) via recharts
- UsageTable: per-tenant ranking by AI cost desc with messages/convs/
  tokens/cost — CSV export client-side via Blob download

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 15:35:30 -03:00

25 lines
714 B
TypeScript

"use client";
import { useQuery } from "@tanstack/react-query";
import { apiClient } from "@/lib/api/client";
import type { UsageData } from "@/app/api/v1/admin/usage/route";
interface UsageResponse {
data: UsageData;
}
export type UsageRange = "7d" | "30d" | "90d";
export function useAdminUsage(range: UsageRange = "30d", tenantId?: string) {
const params = new URLSearchParams({ range });
if (tenantId) params.set("tenant_id", tenantId);
return useQuery({
queryKey: ["admin", "usage", range, tenantId ?? null],
queryFn: () =>
apiClient
.get<UsageResponse>(`/api/v1/admin/usage?${params.toString()}`)
.then((r) => r.data),
staleTime: 5 * 60 * 1000, // 5 min
});
}