From 7d516cd4e2a4046215775ff6db5d86e565a77212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Tue, 9 Jul 2024 18:05:23 +0100 Subject: [PATCH 1/3] Add chatReportID property to Onboard and corresponding logic --- src/libs/ReportUtils.ts | 15 ++++++++++++++- src/types/onyx/Onboarding.ts | 3 +++ tests/unit/ReportUtilsTest.ts | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bf1d86dad32f..ff759b8266b3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -39,6 +39,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'; @@ -550,6 +551,12 @@ Onyx.connect({ }, }); +let onboarding: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.NVP_ONBOARDING, + callback: (value) => (onboarding = value), +}); + function getCurrentUserAvatar(): AvatarSource | undefined { return currentUserPersonalDetails?.avatar; } @@ -7052,9 +7059,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(report: OnyxEntry): boolean { + // onboarding can be an array for old accounts and accounts created from olddot + if (!Array.isArray(onboarding) && onboarding?.chatReportID === report?.reportID) { + return true; + } + return AccountUtils.isAccountIDOddNumber(currentUserAccountID ?? -1) ? isSystemChat(report) : isConciergeChatReport(report); } 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 4ec530036ba5..626afefb5548 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -953,5 +953,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(); + }); }); }); From 677bde86f906b7dcea4f8ee480fd17f942489f2d Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Thu, 11 Jul 2024 17:20:04 +0100 Subject: [PATCH 2/3] chore: fix linter issue --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 805d173d8b56..7699e4fed557 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7403,4 +7403,4 @@ export type { TransactionDetails, PartialReportAction, ParsingDetails, -} \ No newline at end of file +}; From b5cc9391833010ff57529eeb1d6dddea076d3ff5 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Thu, 11 Jul 2024 19:44:53 +0100 Subject: [PATCH 3/3] fix: merge conflict --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e50d997207ec..b365b394962a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7092,7 +7092,7 @@ function shouldShowMerchantColumn(transactions: Transaction[]) { */ 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 === report?.reportID) { + if (!Array.isArray(onboarding) && onboarding?.chatReportID === optionOrReport?.reportID) { return true; }