Skip to content
Merged
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
21 changes: 5 additions & 16 deletions src/components/SidePanel/RHPVariantTest/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import SidePanelActions from '@libs/actions/SidePanel';
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
import Navigation from '@libs/Navigation/Navigation';

Expand Down Expand Up @@ -32,7 +31,7 @@ Onyx.connectWithoutView({
});

/**
* Determines if the user should be navigated to the RHP variant side panel after onboarding.
* Determines if the user should get one of the RHP variant landings after onboarding.
* The existing micro-company RHP variants (rhpConciergeDm, rhpAdminsRoom) are only shown to micro companies.
* The trackExpensesWithConcierge variant is controlled entirely by the backend and applies regardless of company size.
*
Expand Down Expand Up @@ -60,22 +59,13 @@ const shouldOpenRHPVariant: ShouldOpenRHPVariant = (variantOverride) => {
};

/**
* Handles navigation for RHP experiment variants (B/C/D):
* Variants B and C navigate to the workspace overview, Variant D navigates to home.
* All variants open the side panel without overlay.
* The control variant is handled separately in navigateAfterOnboarding.
* Handles navigation for the retired RHP experiment variants that some accounts still have assigned.
* rhpConciergeDm and rhpAdminsRoom navigate to the workspace overview, and rhpHomePage navigates to Home.
* None of them opens the side panel, because onboarding should only happen in one place.
* Track users and the control variant are handled separately in navigateAfterOnboarding.
*/
const handleRHPVariantNavigation: HandleRHPVariantNavigation = (onboardingPolicyID, variantOverride, navigationOptions) => {
const variant = variantOverride ?? onboardingRHPVariant;
if (variant === CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE) {
const shouldPreserveRevealedReport = isReportTopmostSplitNavigator();
if (!shouldPreserveRevealedReport) {
Navigation.navigate(ROUTES.HOME, navigationOptions);
}
SidePanelActions.openSidePanel(true);
return;
}

const isRHPHomePage = variant === CONST.ONBOARDING_RHP_VARIANT.RHP_HOME_PAGE;

if (isRHPHomePage) {
Expand All @@ -86,7 +76,6 @@ const handleRHPVariantNavigation: HandleRHPVariantNavigation = (onboardingPolicy
} else {
Navigation.navigate(ROUTES.WORKSPACE_OVERVIEW.getRoute(onboardingPolicyID), navigationOptions);
}
SidePanelActions.openSidePanel(true);
};

export {shouldOpenRHPVariant, handleRHPVariantNavigation};
3 changes: 1 addition & 2 deletions src/hooks/useAutoCreateSubmitWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function useAutoCreateSubmitWorkspace() {
hasOwnedPaidPolicy,
onboardingMessages,
lastWorkspaceNumber,
shouldUseNarrowLayout,
} = useOnboardingWorkspaceCreationState();
const delegateAccountID = useDelegateAccountID();

Expand Down Expand Up @@ -122,7 +121,7 @@ function useAutoCreateSubmitWorkspace() {
policyIDForNavigation = existingSubmitPolicyID;
}

navigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue(policyIDForNavigation, shouldUseNarrowLayout);
navigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue(policyIDForNavigation);
};

