diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index d39d52c5a9ca..589845e3afd7 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -1,4 +1,5 @@ import {useIsFocused, useRoute} from '@react-navigation/native'; +import {Str} from 'expensify-common'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {FlatList, InteractionManager, View} from 'react-native'; import type {ValueOf} from 'type-fest'; @@ -117,6 +118,8 @@ function WorkspacesListPage() { const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true}); const [duplicateWorkspace] = useOnyx(ONYXKEYS.DUPLICATE_WORKSPACE, {canBeMissing: false}); const isDuplicatedWorkspaceEnabled = isBetaEnabled(CONST.BETAS.DUPLICATE_WORKSPACE); + const [myDomainSecurityGroups] = useOnyx(ONYXKEYS.MY_DOMAIN_SECURITY_GROUPS, {canBeMissing: true}); + const [securityGroups] = useOnyx(ONYXKEYS.COLLECTION.SECURITY_GROUP, {canBeMissing: true}); // This hook preloads the screens of adjacent tabs to make changing tabs faster. usePreloadFullScreenNavigators(); @@ -192,6 +195,24 @@ function WorkspacesListPage() { [session?.accountID], ); + const canUserSetWorkspaceAsDefault = useCallback(() => { + const userEmail = session?.email; + if (!userEmail) { + return true; + } + + const domainName = Str.extractEmailDomain(userEmail); + const primaryDomainSecurityGroupID = myDomainSecurityGroups?.[domainName]; + + if (!primaryDomainSecurityGroupID) { + return true; + } + + const securityGroup = securityGroups?.[`${ONYXKEYS.COLLECTION.SECURITY_GROUP}${primaryDomainSecurityGroupID}`]; + + return !securityGroup?.enableRestrictedPrimaryPolicy; + }, [session?.email, myDomainSecurityGroups, securityGroups]); + /** * Gets the menu item for each workspace */ @@ -227,7 +248,7 @@ function WorkspacesListPage() { }); } - if (!isDefault && !item?.isJoinRequestPending) { + if (!isDefault && !item?.isJoinRequestPending && canUserSetWorkspaceAsDefault()) { threeDotsMenuItems.push({ icon: Expensicons.Star, text: translate('workspace.common.setAsDefault'), @@ -323,20 +344,20 @@ function WorkspacesListPage() { session?.email, session?.accountID, activePolicyID, + duplicateWorkspace?.policyID, translate, policies, + isDuplicatedWorkspaceEnabled, + canUserSetWorkspaceAsDefault, fundList, styles.ph5, styles.mb2, styles.mh5, - styles.ph5, - duplicateWorkspace?.policyID, styles.hoveredComponentBG, styles.offlineFeedback.deleted, loadingSpinnerIconIndex, shouldCalculateBillNewDot, isSupportalAction, - isDuplicatedWorkspaceEnabled, setIsDeletingPaidWorkspace, startChangeOwnershipFlow, isLessThanMediumScreen,