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
1 change: 1 addition & 0 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@
type StartSplitBilActionParams = {
participants: Participant[];
currentUserLogin: string;
currentUserAccountID: number;

Check warning on line 804 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
comment: string;
receipt: Receipt;
existingSplitChatReportID?: string;
Expand Down Expand Up @@ -894,7 +894,7 @@
}

allTransactions = value;
},

Check warning on line 897 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Expand All @@ -908,7 +908,7 @@

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,

Check warning on line 911 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
Expand All @@ -917,7 +917,7 @@
}

allTransactionViolations = value;
},

Check warning on line 920 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Expand All @@ -931,7 +931,7 @@
}
allPolicyTags = value;
},
});

Check warning on line 934 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({
Expand All @@ -944,7 +944,7 @@

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,

Check warning on line 947 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
waitForCollectionCallback: true,
callback: (value) => {
allReportNameValuePairs = value;
Expand All @@ -953,7 +953,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 956 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -963,7 +963,7 @@

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,

Check warning on line 966 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
},
Expand All @@ -972,7 +972,7 @@
let allReportActions: OnyxCollection<OnyxTypes.ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,

Check warning on line 975 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (actions) => {
if (!actions) {
return;
Expand All @@ -980,7 +980,7 @@
allReportActions = actions;
},
});

Check warning on line 983 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let personalDetailsList: OnyxEntry<OnyxTypes.PersonalDetailsList>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
Expand Down Expand Up @@ -11835,6 +11835,7 @@
wasInvited: true,
shouldSkipTestDriveModal: true,
companySize: introSelected?.companySize as OnboardingCompanySize,
introSelected,
});
}

Expand Down
12 changes: 7 additions & 5 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,8 +1299,8 @@ function openReport(

// Prepare guided setup data only when nvp_introSelected is set and onboarding is not completed
// OldDot users will never have nvp_introSelected set, so they will not see guided setup messages
if (introSelected && !isOnboardingCompleted && !isInviteOnboardingComplete && !hasOpenReportWithGuidedSetupData) {
const {choice, inviteType} = introSelected;
if (deprecatedIntroSelected && !isOnboardingCompleted && !isInviteOnboardingComplete && !hasOpenReportWithGuidedSetupData) {

Choose a reason for hiding this comment

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

P1 Badge Keep openReport gating tied to passed intro state

openReport() now gates guided-setup injection on the module-global deprecatedIntroSelected instead of its introSelected argument, while isInviteOnboardingComplete is still read from the argument. This mismatch changes behavior for existing call paths that intentionally pass undefined (for example, src/libs/actions/replaceOptimisticReportWithActualReport.ts calls openReport(parentReportID, undefined)): if global intro state is populated, this branch can still attach guided setup data and set invite onboarding complete during unrelated report-refresh flows, creating duplicate/incorrect onboarding side effects.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dukenv0307 thoughts here?

Copy link
Contributor

Choose a reason for hiding this comment

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

const {choice, inviteType} = deprecatedIntroSelected;
const isInviteIOUorInvoice = inviteType === CONST.ONBOARDING_INVITE_TYPES.IOU || inviteType === CONST.ONBOARDING_INVITE_TYPES.INVOICE;
const isInviteChoiceCorrect = choice === CONST.ONBOARDING_CHOICES.ADMIN || choice === CONST.ONBOARDING_CHOICES.SUBMIT || choice === CONST.ONBOARDING_CHOICES.CHAT_SPLIT;

Expand All @@ -1312,10 +1312,10 @@ function openReport(
}

const onboardingData = prepareOnboardingOnyxData({
introSelected,
introSelected: deprecatedIntroSelected,
engagementChoice: choice,
onboardingMessage,
companySize: introSelected?.companySize as OnboardingCompanySize,
companySize: deprecatedIntroSelected?.companySize as OnboardingCompanySize,
});

if (onboardingData) {
Expand Down Expand Up @@ -4537,6 +4537,7 @@ type CompleteOnboardingProps = {
isInvitedAccountant?: boolean;
onboardingPurposeSelected?: OnboardingPurpose;
shouldWaitForRHPVariantInitialization?: boolean;
introSelected: OnyxEntry<IntroSelected>;
};

async function completeOnboarding({
Expand All @@ -4555,9 +4556,10 @@ async function completeOnboarding({
isInvitedAccountant,
onboardingPurposeSelected,
shouldWaitForRHPVariantInitialization = false,
introSelected,
}: CompleteOnboardingProps) {
const onboardingData = prepareOnboardingOnyxData({
introSelected: deprecatedIntroSelected,
introSelected,
engagementChoice,
onboardingMessage,
adminsChatReportID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin
selectedInterestedFeatures: featuresMap.filter((feature) => feature.enabled).map((feature) => feature.id),
shouldSkipTestDriveModal: !!policyID && !adminsChatReportID,
shouldWaitForRHPVariantInitialization: isSidePanelReportSupported,
introSelected,
});

// Avoid creating new WS because onboardingPolicyID is cleared before unmounting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID, {canBeMissing: true});
const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, {canBeMissing: true});
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const archivedReportsIdSet = useArchivedReportsIdSet();
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {canBeMissing: true});
Expand Down Expand Up @@ -80,6 +81,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
adminsChatReportID: onboardingAdminsChatReportID,
onboardingPolicyID,
shouldSkipTestDriveModal: !!onboardingPolicyID && !mergedAccountConciergeReportID,
introSelected,
});

setOnboardingAdminsChatReportID();
Expand All @@ -105,6 +107,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
isSmallScreenWidth,
mergedAccountConciergeReportID,
conciergeChatReportID,
introSelected,
],
);

Expand Down
2 changes: 2 additions & 0 deletions src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro
const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, {canBeMissing: true});
const [personalDetailsForm] = useOnyx(ONYXKEYS.FORMS.ONBOARDING_PERSONAL_DETAILS_FORM, {canBeMissing: true});
const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const paddingHorizontal = onboardingIsMediumOrLargerScreenWidth ? styles.ph8 : styles.ph5;

