From f8f18ba8e2b98315394fb6143dc0ba59463dd942 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa <5201282+rlinoz@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:09:30 -0300 Subject: [PATCH] Merge pull request #54423 from nkdengineer/fix/54419 fix: onboarding modal is not shown when redirecting from OD (cherry picked from commit f0e8d60d3fe3afe7db7807221f4df8e2935d0f84) (CP triggered by grgia) --- src/hooks/useOnboardingFlow.ts | 63 +++++++++++++++++---------------- src/pages/home/ReportScreen.tsx | 6 ---- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/hooks/useOnboardingFlow.ts b/src/hooks/useOnboardingFlow.ts index 81796dae851d..d322a4d52703 100644 --- a/src/hooks/useOnboardingFlow.ts +++ b/src/hooks/useOnboardingFlow.ts @@ -1,5 +1,5 @@ import {useEffect} from 'react'; -import {NativeModules} from 'react-native'; +import {InteractionManager, NativeModules} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Navigation from '@libs/Navigation/Navigation'; import {hasCompletedGuidedSetupFlowSelector, tryNewDotOnyxSelector} from '@libs/onboardingSelectors'; @@ -32,44 +32,47 @@ function useOnboardingFlowRouter() { const [isSingleNewDotEntry, isSingleNewDotEntryMetadata] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY); const [allBetas, allBetasMetadata] = useOnyx(ONYXKEYS.BETAS); useEffect(() => { - if (isLoadingOnyxValue(isOnboardingCompletedMetadata, tryNewDotdMetadata, dismissedProductTrainingMetadata, allBetasMetadata)) { - return; - } - - if (NativeModules.HybridAppModule && isLoadingOnyxValue(isSingleNewDotEntryMetadata)) { - return; - } + // This should delay opening the onboarding modal so it does not interfere with the ongoing ReportScreen params changes + InteractionManager.runAfterInteractions(() => { + if (isLoadingOnyxValue(isOnboardingCompletedMetadata, tryNewDotdMetadata, dismissedProductTrainingMetadata, allBetasMetadata)) { + return; + } - if (hasBeenAddedToNudgeMigration && !dismissedProductTraining?.migratedUserWelcomeModal && Permissions.shouldShowProductTrainingElements(allBetas)) { - const defaultCannedQuery = SearchQueryUtils.buildCannedSearchQuery(); - const query = defaultCannedQuery; - Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query})); - Navigation.navigate(ROUTES.MIGRATED_USER_WELCOME_MODAL); - return; - } + if (NativeModules.HybridAppModule && isLoadingOnyxValue(isSingleNewDotEntryMetadata)) { + return; + } - if (NativeModules.HybridAppModule) { - // For single entries, such as using the Travel feature from OldDot, we don't want to show onboarding - if (isSingleNewDotEntry) { + if (hasBeenAddedToNudgeMigration && !dismissedProductTraining?.migratedUserWelcomeModal && Permissions.shouldShowProductTrainingElements(allBetas)) { + const defaultCannedQuery = SearchQueryUtils.buildCannedSearchQuery(); + const query = defaultCannedQuery; + Navigation.navigate(ROUTES.SEARCH_CENTRAL_PANE.getRoute({query})); + Navigation.navigate(ROUTES.MIGRATED_USER_WELCOME_MODAL); return; } - // When user is transitioning from OldDot to NewDot, we usually show the explanation modal - if (isHybridAppOnboardingCompleted === false) { - Navigation.navigate(ROUTES.EXPLANATION_MODAL_ROOT); + if (NativeModules.HybridAppModule) { + // For single entries, such as using the Travel feature from OldDot, we don't want to show onboarding + if (isSingleNewDotEntry) { + return; + } + + // When user is transitioning from OldDot to NewDot, we usually show the explanation modal + if (isHybridAppOnboardingCompleted === false) { + Navigation.navigate(ROUTES.EXPLANATION_MODAL_ROOT); + } + + // But if the hybrid app onboarding is completed, but NewDot onboarding is not completed, we start NewDot onboarding flow + // This is a special case when user created an account from NewDot without finishing the onboarding flow and then logged in from OldDot + if (isHybridAppOnboardingCompleted === true && isOnboardingCompleted === false) { + OnboardingFlow.startOnboardingFlow(isPrivateDomain); + } } - // But if the hybrid app onboarding is completed, but NewDot onboarding is not completed, we start NewDot onboarding flow - // This is a special case when user created an account from NewDot without finishing the onboarding flow and then logged in from OldDot - if (isHybridAppOnboardingCompleted === true && isOnboardingCompleted === false) { + // If the user is not transitioning from OldDot to NewDot, we should start NewDot onboarding flow if it's not completed yet + if (!NativeModules.HybridAppModule && isOnboardingCompleted === false) { OnboardingFlow.startOnboardingFlow(isPrivateDomain); } - } - - // If the user is not transitioning from OldDot to NewDot, we should start NewDot onboarding flow if it's not completed yet - if (!NativeModules.HybridAppModule && isOnboardingCompleted === false) { - OnboardingFlow.startOnboardingFlow(isPrivateDomain); - } + }); }, [ isOnboardingCompleted, isHybridAppOnboardingCompleted, diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 008c868a686c..97582f75b7b1 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -112,7 +112,6 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro const {isOffline} = useNetwork(); const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout(); const {activeWorkspaceID} = useActiveWorkspace(); - const lastAccessedReportIDRef = useRef(false); const [modal] = useOnyx(ONYXKEYS.MODAL); const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false}); @@ -152,10 +151,6 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro return; } - if (lastAccessedReportIDRef.current) { - return; - } - const lastAccessedReportID = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, !!route.params.openOnAdminRoom, activeWorkspaceID)?.reportID; // It's possible that reports aren't fully loaded yet @@ -165,7 +160,6 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro } Log.info(`[ReportScreen] no reportID found in params, setting it to lastAccessedReportID: ${lastAccessedReportID}`); - lastAccessedReportIDRef.current = true; navigation.setParams({reportID: lastAccessedReportID}); }, [activeWorkspaceID, canUseDefaultRooms, navigation, route, finishedLoadingApp]);