Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Free Trial] [FE] Getting onboarding chat reportID from nvp #45248

Merged
Show file tree
Hide file tree
Changes from 4 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
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 @@ -572,6 +573,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 @@ -7077,9 +7084,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<Report>): boolean {
// onboarding can be an array for old accounts and accounts created from olddot
if (!Array.isArray(onboarding) && onboarding?.chatReportID === report?.reportID) {
chiragsalian marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

return AccountUtils.isAccountIDOddNumber(currentUserAccountID ?? -1) ? isSystemChat(report) : isConciergeChatReport(report);
}

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();
});
});
});
Loading