260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
122
src/query/assign.ts
Normal file
122
src/query/assign.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {AssignUserCount, MonitoringApplyUser, PerformanceApplyCount, PerformanceAssign, PerformanceFull} from "@/types/gwcf";
|
||||
import {ExcelUploadResult} from "@/types/common";
|
||||
|
||||
const MONITORING_ASSIGN_TYPE = 1;
|
||||
|
||||
const mergeMonitoringAssigns = <T extends PerformanceFull>(performance: T, monitoringAssigns: PerformanceAssign[]): T => ({
|
||||
...performance,
|
||||
performanceAssignList: [
|
||||
...(performance.performanceAssignList ?? []).filter((assign) => assign.assignType !== MONITORING_ASSIGN_TYPE),
|
||||
...monitoringAssigns,
|
||||
],
|
||||
});
|
||||
|
||||
export function useMonitoringApplyUsersQuery(performanceId: number, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.assignApplyUsers(performanceId),
|
||||
queryFn: () => nextApi.get<MonitoringApplyUser[]>(`/assign/monitoring/apply-users/${performanceId}`),
|
||||
enabled: enabled && performanceId > 0,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useAssignUserCountsQuery(enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.assignUserCounts(),
|
||||
queryFn: () => nextApi.get<AssignUserCount[]>("/assign/users/count"),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonitoringApplyUserCountsQuery(enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.assignApplyUserCounts(),
|
||||
queryFn: () => nextApi.get<PerformanceApplyCount[]>("/assign/monitoring/apply-users/count"),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useSaveMonitoringAssignMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userIds}: {performanceId: number; userIds: string[]}) =>
|
||||
nextApi.post<PerformanceAssign[]>("/assign/monitoring", {performanceId, userIds}),
|
||||
onSuccess: (res, {performanceId}) => {
|
||||
qc.setQueryData<PerformanceFull | undefined>(qk.performance(performanceId), (old) =>
|
||||
old ? mergeMonitoringAssigns(old, res) : old
|
||||
);
|
||||
qc.setQueryData<PerformanceFull[] | undefined>(qk.performanceList(), (old) =>
|
||||
old?.map((performance) => performance.id === performanceId ? mergeMonitoringAssigns(performance, res) : performance)
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useAssignConfirmMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userId}: {performanceId: number; userId: string}) =>
|
||||
nextApi.patch<void>(`/assign/confirm/${performanceId}/${encodeURIComponent(userId)}`),
|
||||
onSuccess: (_res, {performanceId, userId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.assignConfirm(performanceId, userId) });
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useAssignCancelMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userId}: {performanceId: number; userId: string}) =>
|
||||
nextApi.patch<void>(`/assign/cancel/${performanceId}/${encodeURIComponent(userId)}`),
|
||||
onSuccess: (_res, {performanceId, userId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.assignConfirm(performanceId, userId) });
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useKonAssignConfirmMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userId}: {performanceId: number; userId: string}) =>
|
||||
nextApi.post<string>(`/assign/confirm/${performanceId}/${encodeURIComponent(userId)}`),
|
||||
onSuccess: (_res, {performanceId, userId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.assignConfirm(performanceId, userId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadWrittenAssignExcelMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (file: File): Promise<ExcelUploadResult> => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
return nextApi.postForm<ExcelUploadResult>("/assign/written/excel-upload", formData);
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
if (!res.hasErrorFile) {
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
54
src/query/code.ts
Normal file
54
src/query/code.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
"use client";
|
||||
|
||||
import {useQueries, useQuery} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {Code} from "@/types/gwcf";
|
||||
|
||||
export const CODE_GROUPS = [
|
||||
"area",
|
||||
"assign_type",
|
||||
"business_type",
|
||||
"gender",
|
||||
"genre",
|
||||
"has_car",
|
||||
"monitoring_visit_status",
|
||||
"review_status",
|
||||
"review_type",
|
||||
"staff_type",
|
||||
"ticket_reservation_status",
|
||||
"user_role",
|
||||
] as const;
|
||||
|
||||
export type CodeGroup = (typeof CODE_GROUPS)[number];
|
||||
|
||||
export function useCodeQuery(codeGroup: CodeGroup, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.codes(codeGroup),
|
||||
queryFn: () => nextApi.get<Code[]>(`/code/${codeGroup}`),
|
||||
enabled,
|
||||
staleTime: 10 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCodesQuery(groups: readonly CodeGroup[] = CODE_GROUPS) {
|
||||
return useQueries({
|
||||
queries: groups.map((codeGroup) => ({
|
||||
queryKey: qk.codes(codeGroup),
|
||||
queryFn: () => nextApi.get<Code[]>(`/code/${codeGroup}`),
|
||||
staleTime: 10 * 60_000,
|
||||
})),
|
||||
combine: (results) => {
|
||||
const data = groups.reduce<Record<CodeGroup, Code[]>>((acc, group, index) => {
|
||||
acc[group] = results[index].data ?? [];
|
||||
return acc;
|
||||
}, {} as Record<CodeGroup, Code[]>);
|
||||
|
||||
return {
|
||||
data,
|
||||
isLoading: results.some((result) => result.isLoading),
|
||||
isError: results.some((result) => result.isError),
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
19
src/query/key/keys.ts
Normal file
19
src/query/key/keys.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const qk = {
|
||||
codes: (codeGroup: string) => ["code", codeGroup] as const,
|
||||
|
||||
users: (userRole: number) => ["user", "list", userRole] as const,
|
||||
user: (userId: string) => ["user", "detail", userId] as const,
|
||||
|
||||
performanceList: () => ["performance", "list"] as const,
|
||||
performanceCompactList: () => ["performance", "list", "compact"] as const,
|
||||
performance: (performanceId: number) => ["performance", "detail", performanceId] as const,
|
||||
|
||||
assignApplyUsers: (performanceId: number) => ["assign", "monitoring", "apply-users", performanceId] as const,
|
||||
assignApplyUserCounts: () => ["assign", "monitoring", "apply-users", "count"] as const,
|
||||
assignUserCounts: () => ["assign", "users", "count"] as const,
|
||||
assignConfirm: (performanceId: number, userId: string) => ["assign", "confirm", performanceId, userId] as const,
|
||||
|
||||
monitoringEvidence: (performanceId: number, userId: string) => ["monitoring", "evidence", performanceId, userId] as const,
|
||||
|
||||
review: (performanceId: number, reviewType: number) => ["review", performanceId, reviewType] as const,
|
||||
} as const;
|
||||
56
src/query/monitoring.ts
Normal file
56
src/query/monitoring.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {MonitoringGpsRequest, PerformanceMonitoringVisit} from "@/types/gwcf";
|
||||
|
||||
export function useSaveDepartureMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, gps}: {performanceId: number; gps: MonitoringGpsRequest}) =>
|
||||
nextApi.post<PerformanceMonitoringVisit>(`/monitoring/visit/departure/${performanceId}`, gps),
|
||||
onSuccess: (_res, {performanceId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useSaveArrivalMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, gps, files}: {performanceId: number; gps: MonitoringGpsRequest; files?: File[]}) => {
|
||||
const formData = new FormData();
|
||||
formData.append("gps", new Blob([JSON.stringify(gps)], {type: "application/json"}));
|
||||
files?.forEach((file) => formData.append("files", file, file.name));
|
||||
return nextApi.postForm<PerformanceMonitoringVisit>(`/monitoring/visit/arrival/${performanceId}`, formData);
|
||||
},
|
||||
onSuccess: (_res, {performanceId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonitoringEvidenceQuery(performanceId: number, userId: string, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.monitoringEvidence(performanceId, userId),
|
||||
queryFn: () => nextApi.get<PerformanceMonitoringVisit[]>(`/monitoring/visit/evidence/${performanceId}/${encodeURIComponent(userId)}`),
|
||||
enabled: enabled && performanceId > 0 && Boolean(userId),
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadEvidenceZipMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userId}: {performanceId: number; userId: string}) =>
|
||||
nextApi.get<ArrayBuffer>(
|
||||
`/monitoring/visit/evidence/zip/${performanceId}/${encodeURIComponent(userId)}`,
|
||||
{expectBinary: true}
|
||||
),
|
||||
});
|
||||
}
|
||||
35
src/query/notification.ts
Normal file
35
src/query/notification.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {BulkSendResponse, SaveTemplateRequest, SendSmsBulkRequest, Template} from "@/types/notification";
|
||||
|
||||
export const SMS_TEMPLATE_IDS = {
|
||||
ACCOUNT_MONITORING: 45,
|
||||
ASSIGN_CONFIRM: 46,
|
||||
CUSTOM: 47,
|
||||
} as const;
|
||||
|
||||
export const NOTIFICATION_REQUEST_SERVICE = "gwcf-review";
|
||||
|
||||
export function useNotificationTemplateQuery(templateIdx: number, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: ["notification", "template", templateIdx],
|
||||
queryFn: () => nextApi.get<Template>(`/notification/template/${templateIdx}`),
|
||||
enabled: enabled && templateIdx > 0,
|
||||
});
|
||||
}
|
||||
|
||||
export function useSaveNotificationTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (data: SaveTemplateRequest) =>
|
||||
nextApi.patch<Template>("/notification/template", data),
|
||||
});
|
||||
}
|
||||
|
||||
export function useSendSmsBulkMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (data: SendSmsBulkRequest) =>
|
||||
nextApi.post<BulkSendResponse>("/notification/sms-bulk", data),
|
||||
});
|
||||
}
|
||||
100
src/query/performance.ts
Normal file
100
src/query/performance.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {ExcelUploadResult} from "@/types/common";
|
||||
import {PerformanceCompact, PerformanceFull} from "@/types/gwcf";
|
||||
|
||||
export function usePerformanceListQuery(enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.performanceList(),
|
||||
queryFn: () => nextApi.get<PerformanceFull[]>("/performance/list"),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function usePerformanceCompactListQuery(enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.performanceCompactList(),
|
||||
queryFn: () => nextApi.get<PerformanceCompact[]>("/performance/list/compact"),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function usePerformanceDetailQuery(performanceId: number, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.performance(performanceId),
|
||||
queryFn: () => nextApi.get<PerformanceFull>(`/performance/${performanceId}`),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdatePerformanceMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: PerformanceCompact) => nextApi.patch<void>("/performance", data),
|
||||
onSuccess: (_res, data) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(data.id) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeletePerformanceMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (performanceId: number) => nextApi.del<void>(`/performance/${performanceId}`),
|
||||
onSuccess: (_res, performanceId) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadPerformanceExcelMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (file: File): Promise<ExcelUploadResult> => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
return nextApi.postForm<ExcelUploadResult>("/performance/excel-upload", formData);
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
if (!res.hasErrorFile) {
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadPerformanceExcelTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
nextApi.post<ArrayBuffer>(
|
||||
"/performance/excel-template",
|
||||
undefined,
|
||||
{ expectBinary: true }
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadAssignExcelTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
nextApi.post<ArrayBuffer>(
|
||||
"/assign/written/excel-template",
|
||||
undefined,
|
||||
{ expectBinary: true }
|
||||
),
|
||||
});
|
||||
}
|
||||
72
src/query/review.ts
Normal file
72
src/query/review.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {PerformanceReview} from "@/types/gwcf";
|
||||
|
||||
export function useReviewFileQuery(performanceId: number, reviewType: number, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.review(performanceId, reviewType),
|
||||
queryFn: () => nextApi.get<PerformanceReview>(`/review/${performanceId}/${reviewType}`),
|
||||
enabled: enabled && performanceId > 0 && reviewType > 0,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadReviewFileMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, reviewType, file}: {performanceId: number; reviewType: number; file: File}) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file, file.name);
|
||||
return nextApi.postForm<PerformanceReview>(`/review/${performanceId}/${reviewType}`, formData);
|
||||
},
|
||||
onSuccess: (_res, {performanceId, reviewType}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.review(performanceId, reviewType) });
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadReviewOriginalMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, reviewType}: {performanceId: number; reviewType: number}) =>
|
||||
nextApi.get<ArrayBuffer>(`/review/download/${performanceId}/${reviewType}`, {expectBinary: true}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadReviewPdfMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, reviewType}: {performanceId: number; reviewType: number}) =>
|
||||
nextApi.get<ArrayBuffer>(`/review/pdf/${performanceId}/${reviewType}`, {expectBinary: true}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useStartWrittenReviewMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (performanceId: number) => nextApi.post<void>(`/review/start/${performanceId}`),
|
||||
onSuccess: (_res, performanceId) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEndWrittenReviewMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userId}: {performanceId: number; userId: string}) =>
|
||||
nextApi.post<void>(`/review/end/${performanceId}/${encodeURIComponent(userId)}`),
|
||||
onSuccess: (_res, {performanceId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
79
src/query/user.ts
Normal file
79
src/query/user.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {ExcelUploadResult} from "@/types/common";
|
||||
import {UserFull} from "@/types/gwcf";
|
||||
|
||||
export function useUsersQuery(userRole: number, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.users(userRole),
|
||||
queryFn: () => nextApi.get<UserFull[]>(`/user/list/${userRole}`),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useUserDetailQuery(userId: string, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.user(userId),
|
||||
queryFn: () => nextApi.get<UserFull>(`/user/${encodeURIComponent(userId)}`),
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateUserMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: UserFull) => nextApi.patch<void>("/user", data),
|
||||
onSuccess: (_res, data) => {
|
||||
qc.invalidateQueries({ queryKey: qk.user(data.userId) });
|
||||
qc.invalidateQueries({ queryKey: ["user", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteUserMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (userId: string) => nextApi.del<void>(`/user/${encodeURIComponent(userId)}`),
|
||||
onSuccess: (_res, userId) => {
|
||||
qc.invalidateQueries({ queryKey: qk.user(userId) });
|
||||
qc.invalidateQueries({ queryKey: ["user", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadUsersExcelMutation(userRole: number) {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (file: File): Promise<ExcelUploadResult> => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
return nextApi.postForm<ExcelUploadResult>(`/user/excel-upload/${userRole}`, formData);
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
if (!res.hasErrorFile) {
|
||||
qc.invalidateQueries({ queryKey: qk.users(userRole) });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadUserExcelTemplateMutation(userRole: number) {
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
nextApi.post<ArrayBuffer>(
|
||||
`/user/excel-template/${userRole}`,
|
||||
undefined,
|
||||
{ expectBinary: true }
|
||||
),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user