-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathuseCheckLocation.ts
More file actions
27 lines (25 loc) · 931 Bytes
/
useCheckLocation.ts
File metadata and controls
27 lines (25 loc) · 931 Bytes
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
import { useQuery } from '@tanstack/react-query';
import { generateQueryKey, RequestKey } from '../lib/query';
import type { LoggedUser } from '../lib/user';
import { useAuthContext } from '../contexts/AuthContext';
import { useRequestProtocol } from './useRequestProtocol';
import { CHECK_LOCATION_QUERY } from '../graphql/users';
export const useCheckLocation = (): void => {
const { user, isFetched, updateUser } = useAuthContext();
const { requestMethod } = useRequestProtocol();
useQuery({
queryKey: generateQueryKey(RequestKey.CheckLocation, user),
queryFn: async () => {
const result = await requestMethod<{
location: Pick<LoggedUser, 'hasLocationSet'>;
}>(CHECK_LOCATION_QUERY);
await updateUser({
...user!,
hasLocationSet: !!result,
});
},
staleTime: Infinity,
gcTime: Infinity,
enabled: !!user && isFetched && !user.hasLocationSet,
});
};