-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseParticipants.ts
More file actions
40 lines (35 loc) · 1.26 KB
/
useParticipants.ts
File metadata and controls
40 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { getParticipants } from '../../../features/dashboard/api/participants';
import { useParams } from 'react-router-dom';
import { ApiResponse } from '../../../shared/types/api/apiResponse';
import { AxiosError } from 'axios';
import { approveParticipants } from '../../../features/dashboard/api/participants';
export const useParticipants = (tags: string = 'all', page: number = 0, size: number = 300) => {
const { id } = useParams();
const eventId = Number(id);
const {
data: participantInfo,
isLoading,
error,
} = useQuery({
queryKey: ['participants', eventId, tags, page, size],
queryFn: () => getParticipants(eventId, tags, page, size),
enabled: !!eventId,
});
return {
participants: participantInfo || [],
isLoading,
error,
};
};
export const useApproveParticipants = (orderId: number) => {
const queryClient = useQueryClient();
return useMutation<ApiResponse<string>, AxiosError, { orderId: number }>({
mutationFn: () => approveParticipants({ orderId }),
onSuccess: () => {
queryClient.invalidateQueries({
predicate: query => Array.isArray(query.queryKey) && query.queryKey[0] === 'participants',
});
},
});
};