Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -250,6 +252,11 @@ function AccessOrNotFoundWrapper({
if (shouldShowFullScreenLoadingIndicator) {
return <FullscreenLoadingIndicator />;
}
// 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 <FullscreenLoadingIndicator />;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ UI-1 (docs)

This newly added FullscreenLoadingIndicator is returned from a conditional branch with no navigation component (no HeaderWithBackButton or close button) in the same return. If the redirect ever hangs, the user has no escape route because there is no visible navigation. Per UI-1, a full-screen loader rendered without accompanying navigation should set shouldUseGoBackButton so an emergency "Go Back" button appears after a timeout.

if (shouldRedirectToMoreFeatures) {
    return <FullscreenLoadingIndicator shouldUseGoBackButton />;
}

Reviewed at: 1bb089b | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

}
if (shouldShowNotFoundPage) {
return (
<PageNotFoundFallback
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/AssignCardFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
employeeList: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -347,6 +350,7 @@ describe('AssignCardFeed', () => {
await TestHelper.signInWithTestUser();
const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -380,6 +384,7 @@ describe('AssignCardFeed', () => {
await TestHelper.signInWithTestUser();
const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -417,6 +422,7 @@ describe('AssignCardFeed', () => {
await TestHelper.signInWithTestUser();
const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -445,6 +451,7 @@ describe('AssignCardFeed', () => {
await TestHelper.signInWithTestUser();
const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -478,6 +485,7 @@ describe('AssignCardFeed', () => {
await TestHelper.signInWithTestUser();
const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -514,6 +522,7 @@ describe('AssignCardFeed', () => {
await TestHelper.signInWithTestUser();
const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -634,6 +645,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -670,6 +682,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -719,6 +732,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -766,6 +780,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -829,6 +844,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -909,6 +925,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -946,6 +963,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down Expand Up @@ -996,6 +1014,7 @@ describe('AssignCardFeed', () => {

const policy = {
...LHNTestUtils.getFakePolicy(),
areCompanyCardsEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
policyAccountID: WORKSPACE_ACCOUNT_ID,
};
Expand Down
Loading