59 lines
2.2 KiB
TypeScript
59 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { nextApi } from "@/lib/http-client";
|
|
import { queryKeys } from "@/query/key/keys";
|
|
import type {
|
|
AssignUserCount,
|
|
MonitoringApplyUser,
|
|
PerformanceApplyCount,
|
|
PerformanceAssign,
|
|
PerformanceAssignRequest,
|
|
} from "@/types/kmusical";
|
|
|
|
export const useMonitoringApplyUsersCountQuery = () => useQuery({
|
|
queryKey: queryKeys.assign.monitoringApplyUsersCount,
|
|
queryFn: () => nextApi.get<PerformanceApplyCount[]>("/assign/monitoring/apply-users/count"),
|
|
});
|
|
|
|
export const useMonitoringApplyUsersQuery = (performanceId: string, options?: {ignoreGlobalLoading?: boolean}) => useQuery({
|
|
queryKey: queryKeys.assign.monitoringApplyUsers(performanceId),
|
|
queryFn: () => nextApi.get<MonitoringApplyUser[]>(`/assign/monitoring/apply-users/${encodeURIComponent(performanceId)}`),
|
|
enabled: Boolean(performanceId),
|
|
meta: {ignoreGlobalLoading: options?.ignoreGlobalLoading ?? false},
|
|
});
|
|
|
|
export const useAllMonitoringApplyUsersQuery = (enabled = true) => useQuery({
|
|
queryKey: queryKeys.assign.allMonitoringApplyUsers,
|
|
queryFn: () => nextApi.get<MonitoringApplyUser[]>("/assign/monitoring/apply-users"),
|
|
enabled,
|
|
});
|
|
|
|
export const useAssignUserCountsQuery = () => useQuery({
|
|
queryKey: queryKeys.assign.userCounts,
|
|
queryFn: () => nextApi.get<AssignUserCount[]>("/assign/users/count"),
|
|
});
|
|
|
|
export function useConfirmAssignMutation() {
|
|
const client = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (request: PerformanceAssignRequest) => nextApi.post<PerformanceAssign>("/assign", request),
|
|
onSuccess: () => {
|
|
client.invalidateQueries({ queryKey: queryKeys.assign.all });
|
|
client.invalidateQueries({ queryKey: queryKeys.performance.all });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useCancelAssignMutation() {
|
|
const client = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ performanceId, reviewSlot }: { performanceId: string; reviewSlot: number }) =>
|
|
nextApi.del<void>(`/assign/${encodeURIComponent(performanceId)}/${reviewSlot}`),
|
|
onSuccess: () => {
|
|
client.invalidateQueries({ queryKey: queryKeys.assign.all });
|
|
client.invalidateQueries({ queryKey: queryKeys.performance.all });
|
|
},
|
|
});
|
|
}
|