37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import { codeService } from "./code-service";
|
|
|
|
const codeBaseKey = [ENDPOINT.CMS_SERVICE.CODE] as const;
|
|
|
|
const CODE_STALE_TIME = 1000 * 60 * 10;
|
|
|
|
export function useCodeList(upCd: string | undefined) {
|
|
return useQuery({
|
|
queryKey: [...codeBaseKey, upCd],
|
|
queryFn: () => codeService.getList(upCd!),
|
|
enabled: Boolean(upCd),
|
|
staleTime: CODE_STALE_TIME,
|
|
});
|
|
}
|
|
|
|
export function useCodeListByUseYn(upCd: string | undefined, useYn: string) {
|
|
return useQuery({
|
|
queryKey: [...codeBaseKey, upCd, useYn],
|
|
queryFn: () => codeService.getListByUseYn(upCd!, useYn),
|
|
enabled: Boolean(upCd && useYn),
|
|
staleTime: CODE_STALE_TIME,
|
|
});
|
|
}
|
|
|
|
export function useCodeName(upCd: string | undefined, lwpoCd: string | undefined) {
|
|
return useQuery({
|
|
queryKey: [...codeBaseKey, upCd, "name", lwpoCd],
|
|
queryFn: () => codeService.getCodeName(upCd!, lwpoCd!),
|
|
enabled: Boolean(upCd && lwpoCd),
|
|
staleTime: CODE_STALE_TIME,
|
|
});
|
|
}
|