way better auth middleware, enroll team server fn and pb fn

This commit is contained in:
yohlo
2025-08-24 00:10:09 -05:00
parent 4427bd5494
commit 53276cc18e
6 changed files with 164 additions and 70 deletions

View File

@@ -0,0 +1,30 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { enrollTeam } from "@/features/tournaments/server";
import toast from '@/lib/sonner';
const useEnrollTeam = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: { tournamentId: string, teamId: string }) => {
return enrollTeam({ data });
},
onSuccess: (data, { tournamentId }) => {
if (!data) {
toast.error('There was an issue enrolling. Please try again later.');
} else {
queryClient.invalidateQueries({ queryKey: ['tournaments', 'detail', tournamentId] });
toast.success('Team enrolled successfully!');
}
},
onError: (error: any) => {
if (error.message) {
toast.error(error.message);
} else {
toast.error('An unexpected error occurred when trying to enroll the team. Please try again later.');
}
},
});
};
export default useEnrollTeam;