Skip to content

Commit

Permalink
Merge pull request #38490 from software-mansion-labs/fix/delayed-work…
Browse files Browse the repository at this point in the history
…spaces-transition

Add getPolicyIDFromNavigationState method
  • Loading branch information
techievivek authored Apr 1, 2024
2 parents b282693 + eb11d74 commit 272b05f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>;

Expand Down Expand Up @@ -304,6 +306,13 @@ function isPolicyFeatureEnabled(policy: OnyxEntry<Policy> | 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<RootStackParamList>);
}

export {
getActivePolicies,
hasAccountingConnections,
Expand Down Expand Up @@ -340,6 +349,7 @@ export {
hasTaxRateError,
getTaxByID,
hasPolicyCategoriesError,
getPolicyIDFromNavigationState,
};

export type {MemberEmailsToAccountIDs};
4 changes: 2 additions & 2 deletions src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down

0 comments on commit 272b05f

Please sign in to comment.