110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import type { DashboardSearchParams } from "../../model/dashboard/dashboard-interface";
|
|
|
|
import { dashboardApi } from "./dashboard-service";
|
|
|
|
// 이상치 선별보고서 조회
|
|
export function useDashboardVrfcReport(params: DashboardSearchParams | null) {
|
|
return useQuery({
|
|
queryKey: createDashboardQueryKey("vrfc-report", params),
|
|
queryFn: async () => {
|
|
if (!params)
|
|
throw new Error("Dashboard search params are required.");
|
|
const response = await dashboardApi.getVrfcReport(params);
|
|
return response.data;
|
|
},
|
|
enabled: hasRequiredDashboardParams(params),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|
|
|
|
// 검증오류 수 조회
|
|
export function useDashboardVrfcErrCount(params: DashboardSearchParams | null) {
|
|
return useQuery({
|
|
queryKey: createDashboardQueryKey("vrfc-err-count", params),
|
|
queryFn: async () => {
|
|
if (!params)
|
|
throw new Error("Dashboard search params are required.");
|
|
const response = await dashboardApi.getVrfcErrCount(params);
|
|
return response.data;
|
|
},
|
|
enabled: hasRequiredDashboardParams(params),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|
|
|
|
// 미제출 수 & 목록 조회
|
|
export function useDashboardUnSubmitCount(
|
|
params: DashboardSearchParams | null,
|
|
) {
|
|
return useQuery({
|
|
queryKey: createDashboardQueryKey("submission-status", params),
|
|
queryFn: async () => {
|
|
if (!params)
|
|
throw new Error("Dashboard search params are required.");
|
|
const response = await dashboardApi.getUnSubmitCount({
|
|
...params,
|
|
unSubmitOnly: true,
|
|
});
|
|
return response.data;
|
|
},
|
|
enabled: hasRequiredDashboardParams(params),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|
|
|
|
// 통계입력현황 조회
|
|
export function useDashboardStatsSubmissionRate(
|
|
params: DashboardSearchParams | null,
|
|
) {
|
|
return useQuery({
|
|
queryKey: createDashboardQueryKey("stats-submission-rate", params),
|
|
queryFn: async () => {
|
|
if (!params)
|
|
throw new Error("Dashboard search params are required.");
|
|
const response = await dashboardApi.getStatsSubmissionRate(params);
|
|
return response.data;
|
|
},
|
|
enabled: hasRequiredDashboardParams(params),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|
|
|
|
// 예외신청 수 조회
|
|
export function useDashboardEcptReqCount(params: DashboardSearchParams | null) {
|
|
return useQuery({
|
|
queryKey: createDashboardQueryKey("ecpt-req-count", params),
|
|
queryFn: async () => {
|
|
if (!params)
|
|
throw new Error("Dashboard search params are required.");
|
|
const response = await dashboardApi.getEcptReqCount(params);
|
|
return response.data;
|
|
},
|
|
enabled: hasRequiredDashboardParams(params),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|
|
|
|
function createDashboardQueryKey(
|
|
name: string,
|
|
params: DashboardSearchParams | null,
|
|
) {
|
|
return [
|
|
ENDPOINT.ST_SERVICE.DASHBOARD,
|
|
name,
|
|
params?.statsYr ?? "",
|
|
params?.dtlInstCd ?? "",
|
|
params?.enoCd ?? "",
|
|
params?.laeSeCd ?? "",
|
|
];
|
|
}
|
|
|
|
function hasRequiredDashboardParams(
|
|
params: DashboardSearchParams | null,
|
|
): params is DashboardSearchParams {
|
|
return Boolean(params?.statsYr && params.dtlInstCd);
|
|
}
|