From 55b0dd81eb8aa8e8e827d1deaee3643e41eb7ff7 Mon Sep 17 00:00:00 2001 From: timepresent95 Date: Fri, 11 Oct 2024 01:02:09 +0900 Subject: [PATCH] feat: implement query of validate invite code #65 --- src/store/queries/useAuthQuery.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/store/queries/useAuthQuery.ts b/src/store/queries/useAuthQuery.ts index d3ef693..da28bb1 100644 --- a/src/store/queries/useAuthQuery.ts +++ b/src/store/queries/useAuthQuery.ts @@ -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'; @@ -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 = { @@ -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, + }); +}