36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import type { ScheduleInfoSearchParams } from "../../model/dashboard/schedule-info-interface";
|
|
|
|
import { scheduleInfoApi } from "./schedule-info-service";
|
|
|
|
export function useScheduleInfo(params: ScheduleInfoSearchParams | null) {
|
|
return useQuery({
|
|
queryKey: createScheduleInfoQueryKey(params),
|
|
queryFn: async () => {
|
|
if (!params)
|
|
throw new Error("Schedule info search params are required.");
|
|
const response = await scheduleInfoApi.getScheduleInfo(params);
|
|
return response.data;
|
|
},
|
|
enabled: hasRequiredScheduleInfoParams(params),
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
}
|
|
|
|
function createScheduleInfoQueryKey(params: ScheduleInfoSearchParams | null) {
|
|
return [
|
|
ENDPOINT.ST_SERVICE.DASHBOARD,
|
|
"schedule-info",
|
|
params?.statsYr ?? "",
|
|
];
|
|
}
|
|
|
|
function hasRequiredScheduleInfoParams(
|
|
params: ScheduleInfoSearchParams | null,
|
|
): params is ScheduleInfoSearchParams {
|
|
return Boolean(params?.statsYr);
|
|
}
|