several changes
This commit is contained in:
36
src/features/tournaments/hooks/use-create-tournament.ts
Normal file
36
src/features/tournaments/hooks/use-create-tournament.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { createTournament } from "@/features/tournaments/server";
|
||||
import toast from '@/lib/sonner';
|
||||
import { TournamentInput } from "@/features/tournaments/types";
|
||||
import { logger } from "../";
|
||||
|
||||
const useCreateTournament = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: TournamentInput) => createTournament({ data }),
|
||||
onMutate: (data) => {
|
||||
logger.info('Creating tournament', data);
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (!data) {
|
||||
toast.error('There was an issue creating your tournament. Please try again later.');
|
||||
logger.error('Error creating tournament', data);
|
||||
} else {
|
||||
logger.info('Tournament created successfully', data);
|
||||
navigate({ to: '/tournaments' });
|
||||
}
|
||||
},
|
||||
onError: (error: any) => {
|
||||
logger.error('Error creating tournament', error);
|
||||
if (error.message) {
|
||||
toast.error(error.message);
|
||||
} else {
|
||||
toast.error('An unexpected error occurred when trying to create a tournament. Please try again later.');
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default useCreateTournament;
|
||||
12
src/features/tournaments/hooks/use-update-tournament.ts
Normal file
12
src/features/tournaments/hooks/use-update-tournament.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { updateTournament } from "@/features/tournaments/server";
|
||||
import { TournamentFormInput } from "@/features/tournaments/types";
|
||||
|
||||
const useUpdateTournament = (tournamentId: string) => {
|
||||
return useMutation({
|
||||
mutationFn: (data: Partial<TournamentFormInput>) =>
|
||||
updateTournament({ data: { id: tournamentId, updates: data } }),
|
||||
});
|
||||
};
|
||||
|
||||
export default useUpdateTournament;
|
||||
Reference in New Issue
Block a user