diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 6f871bea7ab8..0a8437a5afaf 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -8,7 +8,9 @@ import type {PersonalDetailsList, Policy, PolicyCategories, PolicyMembers, Polic import type {PolicyFeatureName, Rate} from '@src/types/onyx/Policy'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import Navigation from './Navigation/Navigation'; +import getPolicyIDFromState from './Navigation/getPolicyIDFromState'; +import Navigation, {navigationRef} from './Navigation/Navigation'; +import type {RootStackParamList, State} from './Navigation/types'; type MemberEmailsToAccountIDs = Record; @@ -304,6 +306,13 @@ function isPolicyFeatureEnabled(policy: OnyxEntry | EmptyObject, feature return Boolean(policy?.[featureName]); } +/** + * Get the currently selected policy ID stored in the navigation state. + */ +function getPolicyIDFromNavigationState() { + return getPolicyIDFromState(navigationRef.getRootState() as State); +} + export { getActivePolicies, hasAccountingConnections, @@ -340,6 +349,7 @@ export { hasTaxRateError, getTaxByID, hasPolicyCategoriesError, + getPolicyIDFromNavigationState, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js index 2c2d28a0edbc..d34f821b4b9b 100644 --- a/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js @@ -1,11 +1,11 @@ import React, {useEffect} from 'react'; import {View} from 'react-native'; import ScreenWrapper from '@components/ScreenWrapper'; -import useActiveWorkspace from '@hooks/useActiveWorkspace'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Browser from '@libs/Browser'; import TopBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar'; import Performance from '@libs/Performance'; +import {getPolicyIDFromNavigationState} from '@libs/PolicyUtils'; import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData'; import Timing from '@userActions/Timing'; import CONST from '@src/CONST'; @@ -21,7 +21,7 @@ const startTimer = () => { function BaseSidebarScreen(props) { const styles = useThemeStyles(); - const {activeWorkspaceID} = useActiveWorkspace(); + const activeWorkspaceID = getPolicyIDFromNavigationState(); useEffect(() => { Performance.markStart(CONST.TIMING.SIDEBAR_LOADED); Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);