Skip to content

Commit 92499de

Browse files
committed
Start using EditTaskAssignee
1 parent ed690eb commit 92499de

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

src/libs/actions/Task.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,83 @@ function editTaskAndNavigate(report, ownerAccountID, {title, description, assign
440440
Navigation.dismissModal(report.reportID);
441441
}
442442

443+
function editTaskAssigneeAndNavigate(report, ownerAccountID, assigneeEmail, assigneeAccountID = 0, assigneeChatReport = null) {
444+
// Create the EditedReportAction on the task
445+
const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskReportAction(currentUserEmail);
446+
const reportName = report.reportName.trim();
447+
448+
let assigneeChatReportOnyxData;
449+
const assigneeChatReportID = assigneeChatReport ? assigneeChatReport.reportID : 0;
450+
451+
const optimisticData = [
452+
{
453+
onyxMethod: Onyx.METHOD.MERGE,
454+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
455+
value: {[editTaskReportAction.reportActionID]: editTaskReportAction},
456+
},
457+
{
458+
onyxMethod: Onyx.METHOD.MERGE,
459+
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
460+
value: {
461+
reportName,
462+
managerID: assigneeAccountID || report.managerID,
463+
managerEmail: assigneeEmail || report.managerEmail,
464+
},
465+
},
466+
];
467+
const successData = [];
468+
const failureData = [
469+
{
470+
onyxMethod: Onyx.METHOD.MERGE,
471+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
472+
value: {[editTaskReportAction.reportActionID]: {pendingAction: null}},
473+
},
474+
{
475+
onyxMethod: Onyx.METHOD.MERGE,
476+
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
477+
value: {assignee: report.managerEmail, assigneeAccountID: report.managerID},
478+
},
479+
];
480+
481+
// If we make a change to the assignee, we want to add a comment to the assignee's chat
482+
// Check if the assignee actually changed
483+
if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport) {
484+
assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData(
485+
currentUserAccountID,
486+
assigneeEmail,
487+
assigneeAccountID,
488+
report.reportID,
489+
assigneeChatReportID,
490+
report.parentReportID,
491+
reportName,
492+
assigneeChatReport,
493+
);
494+
optimisticData.push(...assigneeChatReportOnyxData.optimisticData);
495+
successData.push(...assigneeChatReportOnyxData.successData);
496+
failureData.push(...assigneeChatReportOnyxData.failureData);
497+
}
498+
499+
API.write(
500+
'EditTaskAssignee',
501+
{
502+
taskReportID: report.reportID,
503+
assignee: assigneeEmail || report.managerEmail,
504+
assigneeAccountID: assigneeAccountID || report.managerID,
505+
editedTaskReportActionID: editTaskReportAction.reportActionID,
506+
assigneeChatReportID,
507+
assigneeChatReportActionID:
508+
assigneeChatReportOnyxData && assigneeChatReportOnyxData.optimisticAssigneeAddComment
509+
? assigneeChatReportOnyxData.optimisticAssigneeAddComment.reportAction.reportActionID
510+
: 0,
511+
assigneeChatCreatedReportActionID:
512+
assigneeChatReportOnyxData && assigneeChatReportOnyxData.optimisticChatCreatedReportAction ? assigneeChatReportOnyxData.optimisticChatCreatedReportAction.reportActionID : 0,
513+
},
514+
{optimisticData, successData, failureData},
515+
);
516+
517+
Navigation.dismissModal(report.reportID);
518+
}
519+
443520
/**
444521
* Sets the report info for the task being viewed
445522
*
@@ -739,6 +816,7 @@ function canModifyTask(taskReport, sessionAccountID) {
739816
export {
740817
createTaskAndNavigate,
741818
editTaskAndNavigate,
819+
editTaskAssigneeAndNavigate,
742820
setTitleValue,
743821
setDescriptionValue,
744822
setTaskReport,

src/pages/tasks/TaskAssigneeSelectorModal.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@ function TaskAssigneeSelectorModal(props) {
170170
const assigneeChatReport = Task.setAssigneeValue(option.login, option.accountID, props.task.shareDestination, OptionsListUtils.isCurrentUser(option));
171171

172172
// Pass through the selected assignee
173-
Task.editTaskAndNavigate(
173+
Task.editTaskAssigneeAndNavigate(
174174
props.task.report,
175175
props.session.accountID,
176-
{
177-
assignee: option.login,
178-
assigneeAccountID: option.accountID,
179-
},
176+
option.login,
177+
option.accountID,
180178
assigneeChatReport,
181-
);
179+
)
182180
}
183181
};
184182

0 commit comments

Comments
 (0)