Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto assign when create a task in a DM #20501

Merged
merged 14 commits into from
Jun 13, 2023
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 @@ -85,6 +85,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