153 lines
4.8 KiB
TypeScript
153 lines
4.8 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import type {
|
|
DocPrgrsUpdateRequestDto,
|
|
InstlSncnApplySaveRequestDto,
|
|
InstlSncnMngSaveRequestDto,
|
|
InstlSncnMngSearchParams,
|
|
InstlSncnMngUpdateRequestDto,
|
|
} from "../model/instl-sncn-interface";
|
|
|
|
import { instlSncnRegionService, instlSncnService } from "./instl-sncn-service";
|
|
|
|
export const instlSncnKeys = {
|
|
all: ["instl-sncn"] as const,
|
|
list: () => [...instlSncnKeys.all, "list"] as const,
|
|
detail: (id: string) => [...instlSncnKeys.all, "detail", id] as const,
|
|
sidoCombo: () => [ENDPOINT.STATVERIFY_SERVICE.ST_ANLS_MST, "sido"] as const,
|
|
sigunguCombo: (sidoCd: string) =>
|
|
[ENDPOINT.STATVERIFY_SERVICE.ST_ANLS_MST, "sigungu", sidoCd] as const,
|
|
};
|
|
|
|
export function useInstlSncnList(params: InstlSncnMngSearchParams) {
|
|
return useQuery({
|
|
queryKey: [...instlSncnKeys.list(), params],
|
|
queryFn: () => instlSncnService.getPage(params),
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnDetail(id: string) {
|
|
return useQuery({
|
|
queryKey: instlSncnKeys.detail(id),
|
|
queryFn: () => instlSncnService.getById(id),
|
|
enabled: Boolean(id),
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnSidoCombo() {
|
|
return useQuery({
|
|
queryKey: instlSncnKeys.sidoCombo(),
|
|
queryFn: () => instlSncnRegionService.getSidoCombo(),
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnSigunguCombo(sidoCd: string) {
|
|
return useQuery({
|
|
queryKey: instlSncnKeys.sigunguCombo(sidoCd),
|
|
queryFn: () => instlSncnRegionService.getSigunguCombo(sidoCd),
|
|
enabled: Boolean(sidoCd),
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnSave() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (payload: InstlSncnMngSaveRequestDto) => instlSncnService.save(payload),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnSaveApply() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (payload: InstlSncnApplySaveRequestDto) => instlSncnService.saveApply(payload),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnUpdate() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ id, payload }: { id: string; payload: InstlSncnMngUpdateRequestDto }) =>
|
|
instlSncnService.update(id, payload),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.detail(variables.id) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnTechReview() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ id, payload }: { id: string; payload: InstlSncnApplySaveRequestDto }) =>
|
|
instlSncnService.techReview(id, payload),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.detail(variables.id) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnSubmitSupplement() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ id, payload }: { id: string; payload: InstlSncnApplySaveRequestDto }) =>
|
|
instlSncnService.submitSupplement(id, payload),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.detail(variables.id) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnSubmitReqSupplement() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ id, payload }: { id: string; payload: InstlSncnApplySaveRequestDto }) =>
|
|
instlSncnService.submitReqSupplement(id, payload),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.detail(variables.id) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnRemove() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (id: string) => instlSncnService.remove(id),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useInstlSncnChangePrgrsStts() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (payload: DocPrgrsUpdateRequestDto) =>
|
|
instlSncnService.changePrgrsSttsComCd(payload),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
|
|
queryClient.invalidateQueries({
|
|
queryKey: instlSncnKeys.detail(variables.docNo),
|
|
});
|
|
},
|
|
});
|
|
}
|