Backend: /api/admin/* blueprint with user CRUD (list, get, update, disable/enable), usage summary aggregation (group by user/model/feature/ day/focus_group), usage event drill-down, and pricing list. Fixed admin_required decorator (async-safe). Added find_all/count/update helpers to User model. Frontend: /admin page (AdminRoute guard, 3 tabs) — Users table with search/filter/edit dialog, Usage tab with KPI cards + bar chart + events table, Pricing tab showing active model rows with tier details. Admin nav link visible only to admin role. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
838 B
TypeScript
32 lines
838 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { adminApi } from '@/lib/api';
|
|
|
|
interface UsageSummaryParams {
|
|
from?: string;
|
|
to?: string;
|
|
group_by?: 'user' | 'model' | 'feature' | 'day' | 'focus_group';
|
|
user_id?: string;
|
|
focus_group_id?: string;
|
|
}
|
|
|
|
export function useAdminUsageSummary(params: UsageSummaryParams = {}) {
|
|
return useQuery({
|
|
queryKey: ['admin', 'usage', 'summary', params],
|
|
queryFn: () => adminApi.usageSummary(params).then(r => r.data),
|
|
staleTime: 60_000,
|
|
});
|
|
}
|
|
|
|
export function useAdminUsageEvents(params?: {
|
|
user_id?: string;
|
|
focus_group_id?: string;
|
|
feature?: string;
|
|
skip?: number;
|
|
limit?: number;
|
|
}) {
|
|
return useQuery({
|
|
queryKey: ['admin', 'usage', 'events', params],
|
|
queryFn: () => adminApi.usageEvents(params).then(r => r.data),
|
|
staleTime: 30_000,
|
|
});
|
|
}
|