From 65b6c89630e60bc59c2b65fe03fa98378a0c971a Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 4 Nov 2024 13:58:03 +0100 Subject: [PATCH] Adjust getAdaptedState to handle OnboardingModalNavigator --- .../linkingConfig/getAdaptedStateFromPath.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index d3116eb15e8d..c86635fb18bd 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -145,9 +145,26 @@ function getDefaultFullScreenRoute(route?: NavigationPartialRoute, policyID?: st return fallbackRoute; } +function getOnboardingAdaptedState(state: PartialState): PartialState { + const onboardingRoute = state.routes.at(0); + if (!onboardingRoute || onboardingRoute.name === SCREENS.ONBOARDING.PURPOSE) { + return state; + } + + const routes = []; + routes.push({name: SCREENS.ONBOARDING.PURPOSE}); + if (onboardingRoute.name === SCREENS.ONBOARDING.ACCOUNTING) { + routes.push({name: SCREENS.ONBOARDING.EMPLOYEES}); + } + routes.push(onboardingRoute); + + return getRoutesWithIndex(routes); +} + function getAdaptedState(state: PartialState>, policyID?: string): GetAdaptedStateReturnType { const fullScreenRoute = state.routes.find((route) => isFullScreenName(route.name)); const reportsSplitNavigator = state.routes.find((route) => route.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); + const onboardingNavigator = state.routes.find((route) => route.name === NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR); // If policyID is defined, it should be passed to the reportNavigator params. if (reportsSplitNavigator && policyID) { @@ -177,6 +194,17 @@ function getAdaptedState(state: PartialState const defaultFullScreenRoute = getDefaultFullScreenRoute(focusedRoute, policyID); + if (onboardingNavigator?.state) { + const adaptedOnboardingNavigator = { + ...onboardingNavigator, + state: getOnboardingAdaptedState(onboardingNavigator.state), + }; + + return { + adaptedState: getRoutesWithIndex([defaultFullScreenRoute, adaptedOnboardingNavigator]), + }; + } + // If not, add the default full screen route. return { adaptedState: getRoutesWithIndex([defaultFullScreenRoute, ...state.routes]),