adding all logic for sending request and should work?

This commit is contained in:
talksik
2022-03-19 22:49:43 -04:00
parent def2cd2085
commit 0faacbab73
7 changed files with 102 additions and 13 deletions
+31 -1
View File
@@ -48,6 +48,20 @@ const getConversationDetails = async (
return response.data;
};
const sendContactRequest = async (
idToken: string,
otherUserGoogleId: string
) => {
const response = await axios.post(
localHost + `/contacts/${otherUserGoogleId}`,
{
headers: { Authorization: idToken },
}
);
return response.data;
};
// ====== QUERIES
export enum Querytypes {
GET_USER_DETAILS = "GET_USER_DETAILS",
@@ -74,7 +88,7 @@ export function useSearch() {
return useQuery(
Querytypes.GET_SEARCH_RESULTS,
() => search(authTokens.idToken, searchQuery),
{ enabled: searchQuery ? true : false }
{ enabled: searchQuery ? true : false, refetchOnWindowFocus: false }
);
}
@@ -96,3 +110,19 @@ export function useCreateUser() {
},
});
}
export function useSendContactRequest() {
const authTokens = useRecoilValue($authTokens);
return useMutation(
(otherGoogleUserId: string) =>
sendContactRequest(authTokens.idToken, otherGoogleUserId),
{
onSettled: (data, error) => {
return queryClient.invalidateQueries(
Querytypes.GET_CONVERSATION_DETAILS + "/" + ""
);
},
}
);
}