diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index 6bf1dd54c980..6977857cf2ea 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -227,8 +227,10 @@ function AccessOrNotFoundWrapper({ // We only update the feature state if it isn't pending. // This is because the feature state changes several times during the creation of a workspace, while we are waiting for a response from the backend. // Without this, we can be unexpectedly navigated to the More Features page. + const shouldRedirectToMoreFeatures = isFocused && !isEmptyObject(policy) && !isFeatureEnabled && !(pendingField && !isOffline) && !shouldShowNotFoundPage; + useEffect(() => { - if (!isFocused || isEmptyObject(policy) || isFeatureEnabled || (pendingField && !isOffline && !isFeatureEnabled) || shouldShowNotFoundPage) { + if (!shouldRedirectToMoreFeatures) { return; } @@ -238,7 +240,7 @@ function AccessOrNotFoundWrapper({ }); // We don't need to run the effect on policyID change as we only use it to get the route to navigate to. // eslint-disable-next-line react-hooks/exhaustive-deps - }, [pendingField, isOffline, isFeatureEnabled, shouldShowNotFoundPage, isFocused]); + }, [shouldRedirectToMoreFeatures]); useEffect(() => { if (isLoadingReportData || !isPolicyNotAccessible) { @@ -250,6 +252,11 @@ function AccessOrNotFoundWrapper({ if (shouldShowFullScreenLoadingIndicator) { return ; } + // The feature linked to this page is disabled, so the redirect effect above will navigate to the More Features page. + // Render a loader instead of the page's children so the disabled page is never shown for a frame (avoids a visible flash). + if (shouldRedirectToMoreFeatures) { + return ; + } if (shouldShowNotFoundPage) { return ( { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, employeeList: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -265,6 +266,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, employeeList: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -303,6 +305,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, employeeList: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -347,6 +350,7 @@ describe('AssignCardFeed', () => { await TestHelper.signInWithTestUser(); const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -380,6 +384,7 @@ describe('AssignCardFeed', () => { await TestHelper.signInWithTestUser(); const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -417,6 +422,7 @@ describe('AssignCardFeed', () => { await TestHelper.signInWithTestUser(); const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -445,6 +451,7 @@ describe('AssignCardFeed', () => { await TestHelper.signInWithTestUser(); const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -478,6 +485,7 @@ describe('AssignCardFeed', () => { await TestHelper.signInWithTestUser(); const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -514,6 +522,7 @@ describe('AssignCardFeed', () => { await TestHelper.signInWithTestUser(); const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -551,6 +560,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, employeeList: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -591,6 +601,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, employeeList: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -634,6 +645,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -670,6 +682,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -719,6 +732,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -766,6 +780,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -829,6 +844,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -909,6 +925,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -946,6 +963,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, }; @@ -996,6 +1014,7 @@ describe('AssignCardFeed', () => { const policy = { ...LHNTestUtils.getFakePolicy(), + areCompanyCardsEnabled: true, role: CONST.POLICY.ROLE.ADMIN, policyAccountID: WORKSPACE_ACCOUNT_ID, };