return autoCreateSubmitWorkspace;
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/useAutoCreateTrackWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ function useAutoCreateTrackWorkspace() {

if (isSidePanelReportSupported) {
rhpVariant = extractRHPVariantFromResponse(response);
// Every Track onboarding choice should land in the Concierge RHP, but the backend
// doesn't reliably return trackExpensesWithConcierge for all of them, so fall back to it
// whenever the response omits a variant.
if (!rhpVariant && isTrackOnboardingChoice(onboardingPurposeSelected)) {
rhpVariant = CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE;
}
}
} catch (error) {
Log.warn('[useAutoCreateTrackWorkspace] Error completing onboarding', {error});
} finally {
// Every Track onboarding choice should get the Track landing, but the backend doesn't reliably return
// trackExpensesWithConcierge for all of them, and a failed request returns nothing. Falling back here
// covers both cases.
if (!rhpVariant && isTrackOnboardingChoice(onboardingPurposeSelected)) {
rhpVariant = CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE;
}
setOnboardingAdminsChatReportID();
setOnboardingPolicyID();

Expand Down
28 changes: 9 additions & 19 deletions src/libs/navigateAfterOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';

import {setDisableDismissOnEscape} from './actions/Modal';
import SidePanelActions from './actions/SidePanel';
import {setOnboardingRHPVariant} from './actions/Welcome';
import Log from './Log';
import isReportTopmostSplitNavigator from './Navigation/helpers/isReportTopmostSplitNavigator';
Expand Down Expand Up @@ -130,28 +129,20 @@ function navigateAfterOnboarding(
return;
}

// On mobile (small screen), Track workspace admins with the trackExpensesWithConcierge variant
// should navigate directly to the Concierge DM (which contains onboarding tasks).
// This check is outside shouldOpenRHPVariant because that function returns false on native
// (Side Panel doesn't exist on native), but we still need to navigate to Concierge on mobile.
const navigationOptions = options?.afterTransition ? {afterTransition: options.afterTransition} : undefined;
const variantOverride = options?.variantOverride;
const variant = variantOverride ?? onboardingRHPVariant;

// The homePageNoRHP arm of the onboarding experiment lands on Home without opening the side panel, at every company size,
// so it is handled before the variants that are limited to micro companies or that open the side panel.
if (variant === CONST.ONBOARDING_RHP_VARIANT.HOME_PAGE_NO_RHP) {
// Track users and the homePageNoRHP arm of the onboarding experiment land on Home without the side panel, at every company size
// and screen size, because Home's Getting started section is their onboarding. This runs before shouldOpenRHPVariant, which
// returns false on native even though native Track users also have the Track variant.
if (variant === CONST.ONBOARDING_RHP_VARIANT.HOME_PAGE_NO_RHP || variant === CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE) {
if (!isReportTopmostSplitNavigator()) {
Navigation.navigate(ROUTES.HOME, navigationOptions);
}
return;
}

if (isSmallScreenWidth && variant === CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(conciergeReportID), navigationOptions);
return;
}

if (shouldOpenRHPVariant(variantOverride)) {
handleRHPVariantNavigation(onboardingPolicyID, variantOverride, navigationOptions);
return;
Expand Down Expand Up @@ -204,10 +195,10 @@ function navigateAfterOnboardingWithMicrotaskQueue(
}

/**
* After creating or joining a Submit workspace during onboarding, navigate to Spend > Expenses
* with the side panel open so the #admins room is visible in Concierge Anywhere.
* After creating or joining a Submit workspace, navigate to Spend > Expenses with the side panel closed.
* This covers onboarding, the Submit plan welcome modal and the `intent=submit` deeplink, so new and existing Employer users get the same experience.
*/
function navigateToSubmitWorkspaceAfterOnboarding(policyID?: string, shouldUseNarrowLayout = false) {
function navigateToSubmitWorkspaceAfterOnboarding(policyID?: string) {
setDisableDismissOnEscape(false);

if (consumeDeepLinkToOpenAfterOnboarding()) {
Expand All @@ -221,13 +212,12 @@ function navigateToSubmitWorkspaceAfterOnboarding(policyID?: string, shouldUseNa

setOnboardingRHPVariant(CONST.ONBOARDING_RHP_VARIANT.RHP_ADMINS_ROOM);
Navigation.navigate(ROUTES.SEARCH_ROOT.getRoute({query: buildCannedSearchQuery({type: CONST.SEARCH.DATA_TYPES.EXPENSE}), searchKey: CONST.SEARCH.SEARCH_KEYS.EXPENSES}));
SidePanelActions.openSidePanel(!shouldUseNarrowLayout);
}

function navigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue(policyID?: string, shouldUseNarrowLayout = false) {
function navigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue(policyID?: string) {
dismissOnboardingModalBeforeExit(() => {
Navigation.setNavigationActionToMicrotaskQueue(() => {
navigateToSubmitWorkspaceAfterOnboarding(policyID, shouldUseNarrowLayout);
navigateToSubmitWorkspaceAfterOnboarding(policyID);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
// We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
isSmallScreenWidth,
shouldUseNarrowLayout,
} = useResponsiveLayout();
const [joinablePolicies] = useOnyx(ONYXKEYS.JOINABLE_POLICIES);
const [getAccessiblePoliciesAction] = useOnyx(ONYXKEYS.VALIDATE_USER_AND_GET_ACCESSIBLE_POLICIES);
Expand Down Expand Up @@ -191,7 +190,7 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
});

if (shouldUseSubmitFlow) {
navigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue(policy.policyID, shouldUseNarrowLayout);
navigateToSubmitWorkspaceAfterOnboardingWithMicrotaskQueue(policy.policyID);
return;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/ui/OnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ describe('OnboardingPurpose Page', () => {
);
});

// Then Employer onboarding still lands on Expenses, but doesn't open the side panel as a second onboarding place
expect((await getOnyxValue(ONYXKEYS.NVP_SIDE_PANEL))?.open).toBeFalsy();

onyxSetSpy.mockRestore();
unmount();
await waitForBatchedUpdatesWithAct();
Expand Down
10 changes: 9 additions & 1 deletion tests/ui/WorkspaceOnboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {View} from 'react-native';
import Onyx from 'react-native-onyx';

import createMock from '../utils/createMock';
import getOnyxValue from '../utils/getOnyxValue';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';

Expand Down Expand Up @@ -1192,6 +1193,9 @@ describe('OnboardingWorkspaces Page', () => {
);
});

// Then skipping still lands on Expenses, but onboarding doesn't open the side panel next to it
expect((await getOnyxValue(ONYXKEYS.NVP_SIDE_PANEL))?.open).toBeFalsy();

unmount();
await waitForBatchedUpdatesWithAct();
});
Expand Down Expand Up @@ -1261,7 +1265,7 @@ describe('OnboardingWorkspaces Page', () => {
await waitForBatchedUpdatesWithAct();
});

it('should complete onboarding without passing the joined workspace policyID and open Spend > Expenses in the admins room', async () => {
it('should complete onboarding without passing the joined workspace policyID and open Spend > Expenses with the side panel closed', async () => {
jest.spyOn(Navigation, 'dismissModal').mockImplementation(({afterTransition} = {}) => afterTransition?.());
jest.spyOn(Navigation, 'setNavigationActionToMicrotaskQueue').mockImplementation((callback: () => void) => callback());

Expand Down Expand Up @@ -1319,6 +1323,10 @@ describe('OnboardingWorkspaces Page', () => {
);
});

// Then auto-joining a Submit workspace still lands on Expenses and stores the rhpAdminsRoom variant,
// but onboarding doesn't open the side panel
expect((await getOnyxValue(ONYXKEYS.NVP_SIDE_PANEL))?.open).toBeFalsy();

onyxSetSpy.mockRestore();
unmount();
await waitForBatchedUpdatesWithAct();
Expand Down
39 changes: 22 additions & 17 deletions tests/unit/components/SidePanel/RHPVariantTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,40 @@ describe('handleRHPVariantNavigation', () => {
mockIsReportTopmostSplitNavigator.mockReturnValue(false);
});

it('preserves the topmost report for the rhpHomePage variant', () => {
it('preserves the topmost report for the rhpHomePage variant without opening the side panel', () => {
// Given an account that still has the retired rhpHomePage arm and already shows a report
mockIsReportTopmostSplitNavigator.mockReturnValue(true);

// When onboarding finishes
handleRHPVariantNavigation('policyID', CONST.ONBOARDING_RHP_VARIANT.RHP_HOME_PAGE);

// Then the report stays on screen, and the side panel stays closed because onboarding should only happen on Home
expect(Navigation.navigate).not.toHaveBeenCalled();
expect(SidePanelActions.openSidePanel).toHaveBeenCalledWith(true);
expect(SidePanelActions.openSidePanel).not.toHaveBeenCalled();
});

it('navigates home for the rhpHomePage variant when no report is topmost', () => {
it('navigates home for the rhpHomePage variant when no report is topmost, without opening the side panel', () => {
// Given an account that still has the retired rhpHomePage arm and no report on screen

// When onboarding finishes
handleRHPVariantNavigation('policyID', CONST.ONBOARDING_RHP_VARIANT.RHP_HOME_PAGE);

// Then it keeps landing on Home, but without a second onboarding chat in the side panel
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME, undefined);
expect(SidePanelActions.openSidePanel).toHaveBeenCalledWith(true);
expect(SidePanelActions.openSidePanel).not.toHaveBeenCalled();
});

it('preserves the topmost report for the trackExpensesWithConcierge variant and opens the side panel on top of it', () => {
mockIsReportTopmostSplitNavigator.mockReturnValue(true);

handleRHPVariantNavigation('policyID', CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE);

expect(Navigation.navigate).not.toHaveBeenCalled();
expect(SidePanelActions.openSidePanel).toHaveBeenCalledWith(true);
});
it.each([CONST.ONBOARDING_RHP_VARIANT.RHP_ADMINS_ROOM, CONST.ONBOARDING_RHP_VARIANT.RHP_CONCIERGE_DM])(
'navigates to the workspace overview for the retired %s variant without opening the side panel',
(variant) => {
// Given an account that still has one of the retired arms that used to show the side panel next to the workspace

it('navigates home for the trackExpensesWithConcierge variant when no report is topmost', () => {
handleRHPVariantNavigation('policyID', CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE);
// When onboarding finishes
handleRHPVariantNavigation('policyID', variant);

expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME, undefined);
expect(SidePanelActions.openSidePanel).toHaveBeenCalledWith(true);
});
// Then it keeps landing on the workspace overview, but the side panel stays closed
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.WORKSPACE_OVERVIEW.getRoute('policyID'), undefined);
expect(SidePanelActions.openSidePanel).not.toHaveBeenCalled();
},
);
});
8 changes: 4 additions & 4 deletions tests/unit/hooks/useAutoCreateSubmitWorkspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('useAutoCreateSubmitWorkspace', () => {
// Then the user should be navigated to the newly created Submit workspace
// so they land on their workspace immediately after onboarding
expect(navigateSpy).toHaveBeenCalledTimes(1);
expect(navigateSpy).toHaveBeenCalledWith(MOCK_POLICY_ID, expect.any(Boolean));
expect(navigateSpy).toHaveBeenCalledWith(MOCK_POLICY_ID);
});

it('reuses the existing onboarding workspace instead of creating a new one', async () => {
Expand Down Expand Up @@ -318,7 +318,7 @@ describe('useAutoCreateSubmitWorkspace', () => {
expect(createWorkspaceSpy).not.toHaveBeenCalled();
expect(completeOnboardingSpy).not.toHaveBeenCalled();
expect(navigateSpy).toHaveBeenCalledTimes(1);
expect(navigateSpy).toHaveBeenCalledWith(existingSubmitPolicy.id, expect.any(Boolean));
expect(navigateSpy).toHaveBeenCalledWith(existingSubmitPolicy.id);
});

it('creates a new Submit workspace when the only existing one is pending deletion', async () => {
Expand All @@ -341,7 +341,7 @@ describe('useAutoCreateSubmitWorkspace', () => {
// Then a new Submit workspace is created and the user lands on it, because a workspace
// being deleted should not count as an existing one to reuse
expect(createWorkspaceSpy).toHaveBeenCalledTimes(1);
expect(navigateSpy).toHaveBeenCalledWith(MOCK_POLICY_ID, expect.any(Boolean));
expect(navigateSpy).toHaveBeenCalledWith(MOCK_POLICY_ID);
});

it('keeps the Home fallback for onboarding callers when creation is skipped', async () => {
Expand All @@ -363,7 +363,7 @@ describe('useAutoCreateSubmitWorkspace', () => {
// behavior (landing on Home) so this fix stays scoped to already-onboarded callers
expect(createWorkspaceSpy).not.toHaveBeenCalled();
expect(navigateSpy).toHaveBeenCalledTimes(1);
expect(navigateSpy).toHaveBeenCalledWith(undefined, expect.any(Boolean));
expect(navigateSpy).toHaveBeenCalledWith(undefined);
});

it('uses the localCurrencyCode from personal details for workspace currency', () => {
Expand Down
Loading
Loading