Skip to content

Commit 93957f0

Browse files
authored
Merge pull request #20501 from dukenv0307/fix/19048
Auto assign when create a task in a DM
2 parents ebe28b8 + 6d4d4ef commit 93957f0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/libs/actions/Task.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,23 @@ function setShareDestinationValue(shareDestination) {
424424
Onyx.merge(ONYXKEYS.TASK, {shareDestination});
425425
}
426426

427+
/**
428+
* Auto-assign participant when creating a task in a DM
429+
* @param {String} reportID
430+
*/
431+
432+
function setAssigneeValueWithParentReportID(reportID) {
433+
const report = ReportUtils.getReport(reportID);
434+
const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report));
435+
const participants = lodashGet(report, 'participants', []);
436+
const hasMultipleParticipants = participants.length > 1;
437+
if (!isDefault || hasMultipleParticipants || report.parentReportID) {
438+
return;
439+
}
440+
441+
Onyx.merge(ONYXKEYS.TASK, {assignee: participants[0]});
442+
}
443+
427444
/**
428445
* Sets the assignee value for the task and checks for an existing chat with the assignee
429446
* If there is no existing chat, it creates an optimistic chat report
@@ -591,6 +608,7 @@ export {
591608
setTaskReport,
592609
setDetailsValue,
593610
setAssigneeValue,
611+
setAssigneeValueWithParentReportID,
594612
setShareDestinationValue,
595613
clearOutTaskInfo,
596614
reopenTask,

src/pages/tasks/NewTaskPage.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ const NewTaskPage = (props) => {
8686
setAssignee(displayDetails);
8787
}
8888

89+
// If we don't have an assignee and we are creating a task from a report
90+
// this allows us to auto assign a participant of the report.
91+
if (!props.task.assignee && props.task.parentReportID) {
92+
TaskUtils.setAssigneeValueWithParentReportID(props.task.parentReportID);
93+
}
94+
8995
// We only set the parentReportID if we are creating a task from a report
9096
// this allows us to go ahead and set that report as the share destination
9197
// and disable the share destination selector

0 commit comments

Comments
 (0)