Skip to content

Commit

Permalink
Revert "complete tasks"
Browse files Browse the repository at this point in the history
This reverts commit 3ec3c82.
  • Loading branch information
rezkiy37 committed Apr 19, 2024
1 parent 3ec3c82 commit 8cfbe4c
Showing 1 changed file with 83 additions and 96 deletions.
179 changes: 83 additions & 96 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ type TaskForParameters =
parentReportActionID: string;
assigneeChatReportID: string;
createdTaskReportActionID: string;
completedTaskReportActionID: string;
title: string;
description: string;
}
Expand Down Expand Up @@ -3065,7 +3064,6 @@ 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,
Expand All @@ -3074,116 +3072,105 @@ function completeOnboarding(
taskReportAction,
subtitleComment,
instructionComment,
completedTaskReportAction,
};
});

const tasksForParameters = tasksData.reduce<TaskForParameters[]>(
(acc, {task, currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment, completedTaskReportAction}) => {
const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction;
const instructionCommentText = instructionComment.commentText;
const instructionMessage: TaskMessage = {
const tasksForParameters = tasksData.reduce<TaskForParameters[]>((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 = {
reportID: currentTask.reportID,
reportActionID: instructionCommentAction.reportActionID,
reportComment: instructionCommentText,
reportActionID: subtitleCommentAction.reportActionID,
reportComment: subtitleCommentText,
};

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,
});
}
tasksForParametersAcc.push({
type: 'message',
...subtitleMessage,
});
}

return tasksForParametersAcc;
},
[],
);
return tasksForParametersAcc;
}, []);

const tasksForOptimisticData = tasksData.reduce<OnyxUpdate[]>(
(acc, {currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment, completedTaskReportAction}) => {
const instructionCommentAction: OptimisticAddCommentReportAction = instructionComment.reportAction;
const tasksForOptimisticData = tasksData.reduce<OnyxUpdate[]>((acc, {currentTask, taskCreatedAction, taskReportAction, subtitleComment, instructionComment}) => {
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,
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,
},
{
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,
},
isOptimisticReport: true,
},
{
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,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`,
value: {
[taskCreatedAction.reportActionID]: taskCreatedAction as ReportAction,
[instructionCommentAction.reportActionID]: instructionCommentAction 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,
Expand Down

0 comments on commit 8cfbe4c

Please sign in to comment.