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
31 changes: 2 additions & 29 deletions src/libs/Navigation/guards/OnboardingGuard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {NavigationAction, NavigationState} from '@react-navigation/native';
import {findFocusedRoute} from '@react-navigation/native';
import {isSingleNewDotEntrySelector} from '@selectors/HybridApp';
import {hasCompletedGuidedSetupFlowSelector, tryNewDotOnyxSelector, wasInvitedToNewDotSelector} from '@selectors/Onboarding';
import {hasCompletedGuidedSetupFlowSelector, tryNewDotOnyxSelector} from '@selectors/Onboarding';
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -32,8 +32,6 @@ let hybridApp: {isSingleNewDotEntry?: boolean} | undefined;
let onboardingPurposeSelected: OnyxEntry<OnboardingPurpose>;
let onboardingCompanySize: OnyxEntry<OnboardingCompanySize>;
let onboardingInitialPath: OnyxEntry<string>;
let hasNonPersonalPolicy: OnyxEntry<boolean>;
let wasInvitedToNewDot: boolean | undefined;

Onyx.connectWithoutView({
key: ONYXKEYS.NVP_ONBOARDING,
Expand Down Expand Up @@ -84,20 +82,6 @@ Onyx.connectWithoutView({
},
});

Onyx.connectWithoutView({
key: ONYXKEYS.HAS_NON_PERSONAL_POLICY,
callback: (value) => {
hasNonPersonalPolicy = value;
},
});

Onyx.connectWithoutView({
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (value) => {
wasInvitedToNewDot = value ? wasInvitedToNewDotSelector(value) : undefined;
},
});

/**
* Helper to get the correct onboarding route based on current progress
*/
Expand Down Expand Up @@ -169,8 +153,6 @@ const OnboardingGuard: NavigationGuard = {
const isMigratedUser = tryNewDot?.hasBeenAddedToNudgeMigration ?? false;
const isSingleEntry = hybridApp?.isSingleNewDotEntry ?? false;
const needsExplanationModal = (CONFIG.IS_HYBRID_APP && tryNewDot?.isHybridAppOnboardingCompleted !== true) ?? false;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const isInvitedOrGroupMember = (!CONFIG.IS_HYBRID_APP && (hasNonPersonalPolicy || wasInvitedToNewDot)) ?? false;

// Redirect completed users who try to navigate to onboarding routes (e.g. via deep link)
// The OnboardingModalNavigator is not mounted when onboarding is complete, so the route would silently fail
Expand All @@ -184,15 +166,7 @@ const OnboardingGuard: NavigationGuard = {
const isNavigatingWithReplace = isNavigatingToOnboardingFlowWithReplaceAction(action);

const shouldSkipOnboarding =
skipOnboardingConfig ||
isLoading ||
isTransitioning ||
isOnboardingCompleted ||
isMigratedUser ||
isSingleEntry ||
needsExplanationModal ||
isInvitedOrGroupMember ||
isNavigatingWithReplace;
skipOnboardingConfig || isLoading || isTransitioning || isOnboardingCompleted || isMigratedUser || isSingleEntry || needsExplanationModal || isNavigatingWithReplace;

if (shouldSkipOnboarding) {
return {type: 'ALLOW'};
Expand All @@ -210,7 +184,6 @@ const OnboardingGuard: NavigationGuard = {
isMigratedUser,
isSingleEntry,
needsExplanationModal,
isInvitedOrGroupMember,
isNavigatingWithReplace,
});

Expand Down
26 changes: 0 additions & 26 deletions tests/unit/Navigation/guards/OnboardingGuard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,32 +162,6 @@ describe('OnboardingGuard', () => {
// Then navigation should be allowed because single-entry HybridApp users should not be forced into onboarding for a temporary visit
expect(result.type).toBe('ALLOW');
});

it('should allow users with non-personal policies', async () => {
// Given a user who belongs to a non-personal (e.g. corporate) policy, indicating they were added to a workspace
await Onyx.merge(ONYXKEYS.HAS_NON_PERSONAL_POLICY, true);
await waitForBatchedUpdates();

// When the guard evaluates a navigation action
const result = OnboardingGuard.evaluate(mockState, mockAction, authenticatedContext);

// Then navigation should be allowed because users with workspace policies should skip the individual onboarding flow
expect(result.type).toBe('ALLOW');
});

it('should allow invited users', async () => {
// Given a user who was invited and has already selected their intro choice (SUBMIT), indicating they came through an invitation link
await Onyx.merge(ONYXKEYS.NVP_INTRO_SELECTED, {
choice: CONST.INTRO_CHOICES.SUBMIT,
});
await waitForBatchedUpdates();

// When the guard evaluates a navigation action
const result = OnboardingGuard.evaluate(mockState, mockAction, authenticatedContext);

// Then navigation should be allowed because invited users have a predefined purpose and should skip the onboarding purpose selection
expect(result.type).toBe('ALLOW');
});
});

describe('redirect completed users away from onboarding routes', () => {
Expand Down
Loading