260914_01_ENH: 1차 완성

This commit is contained in:
2026-09-14 15:07:40 +09:00
parent a6642c9a00
commit f1d21d3711
67 changed files with 5595 additions and 148 deletions

60
src/query/performance.ts Normal file
View File

@@ -0,0 +1,60 @@
"use client";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { ExcelUploadResult } from "@kri/common";
import { nextApi } from "@/lib/http-client";
import { queryKeys } from "@/query/key/keys";
import type { PerformanceCompact, PerformanceFull } from "@/types/kmusical";
export const usePerformanceListQuery = () => useQuery({
queryKey: queryKeys.performance.list,
queryFn: () => nextApi.get<PerformanceFull[]>("/performance/list"),
});
export const usePerformanceCompactListQuery = () => useQuery({
queryKey: queryKeys.performance.listCompact,
queryFn: () => nextApi.get<PerformanceCompact[]>("/performance/list/compact"),
});
export const usePerformanceQuery = (performanceId: string) => useQuery({
queryKey: queryKeys.performance.detail(performanceId),
queryFn: () => nextApi.get<PerformanceFull>(`/performance/${encodeURIComponent(performanceId)}`),
enabled: Boolean(performanceId),
});
export function useUpdatePerformanceMutation() {
const client = useQueryClient();
return useMutation({
mutationFn: (request: PerformanceCompact) => nextApi.patch<void>("/performance", request),
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.performance.all }),
});
}
export function useDeletePerformanceMutation() {
const client = useQueryClient();
return useMutation({
mutationFn: (performanceId: string) => nextApi.del<void>(`/performance/${encodeURIComponent(performanceId)}`),
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.performance.all }),
});
}
export function useExportPerformanceMutation() {
return useMutation({
mutationFn: (performanceIds: string[]) =>
nextApi.post<ArrayBuffer>("/performance/excel/download", performanceIds, { expectBinary: true }),
});
}
export function useExportPerformanceTemplateMutation() {
return useMutation({
mutationFn: () => nextApi.post<ArrayBuffer>("/performance/excel/template", undefined, { expectBinary: true }),
});
}
export function useUploadPerformanceExcelMutation() {
const client = useQueryClient();
return useMutation({
mutationFn: (formData: FormData) => nextApi.postForm<ExcelUploadResult>("/performance/excel/upload", formData),
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.performance.all }),
});
}