Raid Layout page working
This commit is contained in:
@@ -52,6 +52,25 @@ export function useGetClassGroupsCount(raidGroupId: string, searchTerm?: string)
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetClassGroupsByRaidLayout(raidGroupId: string, raidLayoutId: string | undefined){
|
||||
return useQuery({
|
||||
queryKey: ["classGroups", "raidLayout", raidLayoutId],
|
||||
queryFn: async () => {
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup/raidLayout/${raidLayoutId}`);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to get class groups");
|
||||
}
|
||||
else if(response.data.error){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as (ClassGroup | null)[];
|
||||
},
|
||||
enabled: !!raidLayoutId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function useCreateClassGroup(raidGroupId: string){
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
130
src/hooks/RaidLayoutHooks.ts
Normal file
130
src/hooks/RaidLayoutHooks.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
import { RaidLayout, RaidLayoutClassGroupXref } from "@/interface/RaidLayout";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
|
||||
export function useGetRaidLayoutsByRaidGroup(raidGroupId: string, page: number, pageSize: number, searchTerm?: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidLayouts", raidGroupId, {page, pageSize, searchTerm}],
|
||||
queryFn: async () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append("page", page.toString());
|
||||
params.append("pageSize", pageSize.toString());
|
||||
if(searchTerm){
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout?${params}`);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to get accounts");
|
||||
}
|
||||
else if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidLayout[];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetRaidLayoutsByRaidGroupCount(raidGroupId: string, searchTerm?: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidLayouts", raidGroupId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
const params = new URLSearchParams();
|
||||
if(searchTerm){
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout/count?${params}`);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to get accounts");
|
||||
}
|
||||
else if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateRaidLayout(raidGroupId: string){
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["createRaidLayout", raidGroupId],
|
||||
mutationFn: async ({raidLayout, raidLayoutClassGroupXrefs}:{raidLayout: RaidLayout; raidLayoutClassGroupXrefs: RaidLayoutClassGroupXref[];}) => {
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/raidLayout`,
|
||||
{
|
||||
raidLayout,
|
||||
raidLayoutClassGroupXrefs
|
||||
}
|
||||
);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to create raid layout");
|
||||
}
|
||||
else if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateRaidLayout(raidGroupId: string){
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["updateRaidLayout", raidGroupId],
|
||||
mutationFn: async ({raidLayout, raidLayoutClassGroupXrefs}:{raidLayout: RaidLayout; raidLayoutClassGroupXrefs: RaidLayoutClassGroupXref[];}) => {
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/raidLayout/${raidLayout.raidLayoutId}`,
|
||||
{
|
||||
raidLayout,
|
||||
raidLayoutClassGroupXrefs
|
||||
}
|
||||
);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to update raid layout");
|
||||
}
|
||||
else if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
queryClient.invalidateQueries({ queryKey: ["classGroups", "raidLayout"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteRaidLayout(raidGroupId: string, raidLayoutId: string){
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ["deleteRaidLayout", raidGroupId, raidLayoutId],
|
||||
mutationFn: async () => {
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/raidLayout/${raidLayoutId}`);
|
||||
|
||||
if(response.status !== 200){
|
||||
throw new Error("Failed to delete raid layout");
|
||||
}
|
||||
else if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user