diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 3f8fdd069fd3..e7003d1e6e20 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -23,6 +23,7 @@ import usePrevious from '@hooks/usePrevious'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import * as CurrencyUtils from '@libs/CurrencyUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; import type {SettingsNavigatorParamList} from '@navigation/types'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; @@ -50,18 +51,20 @@ type WorkspaceMemberDetailsPageProps = Omit; function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceMemberDetailsPageProps) { + const policyID = route.params.policyID; + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID); + const styles = useThemeStyles(); const {isOffline} = useNetwork(); const {translate} = useLocalize(); const StyleUtils = useStyleUtils(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); - const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${policy?.workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); + const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = useState(false); const [isRoleSelectionModalVisible, setIsRoleSelectionModalVisible] = useState(false); const accountID = Number(route.params.accountID); - const policyID = route.params.policyID; const memberLogin = personalDetails?.[accountID]?.login ?? ''; const member = policy?.employeeList?.[memberLogin]; const prevMember = usePrevious(member); diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index b8a2580d0c56..c706e18c688d 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -8,6 +8,7 @@ import * as Policy from '@userActions/Policy/Policy'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; type NavigatorsParamList = BottomTabNavigatorParamList & AuthScreensParamList & SettingsNavigatorParamList & ReimbursementAccountNavigatorParamList & FullScreenNavigatorParamList; @@ -56,6 +57,7 @@ function getPolicyIDFromRoute(route: PolicyRoute): string { type WithPolicyOnyxProps = { policy: OnyxEntry; policyDraft: OnyxEntry; + isLoadingPolicy: boolean; }; type WithPolicyProps = WithPolicyOnyxProps & { @@ -65,6 +67,7 @@ type WithPolicyProps = WithPolicyOnyxProps & { const policyDefaultProps: WithPolicyOnyxProps = { policy: {} as OnyxTypes.Policy, policyDraft: {} as OnyxTypes.Policy, + isLoadingPolicy: false, }; /* @@ -76,8 +79,9 @@ export default function ( function WithPolicy(props: Omit, ref: ForwardedRef) { const policyID = getPolicyIDFromRoute(props.route as PolicyRoute); - const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); - const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`); + const [policy, policyResults] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + const [policyDraft, policyDraftResults] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`); + const isLoadingPolicy = isLoadingOnyxValue(policyResults, policyDraftResults); if (policyID.length > 0) { Policy.updateLastAccessedWorkspace(policyID); @@ -89,6 +93,7 @@ export default function ( {...(props as TProps)} policy={policy} policyDraft={policyDraft} + isLoadingPolicy={isLoadingPolicy} ref={ref} /> ); diff --git a/src/pages/workspace/withPolicyAndFullscreenLoading.tsx b/src/pages/workspace/withPolicyAndFullscreenLoading.tsx index 686e7bd54655..fd3efc3d84ef 100644 --- a/src/pages/workspace/withPolicyAndFullscreenLoading.tsx +++ b/src/pages/workspace/withPolicyAndFullscreenLoading.tsx @@ -27,13 +27,18 @@ export default function withPolicyAndFullscreenLoading>, ): ComponentWithPolicyAndFullscreenLoading { function WithPolicyAndFullscreenLoading( - {policy = policyDefaultProps.policy, policyDraft = policyDefaultProps.policyDraft, ...rest}: Omit, + { + policy = policyDefaultProps.policy, + policyDraft = policyDefaultProps.policyDraft, + isLoadingPolicy = policyDefaultProps.isLoadingPolicy, + ...rest + }: Omit, ref: ForwardedRef, ) { const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true}); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); - if (isLoadingReportData && isEmpty(policy) && isEmpty(policyDraft)) { + if ((isLoadingPolicy || isLoadingReportData) && isEmpty(policy) && isEmpty(policyDraft)) { return ; }