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
7 changes: 3 additions & 4 deletions src/libs/actions/IOU/PayMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import {buildPolicyData, generatePolicyID} from '@userActions/Policy/Policy';
import type {BuildPolicyDataKeys} from '@userActions/Policy/Policy';
import {completeOnboarding} from '@userActions/Report';
import {notifyNewAction} from '@userActions/Report/reportActionSubscribers';
import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import type {OnboardingCompanySize} from '@userActions/Welcome/OnboardingFlow';
import {getIntroSelectedCompanySize, getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -236,7 +235,7 @@ function getPayMoneyRequestParams({
introSelected,
activePolicy,
conciergeChat,
companySize: introSelected?.companySize as OnboardingCompanySize,
companySize: getIntroSelectedCompanySize(introSelected),
isSelfTourViewed,
delegateAccountID,
// This workspace is created by the invoice payment command, which does not apply CreatePolicy's
Expand Down Expand Up @@ -894,7 +893,7 @@ function completePaymentOnboarding(
onboardingPolicyID,
paymentSelected,
wasInvited: true,
companySize: introSelected?.companySize as OnboardingCompanySize,
companySize: getIntroSelectedCompanySize(introSelected),
introSelected,
isSelfTourViewed,
conciergeChat,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ import * as PaymentMethods from '@userActions/PaymentMethods';
import * as PersistedRequests from '@userActions/PersistedRequests';
import {buildTaskData, getOnboardingTaskCompletionOnSuccessData, withReviewWorkspaceSettingsTaskData} from '@userActions/Task';
import type {OnboardingTaskCompletionOnyxData} from '@userActions/Task';
import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import {getIntroSelectedCompanySize, getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import type {OnboardingCompanySize, OnboardingPurpose} from '@userActions/Welcome/OnboardingFlow';

import CONST from '@src/CONST';
Expand Down Expand Up @@ -3462,7 +3462,7 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData<BuildPolicyD
adminsChatReportID,
onboardingPolicyID: policyID,
onboardingPurposeSelected,
companySize: companySize ?? (introSelected?.companySize as OnboardingCompanySize),
companySize: companySize ?? getIntroSelectedCompanySize(introSelected),
isSelfTourViewed,
conciergeChat,
delegateAccountID,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ import {
import {isAnonymousUser} from '@userActions/Session';
import {getChangeTransactionsReportOnyxData} from '@userActions/Transaction';
import {onServerDataReady} from '@userActions/Welcome';
import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import {getIntroSelectedCompanySize, getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import type {OnboardingCompanySize, OnboardingMessage} from '@userActions/Welcome/OnboardingFlow';

import CONFIG from '@src/CONFIG';
Expand Down Expand Up @@ -1720,7 +1720,7 @@ function getGuidedSetupDataForOpenReport(
engagementChoice: choice,
onboardingMessage,
conciergeChat,
companySize: introSelected?.companySize as OnboardingCompanySize,
companySize: getIntroSelectedCompanySize(introSelected),
isSelfTourViewed,
wasInvited: isPendingInviteOnboarding && isOnboardingCompleted,
currentUserAccountID,
Expand Down
21 changes: 19 additions & 2 deletions src/libs/actions/Welcome/OnboardingFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type {Account, Locale, Onboarding} from '@src/types/onyx';
import type {Account, IntroSelected, Locale, Onboarding} from '@src/types/onyx';

import type {NavigationState, PartialState} from '@react-navigation/native';
import type {OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -163,6 +163,15 @@ function buildOnboardingFlowParams(
};
}

/**
* Returns the saved onboarding company size only when it is one of the known sizes, current or legacy.
* `companySize` is stored as a plain string, so an unknown value is dropped instead of being sent as a company size.
*/
function getIntroSelectedCompanySize(introSelected: OnyxEntry<IntroSelected>): OnboardingCompanySize | undefined {
const companySize = introSelected?.companySize;
return Object.values(CONST.ONBOARDING_COMPANY_SIZE).find((size) => size === companySize);
}

/**
* Resolves the onboarding path to resume after required-2FA setup during incomplete guided setup.
*/
Expand Down Expand Up @@ -209,4 +218,12 @@ async function resumeOnboardingAfterRequired2FASetup(onboardingFlowParams: GetOn
const getOnboardingMessages = (locale?: Locale) => buildOnboardingMessages(onboardingData, locale);

export type {OnboardingMessage, OnboardingTask, OnboardingTaskLinks, OnboardingPurpose, OnboardingCompanySize, GetOnboardingInitialPathParamsType};
export {buildOnboardingFlowParams, getOnboardingInitialPath, getRequired2FAOnboardingResumePath, resumeOnboardingAfterRequired2FASetup, startOnboardingFlow, getOnboardingMessages};
export {
buildOnboardingFlowParams,
getIntroSelectedCompanySize,
getOnboardingInitialPath,
getRequired2FAOnboardingResumePath,
resumeOnboardingAfterRequired2FASetup,
startOnboardingFlow,
getOnboardingMessages,
};
22 changes: 21 additions & 1 deletion tests/unit/OnboardingFlowTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getOnboardingInitialPath, getOnboardingMessages, getRequired2FAOnboardingResumePath, startOnboardingFlow} from '@libs/actions/Welcome/OnboardingFlow';
import {getIntroSelectedCompanySize, getOnboardingInitialPath, getOnboardingMessages, getRequired2FAOnboardingResumePath, startOnboardingFlow} from '@libs/actions/Welcome/OnboardingFlow';
import type {GetOnboardingInitialPathParamsType} from '@libs/actions/Welcome/OnboardingFlow';
import getAdaptedStateFromPath from '@libs/Navigation/helpers/getAdaptedStateFromPath';
import navigationRef from '@libs/Navigation/navigationRef';
Expand Down Expand Up @@ -329,6 +329,26 @@ describe('OnboardingFlow', () => {
});
});

describe('getIntroSelectedCompanySize', () => {
it('keeps current and legacy company sizes', () => {
// Given company sizes saved by the current onboarding UI and by an older one that the UI no longer offers
// When they are read back for the onboarding request
// Then both are sent, so users who onboarded with a legacy range keep their company size
expect(getIntroSelectedCompanySize({companySize: '5-9'})).toBe(CONST.ONBOARDING_COMPANY_SIZE.MICRO_MEDIUM);
expect(getIntroSelectedCompanySize({companySize: '1-10'})).toBe(CONST.ONBOARDING_COMPANY_SIZE.LEGACY_MICRO);
});

it('drops a company size that is not a known size', () => {
// Given a stored value that is not one of the known sizes, and no saved value at all
// When they are read back for the onboarding request
// Then no company size is returned, so an unknown string is never sent as a company size
expect(getIntroSelectedCompanySize({companySize: '7-8'})).toBeUndefined();
expect(getIntroSelectedCompanySize({companySize: ''})).toBeUndefined();
expect(getIntroSelectedCompanySize({})).toBeUndefined();
expect(getIntroSelectedCompanySize(undefined)).toBeUndefined();
});
});

describe('getRequired2FAOnboardingResumePath', () => {
it('returns personal-details for private domain users with accessible policies and no saved path', () => {
const params: GetOnboardingInitialPathParamsType = {
Expand Down
Loading