Skip to content

Commit

Permalink
update optimistic data for parent report action when completing or re…
Browse files Browse the repository at this point in the history
…opening task
  • Loading branch information
dukenv0307 committed Jul 17, 2023
1 parent 25c8ae5 commit 03f4a3e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ function completeTask(taskReportID, taskTitle) {
},
];

// Optimistically update the parent report action
const report = ReportUtils.getReport(taskReportID);
if (report && report.parentReportActionID) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (parentReportAction && parentReportAction.reportActionID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
value: {
[parentReportAction.reportActionID]: ReportUtils.updateOptimisticParentReportAction(
parentReportAction,
completedTaskReportAction.created,
CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
),
},
});
}
}

API.write(
'CompleteTask',
{
Expand Down Expand Up @@ -314,6 +333,25 @@ function reopenTask(taskReportID, taskTitle) {
},
];

// Optimistically update the parent report action
const report = ReportUtils.getReport(taskReportID);
if (report && report.parentReportActionID) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
if (parentReportAction && parentReportAction.reportActionID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
value: {
[parentReportAction.reportActionID]: ReportUtils.updateOptimisticParentReportAction(
parentReportAction,
reopenedTaskReportAction.created,
CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
),
},
});
}
}

API.write(
'ReopenTask',
{
Expand Down

0 comments on commit 03f4a3e

Please sign in to comment.