From b1c34f1e114dbd528969693e43f03b899a975ea8 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 19 Apr 2024 15:38:02 +0200 Subject: [PATCH] integrate autocompleted tasks --- src/CONST.ts | 13 +++++++++++++ src/libs/ReportUtils.ts | 12 +++++++++--- src/libs/actions/Report.ts | 30 ++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index acc9193a6729..0d07d1a6acb8 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3621,6 +3621,7 @@ const CONST = { tasks: [ { type: 'createWorkspace', + autoCompleted: true, title: 'Create a workspace', subtitle: 'Create a workspace to track expenses, scan receipts, chat, and more.', message: @@ -3633,6 +3634,7 @@ const CONST = { }, { type: 'trackExpense', + autoCompleted: false, title: 'Track an expense', subtitle: 'Track an expense in any currency, in just a few clicks.', message: @@ -3659,6 +3661,7 @@ const CONST = { tasks: [ { type: 'submitExpense', + autoCompleted: false, title: 'Submit an expense', subtitle: 'Submit an expense by entering an amount or scanning a receipt.', message: @@ -3673,6 +3676,7 @@ const CONST = { }, { type: 'enableWallet', + autoCompleted: false, title: 'Enable your wallet', subtitle: 'You’ll need to enable your Expensify Wallet to get paid back. Don’t worry, it’s easy!', message: @@ -3698,6 +3702,7 @@ const CONST = { tasks: [ { type: 'createWorkspace', + autoCompleted: true, title: 'Create a workspace', subtitle: 'Create a workspace to track expenses, scan receipts, chat, and more.', message: @@ -3710,6 +3715,7 @@ const CONST = { }, { type: 'meetGuide', + autoCompleted: false, title: 'Meet your setup specialist', subtitle: '', message: ({adminsRoomLink, guideCalendarLink}: {adminsRoomLink: string; guideCalendarLink: string}) => @@ -3719,6 +3725,7 @@ const CONST = { }, { type: 'setupCategories', + autoCompleted: false, title: 'Set up categories', subtitle: 'Set up categories so your team can code expenses for easy reporting.', message: @@ -3734,6 +3741,7 @@ const CONST = { }, { type: 'addExpenseApprovals', + autoCompleted: false, title: 'Add expense approvals', subtitle: 'Add expense approvals to review your team’s spend and keep it under control.', message: @@ -3749,6 +3757,7 @@ const CONST = { }, { type: 'inviteTeam', + autoCompleted: false, title: 'Invite your team', subtitle: 'Invite your team to Expensify so they can start tracking expenses today.', message: @@ -3776,6 +3785,7 @@ const CONST = { tasks: [ { type: 'trackExpense', + autoCompleted: false, title: 'Track an expense', subtitle: 'Track an expense in any currency, whether you have a receipt or not.', message: @@ -3802,6 +3812,7 @@ const CONST = { tasks: [ { type: 'startChat', + autoCompleted: false, title: 'Start a chat', subtitle: 'Start a chat with a friend or group using their email or phone number.', message: @@ -3817,6 +3828,7 @@ const CONST = { }, { type: 'splitExpense', + autoCompleted: false, title: 'Split an expense', subtitle: 'Split an expense right in your chat with one or more friends.', message: @@ -3831,6 +3843,7 @@ const CONST = { }, { type: 'enableWallet', + autoCompleted: false, title: 'Enable your wallet', subtitle: 'You’ll need to enable your Expensify Wallet to get paid back. Don’t worry, it’s easy!', message: diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 19c031966d8a..e759e6fbe1d9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3919,7 +3919,13 @@ function updateReportPreview(iouReport: OnyxEntry, reportPreviewAction: }; } -function buildOptimisticTaskReportAction(taskReportID: string, actionName: OriginalMessageActionName, message = ''): OptimisticTaskReportAction { +function buildOptimisticTaskReportAction( + taskReportID: string, + actionName: OriginalMessageActionName, + message = '', + actorAccountID = currentUserAccountID, + createdOffset = 0, +): OptimisticTaskReportAction { const originalMessage = { taskReportID, type: actionName, @@ -3927,7 +3933,7 @@ function buildOptimisticTaskReportAction(taskReportID: string, actionName: Origi }; return { actionName, - actorAccountID: currentUserAccountID, + actorAccountID, automatic: false, avatar: getCurrentUserAvatarOrDefault(), isAttachment: false, @@ -3948,7 +3954,7 @@ function buildOptimisticTaskReportAction(taskReportID: string, actionName: Origi ], reportActionID: NumberUtils.rand64(), shouldShow: true, - created: DateUtils.getDBTime(), + created: DateUtils.getDBTimeWithSkew(Date.now() + createdOffset), isFirstItem: false, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 47655cfe9f55..f8bc1e0e4979 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -128,7 +128,7 @@ type TaskForParameters = parentReportActionID: string; assigneeChatReportID: string; createdTaskReportActionID: string; - completedTaskReportActionID: string; + completedTaskReportActionID?: string; title: string; description: string; } @@ -3065,7 +3065,9 @@ function completeOnboarding( }) : task.message; const instructionComment = ReportUtils.buildOptimisticAddCommentReportAction(taskMessage, undefined, actorAccountID, 1, isTaskMessageFunction ? undefined : false); - const completedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete'); + const completedTaskReportAction = task.autoCompleted + ? ReportUtils.buildOptimisticTaskReportAction(currentTask.reportID, CONST.REPORT.ACTIONS.TYPE.TASK_COMPLETED, 'marked as complete', actorAccountID, 2) + : null; return { task, @@ -3098,7 +3100,7 @@ function completeOnboarding( parentReportActionID: taskReportAction.reportAction.reportActionID, assigneeChatReportID: '', createdTaskReportActionID: taskCreatedAction.reportActionID, - completedTaskReportActionID: completedTaskReportAction.reportActionID, + completedTaskReportActionID: completedTaskReportAction?.reportActionID ?? undefined, title: currentTask.reportName ?? '', description: currentTask.description ?? '', }, @@ -3146,8 +3148,6 @@ function completeOnboarding( key: `${ONYXKEYS.COLLECTION.REPORT}${currentTask.reportID}`, value: { ...currentTask, - stateNum: CONST.REPORT.STATE_NUM.APPROVED, - statusNum: CONST.REPORT.STATUS_NUM.APPROVED, pendingFields: { createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, @@ -3163,7 +3163,6 @@ function completeOnboarding( value: { [taskCreatedAction.reportActionID]: taskCreatedAction as ReportAction, [instructionCommentAction.reportActionID]: instructionCommentAction as ReportAction, - [completedTaskReportAction.reportActionID]: completedTaskReportAction as ReportAction, }, }, ]; @@ -3180,6 +3179,25 @@ function completeOnboarding( }); } + if (completedTaskReportAction) { + tasksForOptimisticDataAcc.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, + value: { + [completedTaskReportAction.reportActionID]: completedTaskReportAction as ReportAction, + }, + }); + + tasksForOptimisticDataAcc.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${currentTask.reportID}`, + value: { + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + }, + }); + } + return tasksForOptimisticDataAcc; }, [],