Files
GMW/services/frontend/src/hooks/use-dashboard.ts
T
Developer 69213ebd75 refactor(fe): align dashboard with backend & gateway data flow
- API/WS clients: same-origin by default, drop dead imphnen hardcode
- chatbot history: map BE rows {user_message,bot_response,created_at}
- message_deleted WS payload: object {id,deleted_at}, not bare string
- dashboard: wire top-channels chart + live mod queue from /api/review,
  add Users & Channels tabs consuming /api/dashboard/users|channels
- recordings: live WS sync via voice_recording_uploaded; duration_bytes optional
- remove dead widgets with no BE data source (trend chart, heatmap)
2026-07-31 16:54:41 +07:00

48 lines
1.3 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import { dashboardApi } from "@/lib/api";
import type {
DashboardChannelDetail,
DashboardStats,
DashboardUserDetail,
} from "@/lib/types";
export function useStats() {
return useQuery<DashboardStats>({
queryKey: ["dashboard-stats"],
queryFn: () => dashboardApi.getStats(),
});
}
export function useUsers(search?: string) {
return useQuery({
queryKey: ["dashboard-users", search ?? ""],
queryFn: () => dashboardApi.listUsers(20, undefined, search),
select: (data) => data.data,
});
}
export function useChannels(guildId?: string, search?: string) {
return useQuery({
queryKey: ["dashboard-channels", guildId ?? "__all__", search ?? ""],
queryFn: () => dashboardApi.listChannels(20, search, guildId || undefined),
select: (data) => data.data,
});
}
export function useUserDetail(userId: string | null) {
return useQuery<DashboardUserDetail>({
queryKey: ["dashboard-user", userId],
queryFn: () => dashboardApi.getUserDetail(userId!),
enabled: !!userId,
});
}
export function useChannelDetail(channelId: string | null) {
return useQuery<DashboardChannelDetail>({
queryKey: ["dashboard-channel", channelId],
queryFn: () => dashboardApi.getChannelDetail(channelId!),
enabled: !!channelId,
});
}