From 65b8beb701f8c14376d056584666cfe39c3f6aff Mon Sep 17 00:00:00 2001 From: Frank Nguyen <41023671+FrankreedX@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:06:27 +0700 Subject: [PATCH] IWB-4: User is navigated off of chooseTeam once they're accepted through waitlist (#312) * added blacklist hook * black list feature works * some unused stuff removal * waitlist seems to work * simplified removeBlacklist.js * pretty * removed transaction and hope that it works * fixed useBlackList.js hook firestore error, and made blacklist check functional * added refresh spinner for chooseTeam.js * updated invalidateKeys and fixed some styling * updated faulty invalidateKeys lists * kinda works lmao * updated the invalidateKeys again * navigation off chooseTeam works. Tech debt +1 * added waitlistError to ErrorComponent * minor comment change Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * changed console log wording in removeBlacklist Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * removed copied over comment * updated tiny comment Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * removed redundant log Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * fix - added email to blacklist record * fix - added assertion if pfp exists when removing a user * prevent double navigation to chooseTeam screen * fixed "invalid-argument" * added key * removed redundant remove user fix * pretty * pretty * pretty * added missing state from merge * simple fix --------- Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> Co-authored-by: Jake Gehrke --- app/segments/(team)/chooseTeam.js | 4 ++++ dbOperations/hooks/useUserInfo.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/segments/(team)/chooseTeam.js b/app/segments/(team)/chooseTeam.js index 1d11662a..72d6a842 100644 --- a/app/segments/(team)/chooseTeam.js +++ b/app/segments/(team)/chooseTeam.js @@ -18,6 +18,7 @@ import { useAuthContext } from "~/context/Auth"; import { addToTeam } from "~/dbOperations/addToTeam"; import { addToWaitlist } from "~/dbOperations/addToWaitlist"; import { useBlackList } from "~/dbOperations/hooks/useBlackList"; +import { useUserInfo } from "~/dbOperations/hooks/useUserInfo"; import { useWaitlist } from "~/dbOperations/hooks/useWaitlist"; import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys"; import { auth } from "~/firebaseConfig"; @@ -46,6 +47,9 @@ function ChooseTeam() { isLoading: waitlistIsLoading, } = useWaitlist(); + //basically to trigger the side effect that navigates off this page + useUserInfo({ userId: currentUserId }); + const state = useMemo(() => { if (blacklist && blacklist[currentUserId]) { return "blacklist"; diff --git a/dbOperations/hooks/useUserInfo.js b/dbOperations/hooks/useUserInfo.js index 6e626e82..bacd5898 100644 --- a/dbOperations/hooks/useUserInfo.js +++ b/dbOperations/hooks/useUserInfo.js @@ -1,5 +1,5 @@ import { useQuery } from "@tanstack/react-query"; -import { router } from "expo-router"; +import { router, useSegments } from "expo-router"; import { collection, doc, @@ -18,6 +18,7 @@ export const useUserInfo = ({ role = null, enabled = true, } = {}) => { + const segments = useSegments(); const { currentTeamId, currentUserId, currentUserVerified } = useAuthContext(); const week_milliseconds = 604800000; @@ -44,8 +45,10 @@ export const useUserInfo = ({ console.log("e", getErrorString(e)); } + const inChooseTeam = segments.at(-1) === "chooseTeam"; + if (!data || !currentUserVerified) { - if (currentUserId === userId) { + if (currentUserId === userId && !inChooseTeam) { router.replace("segments/(team)/chooseTeam"); } return { @@ -57,6 +60,10 @@ export const useUserInfo = ({ uniqueDrills: [], }; } + if (inChooseTeam) { + router.replace("content/assignments"); + } + const filteredAssignedData = data.assigned_data.filter((assignment) => { const timeDifference = currentDateTime - assignment.assignedTime; return timeDifference <= week_milliseconds;