From 4e5a21b697bae8082b56a0c5ff2c4d2433b4e7c9 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 19 Apr 2024 15:21:42 +0200 Subject: [PATCH] Reapply "complete tasks" This reverts commit 8cfbe4cf861c2ab5bd4bb37b44d598c4e245a080. --- src/libs/actions/Report.ts | 179 ++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 83 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 5f7ed3d36d0d..47655cfe9f55 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -128,6 +128,7 @@ type TaskForParameters = parentReportActionID: string; assigneeChatReportID: string; createdTaskReportActionID: string; + completedTaskReportActionID: string; title: string; description: string; } @@ -3064,6 +3065,7 @@ 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'); return { task, @@ -3072,105 +3074,116 @@ function completeOnboarding( taskReportAction, subtitleComment, instructionComment, + completedTaskReportAction, }; }); - const tasksForParameters = tasksData.reduce((acc, {task, currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment}) => { - const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; - const instructionCommentText = instructionComment.commentText; - const instructionMessage: TaskMessage = { - reportID: currentTask.reportID, - reportActionID: instructionCommentAction.reportActionID, - reportComment: instructionCommentText, - }; - - const tasksForParametersAcc: TaskForParameters[] = [ - ...acc, - { - type: 'task', - task: task.type, - taskReportID: currentTask.reportID, - parentReportID: currentTask.parentReportID ?? '', - parentReportActionID: taskReportAction.reportAction.reportActionID, - assigneeChatReportID: '', - createdTaskReportActionID: taskCreatedAction.reportActionID, - title: currentTask.reportName ?? '', - description: currentTask.description ?? '', - }, - { - type: 'message', - ...instructionMessage, - }, - ]; - - if (subtitleComment) { - const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; - const subtitleCommentText = subtitleComment.commentText; - const subtitleMessage: TaskMessage = { + const tasksForParameters = tasksData.reduce( + (acc, {task, currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment, completedTaskReportAction}) => { + const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; + const instructionCommentText = instructionComment.commentText; + const instructionMessage: TaskMessage = { reportID: currentTask.reportID, - reportActionID: subtitleCommentAction.reportActionID, - reportComment: subtitleCommentText, + reportActionID: instructionCommentAction.reportActionID, + reportComment: instructionCommentText, }; - tasksForParametersAcc.push({ - type: 'message', - ...subtitleMessage, - }); - } + const tasksForParametersAcc: TaskForParameters[] = [ + ...acc, + { + type: 'task', + task: task.type, + taskReportID: currentTask.reportID, + parentReportID: currentTask.parentReportID ?? '', + parentReportActionID: taskReportAction.reportAction.reportActionID, + assigneeChatReportID: '', + createdTaskReportActionID: taskCreatedAction.reportActionID, + completedTaskReportActionID: completedTaskReportAction.reportActionID, + title: currentTask.reportName ?? '', + description: currentTask.description ?? '', + }, + { + type: 'message', + ...instructionMessage, + }, + ]; + + if (subtitleComment) { + const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; + const subtitleCommentText = subtitleComment.commentText; + const subtitleMessage: TaskMessage = { + reportID: currentTask.reportID, + reportActionID: subtitleCommentAction.reportActionID, + reportComment: subtitleCommentText, + }; + + tasksForParametersAcc.push({ + type: 'message', + ...subtitleMessage, + }); + } - return tasksForParametersAcc; - }, []); + return tasksForParametersAcc; + }, + [], + ); - const tasksForOptimisticData = tasksData.reduce((acc, {currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment}) => { - const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; + const tasksForOptimisticData = tasksData.reduce( + (acc, {currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment, completedTaskReportAction}) => { + const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction; - const tasksForOptimisticDataAcc: OnyxUpdate[] = [ - ...acc, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, - value: { - [taskReportAction.reportAction.reportActionID]: taskReportAction.reportAction as ReportAction, + const tasksForOptimisticDataAcc: OnyxUpdate[] = [ + ...acc, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [taskReportAction.reportAction.reportActionID]: taskReportAction.reportAction as ReportAction, + }, }, - }, - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${currentTask.reportID}`, - value: { - ...currentTask, - pendingFields: { - createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - reportName: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - description: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + { + onyxMethod: Onyx.METHOD.SET, + 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, + description: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + managerID: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + isOptimisticReport: true, }, - isOptimisticReport: true, }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, - value: { - [taskCreatedAction.reportActionID]: taskCreatedAction as ReportAction, - [instructionCommentAction.reportActionID]: instructionCommentAction as ReportAction, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, + value: { + [taskCreatedAction.reportActionID]: taskCreatedAction as ReportAction, + [instructionCommentAction.reportActionID]: instructionCommentAction as ReportAction, + [completedTaskReportAction.reportActionID]: completedTaskReportAction as ReportAction, + }, }, - }, - ]; + ]; - if (subtitleComment) { - const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; + if (subtitleComment) { + const subtitleCommentAction: OptimisticAddCommentReportAction = subtitleComment.reportAction; - tasksForOptimisticDataAcc.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, - value: { - [subtitleCommentAction.reportActionID]: subtitleCommentAction as ReportAction, - }, - }); - } + tasksForOptimisticDataAcc.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, + value: { + [subtitleCommentAction.reportActionID]: subtitleCommentAction as ReportAction, + }, + }); + } - return tasksForOptimisticDataAcc; - }, []); + return tasksForOptimisticDataAcc; + }, + [], + ); const optimisticData: OnyxUpdate[] = [ ...tasksForOptimisticData,