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
39 changes: 29 additions & 10 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1055 in src/libs/ReportUtils.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.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1060,7 +1060,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1063 in src/libs/ReportUtils.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) => {
// When signed out, val is undefined
Expand All @@ -1078,7 +1078,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1081 in src/libs/ReportUtils.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.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1090,7 +1090,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1093 in src/libs/ReportUtils.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.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1098,7 +1098,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1101 in src/libs/ReportUtils.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.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1108,7 +1108,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1111 in src/libs/ReportUtils.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.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1116,7 +1116,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1119 in src/libs/ReportUtils.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.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1152,14 +1152,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1155 in src/libs/ReportUtils.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.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1162 in src/libs/ReportUtils.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.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1185,7 +1185,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1188 in src/libs/ReportUtils.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.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -11629,15 +11629,34 @@
betas?: OnyxEntry<Beta[]>;
};

function getBespokeWelcomeMessage(userReportedIntegration?: OnboardingAccounting): string {
function getBespokeWelcomeMessage(companySize: OnboardingCompanySize | undefined, userReportedIntegration?: OnboardingAccounting): string {
// Use markdown (not HTML) because buildOptimisticAddCommentReportAction -> getParsedComment
// escapes HTML entities before parsing, so raw HTML tags would render as literal text.
let message =
"# Your free trial has started! Let's get you set up.\n" +
"👋 Hey there! I'm your Expensify setup specialist. " +
'For a small team like yours, the fastest way to get value is to set up a few expense categories, ' +
'invite your team members, and have them start snapping receipts right away. ' +
"I'm here to walk you through each step — just ask!";
const welcomeHeader = "# Your free trial has started! Let's get you set up.\n👋 Hey there! I'm your Expensify setup specialist. ";

let message = welcomeHeader;
switch (companySize) {
case CONST.ONBOARDING_COMPANY_SIZE.MEDIUM:
case CONST.ONBOARDING_COMPANY_SIZE.LARGE:
message +=
'For an organization your size, the fastest path to value is setting up approval workflows, ' +
'connecting your accounting software, and rolling out the Expensify Card to your team. ' +
"I'm here to walk you through each step — just ask!";
break;
case CONST.ONBOARDING_COMPANY_SIZE.SMALL:
case CONST.ONBOARDING_COMPANY_SIZE.MEDIUM_SMALL:
message +=
'For a growing team like yours, the fastest way to get value is to set up expense categories, ' +
'configure approval workflows, and invite your team members. ' +
"I'm here to walk you through each step — just ask!";
break;
default:
message +=
'For a small team like yours, the fastest way to get value is to set up a few expense categories, ' +
'invite your team members, and have them start snapping receipts right away. ' +
"I'm here to walk you through each step — just ask!";
break;
}

if (userReportedIntegration && userReportedIntegration !== 'other') {
const friendlyName = CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration as keyof typeof CONST.ONBOARDING_ACCOUNTING_MAPPING];
Expand Down Expand Up @@ -11744,14 +11763,14 @@
reportComment: textComment.commentText,
};

// When the user is MICRO and using followups, generate a bespoke welcome message from Concierge.
// When using followups instead of tasks, generate a bespoke welcome message from Concierge.
// The frontend displays it optimistically; the server uses it to generate suggested followups.
let bespokeWelcomeMessage: string | undefined;
let optimisticConciergeReportActionID: string | undefined;
let bespokeAction: OptimisticReportAction | undefined;

if (shouldUseFollowupsInsteadOfTasks && companySize === CONST.ONBOARDING_COMPANY_SIZE.MICRO) {
bespokeWelcomeMessage = getBespokeWelcomeMessage(userReportedIntegration);
if (shouldUseFollowupsInsteadOfTasks) {
bespokeWelcomeMessage = getBespokeWelcomeMessage(companySize, userReportedIntegration);
optimisticConciergeReportActionID = rand64();
bespokeAction = buildOptimisticAddCommentReportAction({
text: bespokeWelcomeMessage,
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('actions/Policy', () => {

// After filtering, two actions are added to the list =- signoff message (+1) and default create action (+1)
const expectedReportActionsOfTypeCreatedCount = 1;
const expectedSignOffMessagesCount = 0;
const expectedSignOffMessagesCount = 1;
expect(adminReportActions.length).toBe(expectedManageTeamDefaultTasksCount + expectedReportActionsOfTypeCreatedCount + expectedSignOffMessagesCount);

let reportActionsOfTypeCreatedCount = 0;
Expand Down
114 changes: 112 additions & 2 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,123 @@ describe('ReportUtils', () => {
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
});
expect(result?.guidedSetupData).toHaveLength(0);
// MICRO company size with suggestedFollowups beta adds a bespoke Concierge welcome action optimistically
// suggestedFollowups beta adds a bespoke Concierge welcome action optimistically for all company sizes
const reportActionsEntries = result?.optimisticData.filter((i) => i.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`);
expect(reportActionsEntries).toHaveLength(1);
expect(result?.bespokeWelcomeMessage).toBeDefined();
expect(result?.bespokeWelcomeMessage).toContain('For a small team like yours');
expect(result?.optimisticConciergeReportActionID).toBeDefined();
});

it('should generate bespoke welcome message for SMALL company sizes with suggestedFollowups beta', async () => {
const adminsChatReportID = '1';
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
await waitForBatchedUpdates();

const result = prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false}],
},
adminsChatReportID,
selectedInterestedFeatures: ['areCompanyCardsEnabled'],
companySize: CONST.ONBOARDING_COMPANY_SIZE.SMALL,
});
expect(result?.guidedSetupData).toHaveLength(0);
expect(result?.bespokeWelcomeMessage).toContain('growing team');
expect(result?.optimisticConciergeReportActionID).toBeDefined();
});

it('should generate bespoke welcome message for LARGE company sizes with suggestedFollowups beta', async () => {
const adminsChatReportID = '1';
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
await waitForBatchedUpdates();

const result = prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false}],
},
adminsChatReportID,
selectedInterestedFeatures: ['areCompanyCardsEnabled'],
companySize: CONST.ONBOARDING_COMPANY_SIZE.LARGE,
});
expect(result?.guidedSetupData).toHaveLength(0);
expect(result?.bespokeWelcomeMessage).toContain('organization your size');
expect(result?.optimisticConciergeReportActionID).toBeDefined();
});

it('should generate bespoke welcome message for MEDIUM_SMALL company sizes with suggestedFollowups beta', async () => {
const adminsChatReportID = '1';
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
await waitForBatchedUpdates();

const result = prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false}],
},
adminsChatReportID,
selectedInterestedFeatures: ['areCompanyCardsEnabled'],
companySize: CONST.ONBOARDING_COMPANY_SIZE.MEDIUM_SMALL,
});
expect(result?.guidedSetupData).toHaveLength(0);
expect(result?.bespokeWelcomeMessage).toContain('growing team');
expect(result?.optimisticConciergeReportActionID).toBeDefined();
});

it('should generate bespoke welcome message for MEDIUM company sizes with suggestedFollowups beta', async () => {
const adminsChatReportID = '1';
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
await waitForBatchedUpdates();

const result = prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false}],
},
adminsChatReportID,
selectedInterestedFeatures: ['areCompanyCardsEnabled'],
companySize: CONST.ONBOARDING_COMPANY_SIZE.MEDIUM,
});
expect(result?.guidedSetupData).toHaveLength(0);
expect(result?.bespokeWelcomeMessage).toContain('organization your size');
expect(result?.optimisticConciergeReportActionID).toBeDefined();
});

it('should append accounting integration suffix to bespoke welcome message', async () => {
const adminsChatReportID = '1';
await Onyx.merge(ONYXKEYS.SESSION, {email: 'test@example.com'});
await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.SUGGESTED_FOLLOWUPS]);
await waitForBatchedUpdates();

const result = prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false}],
},
adminsChatReportID,
selectedInterestedFeatures: ['areCompanyCardsEnabled'],
companySize: CONST.ONBOARDING_COMPANY_SIZE.SMALL,
userReportedIntegration: 'quickbooksOnline',
});
expect(result?.bespokeWelcomeMessage).toContain('QuickBooks Online');
expect(result?.bespokeWelcomeMessage).toContain('expenses sync automatically');
});

it('should add guidedSetupData when posting into admin room WITHOUT suggestedFollowups beta', async () => {
const adminsChatReportID = '1';
// Not having `+` in the email allows for `isPostingTasksInAdminsRoom` flow
Expand Down
Loading