Skip to content
Merged
2 changes: 2 additions & 0 deletions src/libs/API/parameters/CompleteGuidedSetupParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type CompleteGuidedSetupParams = {
policyID?: string;
selfDMReportID?: string;
selfDMCreatedReportActionID?: string;
bespokeWelcomeMessage?: string;
optimisticConciergeReportActionID?: string;
};

export default CompleteGuidedSetupParams;
76 changes: 75 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@
};

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

Check warning on line 1024 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 @@ -1029,7 +1029,7 @@
});

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

Check warning on line 1032 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 @@ -1047,7 +1047,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1050 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 @@ -1059,7 +1059,7 @@
});

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

Check warning on line 1062 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 @@ -1068,7 +1068,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1071 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 @@ -1079,7 +1079,7 @@
});

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

Check warning on line 1082 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 @@ -1087,7 +1087,7 @@

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

Check warning on line 1090 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 @@ -1123,14 +1123,14 @@
});

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

Check warning on line 1126 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 allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1133 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 @@ -1156,7 +1156,7 @@
});

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

Check warning on line 1159 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 @@ -11421,6 +11421,26 @@
betas?: OnyxEntry<Beta[]>;
};

function getBespokeWelcomeMessage(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!";

if (userReportedIntegration && userReportedIntegration !== 'other') {
const friendlyName = CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration as keyof typeof CONST.ONBOARDING_ACCOUNTING_MAPPING];
if (friendlyName) {
message += `\n\nSince you use ${friendlyName}, I can help you connect it so your expenses sync automatically — just say the word!`;
}
}

return message;
}

function prepareOnboardingOnyxData({
introSelected,
engagementChoice,
Expand Down Expand Up @@ -11523,6 +11543,18 @@
reportComment: textComment.commentText,
};

// When the user is MICRO and using followups, 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);
optimisticConciergeReportActionID = rand64();
bespokeAction = buildOptimisticAddCommentReportAction(bespokeWelcomeMessage, undefined, CONST.ACCOUNT_ID.CONCIERGE, 2, targetChatReportID, optimisticConciergeReportActionID);
}

let createWorkspaceTaskReportID;
let addExpenseApprovalsTaskReportID;
let setupTagsTaskReportID;
Expand Down Expand Up @@ -11838,6 +11870,26 @@
});
}

if (bespokeAction && optimisticConciergeReportActionID) {
optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[optimisticConciergeReportActionID]: bespokeAction.reportAction as ReportAction,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`,
value: {
lastVisibleActionCreated: bespokeAction.reportAction.created,
lastActorAccountID: CONST.ACCOUNT_ID.CONCIERGE,
},
},
);
}

if (!wasInvited) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -11858,6 +11910,16 @@
},
});

if (bespokeAction && optimisticConciergeReportActionID) {
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[optimisticConciergeReportActionID]: {pendingAction: null, isOptimisticAction: null},
},
});
}

let failureReport: Partial<Report> = {
lastMessageText: '',
lastVisibleActionCreated: '',
Expand Down Expand Up @@ -11911,6 +11973,18 @@
},
});

if (bespokeAction && optimisticConciergeReportActionID) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
value: {
[optimisticConciergeReportActionID]: {
errors: getMicroSecondOnyxErrorWithTranslationKey('report.genericAddCommentFailureMessage'),
} as ReportAction,
},
});
}

if (!wasInvited) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -12084,7 +12158,7 @@
});
}

return {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters};
return {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters, bespokeWelcomeMessage, optimisticConciergeReportActionID};
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4847,7 +4847,7 @@ async function completeOnboarding({
return;
}

const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters} = onboardingData;
const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters, bespokeWelcomeMessage, optimisticConciergeReportActionID} = onboardingData;

const parameters: CompleteGuidedSetupParams = {
engagementChoice,
Expand All @@ -4861,6 +4861,8 @@ async function completeOnboarding({
policyID: onboardingPolicyID,
selfDMReportID: selfDMParameters.reportID,
selfDMCreatedReportActionID: selfDMParameters.createdReportActionID,
bespokeWelcomeMessage,
optimisticConciergeReportActionID,
};

// We should only set testDriveModalDismissed to false if it's not already true (i.e., if the modal hasn't been dismissed yet).
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ describe('ReportUtils', () => {
companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO,
});
expect(result?.guidedSetupData).toHaveLength(0);
expect(result?.optimisticData.filter((i) => i.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`)).toHaveLength(0);
// MICRO company size with suggestedFollowups beta adds a bespoke Concierge welcome action optimistically
const reportActionsEntries = result?.optimisticData.filter((i) => i.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`);
expect(reportActionsEntries).toHaveLength(1);
expect(result?.bespokeWelcomeMessage).toBeDefined();
expect(result?.optimisticConciergeReportActionID).toBeDefined();
});

it('should add guidedSetupData when posting into admin room WITHOUT suggestedFollowups beta', async () => {
Expand Down
Loading