diff --git a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx index bb4bdff27097..673b77d9c9a1 100644 --- a/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx +++ b/src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx @@ -9,7 +9,7 @@ import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; -import {isControlPolicy} from '@libs/PolicyUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; import CONST from '@src/CONST'; import * as Policy from '@src/libs/actions/Policy/Policy'; @@ -29,10 +29,11 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { const [policy] = useOnyx(`policy_${policyID}`); const {isOffline} = useNetwork(); - const isUpgraded = React.useMemo(() => isControlPolicy(policy), [policy]); + const canPerformUpgrade = !!feature && !!policy && PolicyUtils.isPolicyAdmin(policy); + const isUpgraded = React.useMemo(() => PolicyUtils.isControlPolicy(policy), [policy]); const upgradeToCorporate = () => { - if (!policy || !feature) { + if (!canPerformUpgrade) { return; } @@ -57,16 +58,16 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { useEffect(() => { const unsubscribeListener = navigation.addListener('blur', () => { - if (!isUpgraded) { + if (!isUpgraded || !canPerformUpgrade) { return; } confirmUpgrade(); }); return unsubscribeListener; - }, [isUpgraded, confirmUpgrade, navigation]); + }, [isUpgraded, canPerformUpgrade, confirmUpgrade, navigation]); - if (!feature || !policy) { + if (!canPerformUpgrade) { return ; }