const [customChoices = getEmptyArray<OnboardingPurpose>()] = useOnyx(ONYXKEYS.ONBOARDING_CUSTOM_CHOICES, {canBeMissing: true});
Expand Down Expand Up @@ -105,6 +106,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro
adminsChatReportID: onboardingAdminsChatReportID ?? undefined,
onboardingPolicyID,
companySize: onboardingCompanySize,
introSelected,
});

// eslint-disable-next-line @typescript-eslint/no-deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID, {canBeMissing: true});
const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, {canBeMissing: true});
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const policy = usePolicy(onboardingPolicyID);
const {onboardingMessages} = useOnboardingMessages();
// We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment
Expand Down Expand Up @@ -130,6 +131,7 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
shouldSkipTestDriveModal: !!onboardingPolicyID && !onboardingAdminsChatReportID,
isInvitedAccountant,
onboardingPurposeSelected,
introSelected,
});

setOnboardingAdminsChatReportID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function BaseOnboardingWorkspaceOptional({shouldUseNativeStyles}: BaseOnboarding
const [conciergeChatReportID = ''] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID, {canBeMissing: true});
const archivedReportsIdSet = useArchivedReportsIdSet();
const {onboardingMessages} = useOnboardingMessages();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const {isRestrictedPolicyCreation} = usePreferredPolicy();
// When we merge public email with work email, we now want to navigate to the
// concierge chat report of the new work email and not the last accessed report.
Expand Down Expand Up @@ -88,6 +89,7 @@ function BaseOnboardingWorkspaceOptional({shouldUseNativeStyles}: BaseOnboarding
adminsChatReportID: onboardingAdminsChatReportID,
onboardingPolicyID,
shouldSkipTestDriveModal: !!onboardingPolicyID && !onboardingAdminsChatReportID,
introSelected,
});

setOnboardingAdminsChatReportID();
Expand All @@ -113,6 +115,7 @@ function BaseOnboardingWorkspaceOptional({shouldUseNativeStyles}: BaseOnboarding
isSmallScreenWidth,
isBetaEnabled,
mergedAccountConciergeReportID,
introSelected,
conciergeChatReportID,
]);

Expand Down
13 changes: 12 additions & 1 deletion src/pages/OnboardingWorkspaces/BaseOnboardingWorkspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE, {canBeMissing: true});
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true});
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const archivedReportsIdSet = useArchivedReportsIdSet();

const isValidated = isCurrentUserValidated(loginList, session?.email);
Expand All @@ -75,6 +76,7 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
lastName: onboardingPersonalDetails?.lastName ?? '',
shouldSkipTestDriveModal: !!(policy.automaticJoiningEnabled ? policy.policyID : undefined),
companySize: onboardingCompanySize,
introSelected,
});
setOnboardingAdminsChatReportID();
setOnboardingPolicyID(policy.policyID);
Expand All @@ -89,7 +91,16 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
false,
);
},
[onboardingMessages, onboardingPersonalDetails?.firstName, onboardingPersonalDetails?.lastName, isSmallScreenWidth, isBetaEnabled, onboardingCompanySize, archivedReportsIdSet],
[
onboardingMessages,
onboardingPersonalDetails?.firstName,
onboardingPersonalDetails?.lastName,
isSmallScreenWidth,
isBetaEnabled,
onboardingCompanySize,
archivedReportsIdSet,
introSelected,
],
);

const policyIDItems = useMemo(() => {
Expand Down
139 changes: 139 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
cancelPayment,
canIOUBePaid,
canUnapproveIOU,
completePaymentOnboarding,
convertBulkTrackedExpensesToIOU,
createDistanceRequest,
deleteMoneyRequest,
Expand Down Expand Up @@ -14955,4 +14956,142 @@ describe('actions/IOU', () => {
}).not.toThrow();
});
});

