Skip to content

Commit

Permalink
Merge pull request Expensify#45248 from callstack-internal/pac-guerre…
Browse files Browse the repository at this point in the history
…iro/feature/45238-getting-onboarding-chat-reportID-from-nvp

[Free Trial] [FE] Getting onboarding chat reportID from nvp
  • Loading branch information
chiragsalian authored Jul 11, 2024
2 parents 45eec25 + b5cc939 commit 3fd1644
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -573,6 +574,12 @@ Onyx.connect({
},
});

let onboarding: OnyxEntry<Onboarding | []>;
Onyx.connect({
key: ONYXKEYS.NVP_ONBOARDING,
callback: (value) => (onboarding = value),
});

function getCurrentUserAvatar(): AvatarSource | undefined {
return currentUserPersonalDetails?.avatar;
}
Expand Down Expand Up @@ -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<Report> | 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);
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Onboarding.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit 3fd1644

Please sign in to comment.