48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import {useQuery} from "@tanstack/react-query";
|
|
import {nextApi} from "@/lib/http-client";
|
|
import {CsiDataMap, CsiSummaryMap, DivDetailDataMap} from "@/types/kfpa";
|
|
import {statisticsQueryKeys} from "@/query/key/keys";
|
|
|
|
export type StatisticsQueryParams = {
|
|
pkey?: string;
|
|
dt?: string;
|
|
};
|
|
|
|
const hasStatisticsQueryParams = (params: StatisticsQueryParams) => !!params.pkey && !!params.dt;
|
|
|
|
export const getCsiSummary = (params: {dt?: string}) => {
|
|
return nextApi.get<CsiSummaryMap>("/statistics/csi-summary", { query: params });
|
|
};
|
|
|
|
export const getCsiData = (params: StatisticsQueryParams) => {
|
|
return nextApi.get<CsiDataMap>("/statistics/csi", { query: params });
|
|
};
|
|
|
|
export const getDivDetailData = (divId: string | number, params: StatisticsQueryParams) => {
|
|
return nextApi.get<DivDetailDataMap>(`/statistics/div-detail/${divId}`, { query: params });
|
|
};
|
|
|
|
export const useCsiSummaryQuery = (params?: {dt?: string}) => {
|
|
return useQuery({
|
|
queryKey: statisticsQueryKeys.summary(params),
|
|
queryFn: () => getCsiSummary({dt: params?.dt}),
|
|
enabled: !!params?.dt,
|
|
});
|
|
}
|
|
|
|
export const useCsiDataQuery = (params: StatisticsQueryParams) => {
|
|
return useQuery({
|
|
queryKey: statisticsQueryKeys.csi(params),
|
|
queryFn: () => getCsiData(params),
|
|
enabled: hasStatisticsQueryParams(params),
|
|
});
|
|
};
|
|
|
|
export const useDivDetailDataQuery = (divId: string | number, params: StatisticsQueryParams, enabled = true) => {
|
|
return useQuery({
|
|
queryKey: statisticsQueryKeys.divDetail(divId, params),
|
|
queryFn: () => getDivDetailData(divId, params),
|
|
enabled: enabled && hasStatisticsQueryParams(params),
|
|
});
|
|
};
|