describe('completePaymentOnboarding', () => {
let completeOnboardingSpy: jest.SpyInstance;

beforeEach(async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
completeOnboardingSpy = jest.spyOn(require('@libs/actions/Report'), 'completeOnboarding').mockImplementation(jest.fn());
await Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID});
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {
[CARLOS_ACCOUNT_ID]: {
accountID: CARLOS_ACCOUNT_ID,
firstName: 'Carlos',
lastName: 'Test',
},
});
await waitForBatchedUpdates();
});

afterEach(() => {
completeOnboardingSpy.mockRestore();
});

it('should not call completeOnboarding when introSelected is undefined', () => {
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, undefined);
expect(completeOnboardingSpy).not.toHaveBeenCalled();
});

it('should not call completeOnboarding when isInviteOnboardingComplete is true', () => {
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, {
choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
inviteType: CONST.ONBOARDING_INVITE_TYPES.IOU,
isInviteOnboardingComplete: true,
});
expect(completeOnboardingSpy).not.toHaveBeenCalled();
});

it('should not call completeOnboarding when choice is missing', () => {
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, {
inviteType: CONST.ONBOARDING_INVITE_TYPES.IOU,
});
expect(completeOnboardingSpy).not.toHaveBeenCalled();
});

it('should not call completeOnboarding when inviteType is missing', () => {
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, {
choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
});
expect(completeOnboardingSpy).not.toHaveBeenCalled();
});

it('should override purpose to MANAGE_TEAM for IOU invite with BBA payment', () => {
const introSelected: IntroSelected = {
choice: CONST.ONBOARDING_CHOICES.SUBMIT,
inviteType: CONST.ONBOARDING_INVITE_TYPES.IOU,
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
};
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, introSelected);

expect(completeOnboardingSpy).toHaveBeenCalledWith(
expect.objectContaining({
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
paymentSelected: CONST.PAYMENT_SELECTED.BBA,
wasInvited: true,
shouldSkipTestDriveModal: true,
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
introSelected,
}),
);
});

it('should override purpose to CHAT_SPLIT for INVOICE invite with PBA payment', () => {
const introSelected: IntroSelected = {
choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
inviteType: CONST.ONBOARDING_INVITE_TYPES.INVOICE,
companySize: CONST.ONBOARDING_COMPANY_SIZE.SMALL,
};
completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA, introSelected);

expect(completeOnboardingSpy).toHaveBeenCalledWith(
expect.objectContaining({
engagementChoice: CONST.ONBOARDING_CHOICES.CHAT_SPLIT,
paymentSelected: CONST.PAYMENT_SELECTED.PBA,
wasInvited: true,
shouldSkipTestDriveModal: true,
companySize: CONST.ONBOARDING_COMPANY_SIZE.SMALL,
introSelected,
}),
);
});

it('should keep original purpose for INVOICE invite with BBA payment', () => {
const introSelected: IntroSelected = {
choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
inviteType: CONST.ONBOARDING_INVITE_TYPES.INVOICE,
};
completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA, introSelected);

expect(completeOnboardingSpy).toHaveBeenCalledWith(
expect.objectContaining({
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
introSelected,
}),
);
});

it('should keep original purpose for IOU invite with PBA payment', () => {
const introSelected: IntroSelected = {
choice: CONST.ONBOARDING_CHOICES.SUBMIT,
inviteType: CONST.ONBOARDING_INVITE_TYPES.IOU,
};
completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA, introSelected);

expect(completeOnboardingSpy).toHaveBeenCalledWith(
expect.objectContaining({
engagementChoice: CONST.ONBOARDING_CHOICES.SUBMIT,
introSelected,
}),
);
});

it('should pass introSelected and optional params through to completeOnboarding', () => {
const introSelected: IntroSelected = {
choice: CONST.ONBOARDING_CHOICES.CHAT_SPLIT,
inviteType: CONST.ONBOARDING_INVITE_TYPES.CHAT,
companySize: CONST.ONBOARDING_COMPANY_SIZE.MEDIUM,
};
completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA, introSelected, 'adminsChatReport123', 'policyID456');

expect(completeOnboardingSpy).toHaveBeenCalledWith(
expect.objectContaining({
engagementChoice: CONST.ONBOARDING_CHOICES.CHAT_SPLIT,
adminsChatReportID: 'adminsChatReport123',
onboardingPolicyID: 'policyID456',
introSelected,
}),
);
});
});
});
2 changes: 2 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,7 @@ describe('actions/Report', () => {
onboardingPolicyID,
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
userReportedIntegration: null,
introSelected: {choice: engagementChoice},
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -3506,6 +3507,7 @@ describe('actions/Report', () => {
onboardingPolicyID,
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
userReportedIntegration: null,
introSelected: {choice: engagementChoice},
});

await waitForBatchedUpdates();
Expand Down
Loading
Loading