diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3076e029fdad..9fe81b7de5b1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -40,6 +40,7 @@ import type { UserWallet, } from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; +import type Onboarding from '@src/types/onyx/Onboarding'; import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; import type {OriginalMessageChangeLog, PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type {Status} from '@src/types/onyx/PersonalDetails'; @@ -573,6 +574,12 @@ Onyx.connect({ }, }); +let onboarding: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.NVP_ONBOARDING, + callback: (value) => (onboarding = value), +}); + function getCurrentUserAvatar(): AvatarSource | undefined { return currentUserPersonalDetails?.avatar; } @@ -7087,9 +7094,15 @@ function shouldShowMerchantColumn(transactions: Transaction[]) { } /** - * Whether the report is a system chat or concierge chat, depending on the user's account ID (used for A/B testing purposes). + * Whether the report is a system chat or concierge chat, depending on the onboarding report ID or fallbacking + * to the user's account ID (used for A/B testing purposes). */ function isChatUsedForOnboarding(optionOrReport: OnyxEntry | OptionData): boolean { + // onboarding can be an array for old accounts and accounts created from olddot + if (!Array.isArray(onboarding) && onboarding?.chatReportID === optionOrReport?.reportID) { + return true; + } + return AccountUtils.isAccountIDOddNumber(currentUserAccountID ?? -1) ? isSystemChat(optionOrReport) : (optionOrReport as OptionData).isConciergeChat ?? isConciergeChatReport(optionOrReport); diff --git a/src/types/onyx/Onboarding.ts b/src/types/onyx/Onboarding.ts index 9860dd93f9ce..bb250d895c87 100644 --- a/src/types/onyx/Onboarding.ts +++ b/src/types/onyx/Onboarding.ts @@ -1,5 +1,8 @@ /** Model of onboarding */ type Onboarding = { + /** ID of the report used to display the onboarding checklist message */ + chatReportID?: string; + /** A Boolean that informs whether the user has completed the guided setup onboarding flow */ hasCompletedGuidedSetupFlow: boolean; }; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index aa1a2a60628c..34a9a923bd61 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -949,5 +949,25 @@ describe('ReportUtils', () => { expect(ReportUtils.isChatUsedForOnboarding(report)).toBeTruthy(); }); + + it("should use the report id from the onboarding NVP if it's set", async () => { + const reportID = '8010'; + + await Onyx.multiSet({ + [ONYXKEYS.NVP_ONBOARDING]: {chatReportID: reportID, hasCompletedGuidedSetupFlow: true}, + }); + + const report1: Report = { + ...LHNTestUtils.getFakeReport(), + reportID, + }; + expect(ReportUtils.isChatUsedForOnboarding(report1)).toBeTruthy(); + + const report2: Report = { + ...LHNTestUtils.getFakeReport(), + reportID: '8011', + }; + expect(ReportUtils.isChatUsedForOnboarding(report2)).toBeFalsy(); + }); }); });