260914_01_ENH: 1차 완성
This commit is contained in:
65
src/query/review.ts
Normal file
65
src/query/review.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
"use client";
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { nextApi } from "@/lib/http-client";
|
||||
import { queryKeys } from "@/query/key/keys";
|
||||
import type { PerformanceReview, PerformanceReviewSlot } from "@/types/kmusical";
|
||||
|
||||
export const useReviewSlotsQuery = () => useQuery({
|
||||
queryKey: queryKeys.review.slots,
|
||||
queryFn: () => nextApi.get<PerformanceReviewSlot[]>("/review/slots"),
|
||||
});
|
||||
|
||||
export const useReviewFileQuery = (performanceId: string, reviewSlot: number) => useQuery({
|
||||
queryKey: queryKeys.review.detail(performanceId, reviewSlot),
|
||||
queryFn: () => nextApi.get<PerformanceReview>(`/review/${encodeURIComponent(performanceId)}/${reviewSlot}`),
|
||||
enabled: Boolean(performanceId),
|
||||
});
|
||||
|
||||
export function useUploadReviewFileMutation(performanceId: string, reviewSlot: number) {
|
||||
const client = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ formData, paramUserId }: { formData: FormData; paramUserId?: string }) =>
|
||||
nextApi.postForm<PerformanceReview>(
|
||||
`/review/${encodeURIComponent(performanceId)}/${reviewSlot}`,
|
||||
formData,
|
||||
paramUserId ? { query: { paramUserId } } : undefined
|
||||
),
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.review.detail(performanceId, reviewSlot) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadReviewOriginalMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ performanceId, reviewSlot }: { performanceId: string; reviewSlot: number }) =>
|
||||
nextApi.get<ArrayBuffer>(`/review/download/${encodeURIComponent(performanceId)}/${reviewSlot}`, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadReviewPdfMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ performanceId, reviewSlot }: { performanceId: string; reviewSlot: number }) =>
|
||||
nextApi.get<ArrayBuffer>(`/review/pdf/${encodeURIComponent(performanceId)}/${reviewSlot}`, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadReviewTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (reviewType: number) =>
|
||||
nextApi.get<ArrayBuffer>(`/review/template/download/${reviewType}`, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadReviewPdfTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (reviewType: number) =>
|
||||
nextApi.get<ArrayBuffer>(`/review/template/pdf/${reviewType}`, { expectBinary: true }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUploadReviewTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({ reviewType, formData }: { reviewType: number; formData: FormData }) =>
|
||||
nextApi.postForm<string>(`/review/template/upload/${reviewType}`, formData),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user