Skip to content

Commit

Permalink
feat: implement query of validate invite code
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Oct 10, 2024
1 parent d7181e7 commit 55b0dd8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/store/queries/useAuthQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';

import { postSignIn, postSignUp } from '@/api/auth';
import { postSignIn, postSignUp, validateInviteCode } from '@/api/auth';
import { getMy } from '@/api/my';
import queryClient from '@/api/queryClient';
import { authRouteNames } from '@/constants';
Expand All @@ -12,6 +12,10 @@ import { navigate } from '@/utils/navigation';
export const authQueryKeys = {
keychainToken: () => ['token-from-keychain'],
my: () => ['my-information'],
validateInviteCode: (inviteCode: string | null) => [
'validateInviteCode',
inviteCode,
],
};

const ASYNC_STORAGE_KEY = {
Expand Down Expand Up @@ -91,3 +95,12 @@ export function useSignUp() {
},
});
}

export function useValidateInviteCode(inviteCode: string | null) {
return useQuery({
queryKey: authQueryKeys.validateInviteCode(inviteCode),
queryFn: () => validateInviteCode({ inviteCode } as { inviteCode: string }),
enabled: !!inviteCode && inviteCode.length === 8,
staleTime: 1000,
});
}

0 comments on commit 55b0dd8

Please sign in to comment.