Skip to content

Commit

Permalink
Merge pull request #20501 from dukenv0307/fix/19048
Browse files Browse the repository at this point in the history
Auto assign when create a task in a DM
  • Loading branch information
MariaHCD authored Jun 13, 2023
2 parents ebe28b8 + 6d4d4ef commit 93957f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,23 @@ function setShareDestinationValue(shareDestination) {
Onyx.merge(ONYXKEYS.TASK, {shareDestination});
}

/**
* Auto-assign participant when creating a task in a DM
* @param {String} reportID
*/

function setAssigneeValueWithParentReportID(reportID) {
const report = ReportUtils.getReport(reportID);
const isDefault = !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report));
const participants = lodashGet(report, 'participants', []);
const hasMultipleParticipants = participants.length > 1;
if (!isDefault || hasMultipleParticipants || report.parentReportID) {
return;
}

Onyx.merge(ONYXKEYS.TASK, {assignee: participants[0]});
}

/**
* Sets the assignee value for the task and checks for an existing chat with the assignee
* If there is no existing chat, it creates an optimistic chat report
Expand Down Expand Up @@ -591,6 +608,7 @@ export {
setTaskReport,
setDetailsValue,
setAssigneeValue,
setAssigneeValueWithParentReportID,
setShareDestinationValue,
clearOutTaskInfo,
reopenTask,
Expand Down
6 changes: 6 additions & 0 deletions src/pages/tasks/NewTaskPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const NewTaskPage = (props) => {
setAssignee(displayDetails);
}

// If we don't have an assignee and we are creating a task from a report
// this allows us to auto assign a participant of the report.
if (!props.task.assignee && props.task.parentReportID) {
TaskUtils.setAssigneeValueWithParentReportID(props.task.parentReportID);
}

// We only set the parentReportID if we are creating a task from a report
// this allows us to go ahead and set that report as the share destination
// and disable the share destination selector
Expand Down

0 comments on commit 93957f0

Please sign in to comment.