80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import type {
|
|
EsntlAtchFileMngSaveRequest,
|
|
EsntlAtchFileMngSearchParams,
|
|
EsntlAtchFileMngTreeSearchParams,
|
|
} from "../model/esntl-interface";
|
|
|
|
import { esntlAtchFileMngService } from "./esntl-service";
|
|
|
|
const esntlAtchFileMngBaseKey = [ENDPOINT.AS_COMMON_SERVICE.ESNTL_ATCH_FILE] as const;
|
|
|
|
export function useEsntlAtchFileMngTree(params: EsntlAtchFileMngTreeSearchParams) {
|
|
return useQuery({
|
|
queryKey: [...esntlAtchFileMngBaseKey, "tree", params],
|
|
queryFn: () => esntlAtchFileMngService.findTree(params),
|
|
enabled: Boolean(params.docSeComCd),
|
|
staleTime: Infinity,
|
|
});
|
|
}
|
|
|
|
export function useEsntlAtchFileMngPage(params: EsntlAtchFileMngSearchParams) {
|
|
return useQuery({
|
|
queryKey: [...esntlAtchFileMngBaseKey, "page", params],
|
|
queryFn: () => esntlAtchFileMngService.findPage(params),
|
|
});
|
|
}
|
|
|
|
export function useEsntlAtchFileMng(esntlAtchFileId: string | null | undefined) {
|
|
return useQuery({
|
|
queryKey: [...esntlAtchFileMngBaseKey, esntlAtchFileId],
|
|
queryFn: () => esntlAtchFileMngService.findById(esntlAtchFileId!),
|
|
enabled: Boolean(esntlAtchFileId),
|
|
});
|
|
}
|
|
|
|
export function useCreateEsntlAtchFileMng() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (body: EsntlAtchFileMngSaveRequest) => esntlAtchFileMngService.create(body),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: esntlAtchFileMngBaseKey });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateEsntlAtchFileMng() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({
|
|
esntlAtchFileId,
|
|
body,
|
|
}: {
|
|
esntlAtchFileId: string;
|
|
body: EsntlAtchFileMngSaveRequest;
|
|
}) => esntlAtchFileMngService.update(esntlAtchFileId, body),
|
|
onSuccess: (_data, { esntlAtchFileId }) => {
|
|
queryClient.invalidateQueries({ queryKey: esntlAtchFileMngBaseKey });
|
|
queryClient.invalidateQueries({
|
|
queryKey: [...esntlAtchFileMngBaseKey, esntlAtchFileId],
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteEsntlAtchFileMng() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (esntlAtchFileId: string) => esntlAtchFileMngService.remove(esntlAtchFileId),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: esntlAtchFileMngBaseKey });
|
|
},
|
|
});
|
|
}
|