260515_01_ENH: 클라이언트 수정사항 반영 및 다른 조사들 data 연결
This commit is contained in:
@@ -1,27 +1,47 @@
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {CsiDataMap, DivDetailDataMap} from "@/types/kfpa";
|
||||
import {CsiDataMap, CsiSummaryMap, DivDetailDataMap} from "@/types/kfpa";
|
||||
import {statisticsQueryKeys} from "@/query/key/keys";
|
||||
|
||||
export const getCsiData = () => {
|
||||
return nextApi.get<CsiDataMap>("/statistics/csi");
|
||||
export type StatisticsQueryParams = {
|
||||
pkey?: string;
|
||||
dt?: string;
|
||||
};
|
||||
|
||||
export const getDivDetailData = (divId: string | number) => {
|
||||
return nextApi.get<DivDetailDataMap>(`/statistics/div-detail/${divId}`);
|
||||
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 useCsiDataQuery = () => {
|
||||
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.csi(),
|
||||
queryFn: getCsiData,
|
||||
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, enabled = true) => {
|
||||
export const useDivDetailDataQuery = (divId: string | number, params: StatisticsQueryParams, enabled = true) => {
|
||||
return useQuery({
|
||||
queryKey: statisticsQueryKeys.divDetail(divId),
|
||||
queryFn: () => getDivDetailData(divId),
|
||||
enabled,
|
||||
queryKey: statisticsQueryKeys.divDetail(divId, params),
|
||||
queryFn: () => getDivDetailData(divId, params),
|
||||
enabled: enabled && hasStatisticsQueryParams(params),
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user