Skip to content

Commit

Permalink
Merge pull request #51070 from nkdengineer/follow/48745
Browse files Browse the repository at this point in the history
Add policyID param to CompleteOnboarding API
  • Loading branch information
marcaaron authored Oct 31, 2024
2 parents 13b169a + 2a6593f commit 4b619c5
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 47 deletions.
47 changes: 44 additions & 3 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,25 @@ type OnboardingInviteType = ValueOf<typeof onboardingInviteTypes>;
type OnboardingTaskType = {
type: string;
autoCompleted: boolean;
title: string;
description: string | ((params: Partial<{adminsRoomLink: string; workspaceCategoriesLink: string; workspaceMoreFeaturesLink: string; workspaceMembersLink: string}>) => string);
title:
| string
| ((
params: Partial<{
integrationName: string;
}>,
) => string);
description:
| string
| ((
params: Partial<{
adminsRoomLink: string;
workspaceCategoriesLink: string;
workspaceMoreFeaturesLink: string;
workspaceMembersLink: string;
integrationName: string;
workspaceAccountingLink: string;
}>,
) => string);
};

type OnboardingMessageType = {
Expand Down Expand Up @@ -4736,7 +4753,13 @@ const CONST = {
'\n' +
"We'll send a request to each person so they can pay you back. Let me know if you have any questions!",
},

ONBOARDING_ACCOUNTING_MAPPING: {
quickbooksOnline: 'QuickBooks Online',
xero: 'Xero',
netsuite: 'NetSuite',
intacct: 'Sage Intacct',
quickbooksDesktop: 'QuickBooks Desktop',
},
ONBOARDING_MESSAGES: {
[onboardingChoices.EMPLOYER]: onboardingEmployerOrSubmitMessage,
[onboardingChoices.SUBMIT]: onboardingEmployerOrSubmitMessage,
Expand Down Expand Up @@ -4848,6 +4871,24 @@ const CONST = {
'\n' +
`[Take me to workspace members](${workspaceMembersLink}). That’s it, happy expensing! :)`,
},
{
type: 'addAccountingIntegration',
autoCompleted: false,
title: ({integrationName}) => `Connect to ${integrationName}`,
description: ({integrationName, workspaceAccountingLink}) =>
`Connect to ${integrationName} for automatic expense coding and syncing that makes month-end close a breeze.\n` +
'\n' +
`Here’s how to connect to ${integrationName}:\n` +
'\n' +
'1. Click your profile photo.\n' +
'2. Go to Workspaces.\n' +
'3. Select your workspace.\n' +
'4. Click Accounting.\n' +
`5. Find ${integrationName}.\n` +
'6. Click Connect.\n' +
'\n' +
`[Take me to Accounting!](${workspaceAccountingLink})`,
},
],
},
[onboardingChoices.PERSONAL_SPEND]: {
Expand Down
1 change: 1 addition & 0 deletions src/libs/API/parameters/CompleteGuidedSetupParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CompleteGuidedSetupParams = {
paymentSelected?: string;
companySize?: OnboardingCompanySizeType;
userReportedIntegration?: OnboardingAccountingType;
policyID?: string;
};

export default CompleteGuidedSetupParams;
105 changes: 61 additions & 44 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,7 @@ function completeOnboarding(
companySize?: OnboardingCompanySizeType,
userReportedIntegration?: OnboardingAccountingType,
) {
const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration] : '';
const actorAccountID = CONST.ACCOUNT_ID.CONCIERGE;
const targetChatReport = ReportUtils.getChatByParticipants([actorAccountID, currentUserAccountID]);
const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {};
Expand Down Expand Up @@ -3414,50 +3415,65 @@ function completeOnboarding(
};
}

const tasksData = data.tasks.map((task, index) => {
const taskDescription =
typeof task.description === 'function'
? task.description({
adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID ?? '-1')}`,
workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(onboardingPolicyID ?? '-1')}`,
workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(onboardingPolicyID ?? '-1')}`,
workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(onboardingPolicyID ?? '-1')}`,
})
: task.description;
const currentTask = ReportUtils.buildOptimisticTaskReport(
actorAccountID,
currentUserAccountID,
targetChatReportID,
task.title,
taskDescription,
targetChatPolicyID,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
);
const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(CONST.EMAIL.CONCIERGE);
const taskReportAction = ReportUtils.buildOptimisticTaskCommentReportAction(
currentTask.reportID,
task.title,
0,
`task for ${task.title}`,
targetChatReportID,
actorAccountID,
index + 3,
);
currentTask.parentReportActionID = taskReportAction.reportAction.reportActionID;

const completedTaskReportAction = task.autoCompleted
? ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2)
: null;

return {
task,
currentTask,
taskCreatedAction,
taskReportAction,
taskDescription: currentTask.description,
completedTaskReportAction,
};
});
const tasksData = data.tasks
.filter((task) => {
if (task.type === 'addAccountingIntegration' && !userReportedIntegration) {
return false;
}
return true;
})
.map((task, index) => {
const taskDescription =
typeof task.description === 'function'
? task.description({
adminsRoomLink: `${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(adminsChatReportID ?? '-1')}`,
workspaceCategoriesLink: `${environmentURL}/${ROUTES.WORKSPACE_CATEGORIES.getRoute(onboardingPolicyID ?? '-1')}`,
workspaceMembersLink: `${environmentURL}/${ROUTES.WORKSPACE_MEMBERS.getRoute(onboardingPolicyID ?? '-1')}`,
workspaceMoreFeaturesLink: `${environmentURL}/${ROUTES.WORKSPACE_MORE_FEATURES.getRoute(onboardingPolicyID ?? '-1')}`,
integrationName,
workspaceAccountingLink: `${environmentURL}/${ROUTES.POLICY_ACCOUNTING.getRoute(onboardingPolicyID ?? '-1')}`,
})
: task.description;
const taskTitle =
typeof task.title === 'function'
? task.title({
integrationName,
})
: task.title;
const currentTask = ReportUtils.buildOptimisticTaskReport(
actorAccountID,
currentUserAccountID,
targetChatReportID,
taskTitle,
taskDescription,
targetChatPolicyID,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
);
const taskCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(CONST.EMAIL.CONCIERGE);
const taskReportAction = ReportUtils.buildOptimisticTaskCommentReportAction(
currentTask.reportID,
taskTitle,
0,
`task for ${taskTitle}`,
targetChatReportID,
actorAccountID,
index + 3,
);
currentTask.parentReportActionID = taskReportAction.reportAction.reportActionID;

const completedTaskReportAction = task.autoCompleted
? ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2)
: null;

return {
task,
currentTask,
taskCreatedAction,
taskReportAction,
taskDescription: currentTask.description,
completedTaskReportAction,
};
});

const tasksForParameters = tasksData.map<TaskForParameters>(({task, currentTask, taskCreatedAction, taskReportAction, taskDescription, completedTaskReportAction}) => ({
type: 'task',
Expand Down Expand Up @@ -3769,6 +3785,7 @@ function completeOnboarding(
paymentSelected,
companySize,
userReportedIntegration,
policyID: onboardingPolicyID,
};

API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {optimisticData, successData, failureData});
Expand Down

0 comments on commit 4b619c5

Please sign in to comment.