51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { commonCodeApi } from "@/lib/api/commonCode";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
|
|
/**
|
|
* 카테고리 중복 검사 훅
|
|
*/
|
|
export function useCheckCategoryDuplicate(
|
|
field: "categoryCode" | "categoryName" | "categoryNameEng",
|
|
value: string,
|
|
excludeCode?: string,
|
|
enabled = true,
|
|
) {
|
|
return useQuery({
|
|
queryKey: queryKeys.validation.categoryDuplicate(field, value, excludeCode),
|
|
queryFn: () => commonCodeApi.validation.checkCategoryDuplicate(field, value, excludeCode),
|
|
enabled: enabled && !!value && value.trim().length > 0,
|
|
staleTime: 0, // 항상 최신 데이터 확인
|
|
retry: false, // 중복 검사는 재시도하지 않음
|
|
select: (data) => data.data,
|
|
meta: {
|
|
// React Query 에러 로깅 비활성화
|
|
errorPolicy: "silent",
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 코드 중복 검사 훅
|
|
*/
|
|
export function useCheckCodeDuplicate(
|
|
categoryCode: string,
|
|
field: "codeValue" | "codeName" | "codeNameEng",
|
|
value: string,
|
|
excludeCode?: string,
|
|
enabled = true,
|
|
) {
|
|
return useQuery({
|
|
queryKey: queryKeys.validation.codeDuplicate(categoryCode, field, value, excludeCode),
|
|
queryFn: () => commonCodeApi.validation.checkCodeDuplicate(categoryCode, field, value, excludeCode),
|
|
enabled: enabled && !!categoryCode && !!value && value.trim().length > 0,
|
|
staleTime: 0, // 항상 최신 데이터 확인
|
|
retry: false, // 중복 검사는 재시도하지 않음
|
|
select: (data) => data.data,
|
|
meta: {
|
|
// React Query 에러 로깅 비활성화
|
|
errorPolicy: "silent",
|
|
},
|
|
});
|
|
}
|