260702_01_ENH: 리스트 작업 도중 공용 ui를 적용하기 위한 중간 커밋
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
import {keepPreviousData, useQuery} from "@tanstack/react-query";
|
||||
import {keepPreviousData, useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {listHeader, ListSearchRequest, ListSearchWithFullResult} from "@/types/list";
|
||||
import {PageResponse} from "@/types/common";
|
||||
import {
|
||||
ExcelUploadResult,
|
||||
listHeader,
|
||||
ListEventHistDownloadRequest,
|
||||
ListFilter,
|
||||
ListResetRequest,
|
||||
ListSearchRequest,
|
||||
ListSearchWithFullResult,
|
||||
ListUpdateRequest,
|
||||
ListUploadHistory,
|
||||
ListUploadRequest,
|
||||
} from "@/types/list";
|
||||
import type { PageResponse } from "@kri/common";
|
||||
import {ListHeaderAssignConst} from "@/const/listConst";
|
||||
|
||||
export function useListHeaderQuery(prjctIdx: number, enabled: boolean) {
|
||||
|
||||
return useQuery({
|
||||
queryKey: qk.listHeader(prjctIdx),
|
||||
queryFn: () =>
|
||||
@@ -30,8 +40,8 @@ const serializeListSearchRequest = (request: ListSearchRequest) => ({
|
||||
[ListHeaderAssignConst.CONTACT_INTERVIEWER]: [],
|
||||
[ListHeaderAssignConst.FIELD_INTERVIEWER]: [],
|
||||
},
|
||||
memo: request.listFilter.memo ?? "",
|
||||
otherItems: request.listFilter.otherItems ?? {},
|
||||
memoConditions: request.listFilter.memoConditions ?? [],
|
||||
otherItemConditions: request.listFilter.otherItemConditions ?? [],
|
||||
},
|
||||
pageRequest: request.pageRequest,
|
||||
});
|
||||
@@ -53,3 +63,112 @@ export function useListSearchQuery(prjctIdx: number, request: ListSearchRequest,
|
||||
meta: { ignoreGlobalLoading: true },
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadListExcelTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (prjctIdx: number) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/excel-template/${prjctIdx}`, undefined, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useListUploadHistoryQuery(prjctIdx: number, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: qk.listUploadHistory(prjctIdx),
|
||||
queryFn: () => nextApi.get<ListUploadHistory[]>(`/list/upload-history/${prjctIdx}`),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
placeholderData: keepPreviousData,
|
||||
meta: { ignoreGlobalLoading: true },
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadListExcelMutation(prjctIdx: number) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ file, request }: { file: File; request: ListUploadRequest }) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("request", new Blob([JSON.stringify(request)], { type: "application/json" }));
|
||||
return nextApi.postForm<ExcelUploadResult>(`/list/excel-upload/${prjctIdx}`, formData);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: qk.listHeader(prjctIdx) }),
|
||||
queryClient.invalidateQueries({ queryKey: qk.listUploadHistory(prjctIdx) }),
|
||||
queryClient.invalidateQueries({ queryKey: ["list", "search-filter"] }),
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateListHeaderMutation(prjctIdx: number) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (rows: listHeader[]) => nextApi.patch<void>(`/list/header/${prjctIdx}`, rows),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: qk.listHeader(prjctIdx) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useResetListMutation(prjctIdx: number) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (request: ListResetRequest) => nextApi.del<number>(`/list/${prjctIdx}`, { json: request }),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateListMutation(prjctIdx: number) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (request: ListUpdateRequest) => nextApi.patch<number>(`/list/update/${prjctIdx}`, request),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["list", "search-filter"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadListMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (listFilter: ListFilter) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/excel-download/${prjctIdx}`, listFilter, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadListUpdateHistoryMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (listFilter: ListFilter) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/excel-download-update/${prjctIdx}`, listFilter, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadListEventHistoryMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (request: ListEventHistDownloadRequest) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/event-history-download/${prjctIdx}`, request, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadListItemFileMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (listFilter: ListFilter) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/item-file-download/${prjctIdx}`, listFilter, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadUploadHistoryFileMutation(prjctIdx: number) {
|
||||
return useMutation({
|
||||
mutationFn: (listUploadLogId: string) =>
|
||||
nextApi.post<ArrayBuffer>(`/list/upload-history-file/${prjctIdx}/${listUploadLogId}`, undefined, {
|
||||
expectBinary: true,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user