Skip to content

Commit

Permalink
Merge pull request Expensify#48256 from mkzie2/mkzie2-issue-47904
Browse files Browse the repository at this point in the history
fix: normal user can access workspace upgrade page
  • Loading branch information
tgolen authored Aug 30, 2024
2 parents 960ae87 + 47456fb commit fa8fa1a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/pages/workspace/upgrade/WorkspaceUpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}

Expand All @@ -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 <NotFoundPage />;
}

Expand Down

0 comments on commit fa8fa1a

Please sign in to comment.