diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index f816085f5325..31b6f139041d 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -415,10 +415,6 @@ function waitForProtectedRoutes() { }); } -function switchPolicyID(policyID?: string) { - navigationRef.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID, payload: {policyID}}); -} - type NavigateToReportWithPolicyCheckPayload = {report?: OnyxEntry; reportID?: string; reportActionID?: string; referrer?: string; policyIDToCheck?: string}; function navigateToReportWithPolicyCheck({report, reportID, reportActionID, referrer, policyIDToCheck}: NavigateToReportWithPolicyCheckPayload, ref = navigationRef) { @@ -499,7 +495,6 @@ export default { getTopmostReportActionId, waitForProtectedRoutes, parseHybridAppUrl, - switchPolicyID, resetToHome, closeRHPFlow, setNavigationActionToMicrotaskQueue, diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index cae6024d4f7b..97d459522e97 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -14,7 +14,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; +import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import {sortWorkspacesBySelected} from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -92,7 +92,7 @@ function WorkspaceSwitcherPage() { Navigation.goBack(); if (policyID !== activeWorkspaceID) { - Navigation.switchPolicyID(policyID); + navigationRef.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID, payload: {policyID}}); } }, [activeWorkspaceID], diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx index 23633f2bb0ec..15b7b35ce889 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx @@ -42,8 +42,11 @@ function BaseSidebarScreen() { Timing.start(CONST.TIMING.SIDEBAR_LOADED); }, []); + // If the selected workspace has been deleted, the current workspace is reset to global. useEffect(() => { - if (!!activeWorkspace || activeWorkspaceID === undefined) { + const isActiveWorkspaceDeleted = !!activeWorkspace || activeWorkspaceID === undefined; + + if (isActiveWorkspaceDeleted) { return; } @@ -58,7 +61,7 @@ function BaseSidebarScreen() { navigationRef.current?.dispatch({ target: navigationRef.current.getRootState().key, payload: createSplitNavigator({name: SCREENS.HOME}, {name: SCREENS.REPORT}), - type: 'REPLACE', + type: CONST.NAVIGATION.ACTION_TYPE.REPLACE, }); } }, [activeWorkspace, activeWorkspaceID, currentRoute]);