diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 59ea33e0d722..bda8bec4f666 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import lodashGet from 'lodash/get'; import Str from 'expensify-common/lib/str'; +import _ from 'underscore'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; import * as ReportUtils from '../ReportUtils'; @@ -278,19 +279,18 @@ function reopenTask(taskReportID, taskTitle) { * @function editTask * @param {object} report * @param {string} ownerEmail - * @param {string} title - * @param {string} description - * @param {string} assignee + * @param {{title?: string, description?: string, assignee?:string}} editedTask * @returns {object} action * */ -function editTaskAndNavigate(report, ownerEmail, title, description, assignee) { +function editTaskAndNavigate(report, ownerEmail, {title, description, assignee}) { // Create the EditedReportAction on the task const editTaskReportAction = ReportUtils.buildOptimisticEditedTaskReportAction(ownerEmail); - // Sometimes title is undefined, so we need to check for that, and we provide it to multiple functions + // Sometimes title or description is undefined, so we need to check for that, and we provide it to multiple functions const reportName = (title || report.reportName).trim(); + const reportDescription = (!_.isUndefined(description) ? description : report.description).trim(); // If we make a change to the assignee, we want to add a comment to the assignee's chat let optimisticAssigneeAddComment; @@ -313,7 +313,7 @@ function editTaskAndNavigate(report, ownerEmail, title, description, assignee) { key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, value: { reportName, - description: description.trim(), + description: reportDescription, managerEmail: assignee || report.managerEmail, }, }, @@ -368,7 +368,7 @@ function editTaskAndNavigate(report, ownerEmail, title, description, assignee) { { taskReportID: report.reportID, title: reportName, - description: (description || report.description).trim(), + description: reportDescription, assignee: assignee || report.managerEmail, editedTaskReportActionID: editTaskReportAction.reportActionID, assigneeChatReportActionID: optimisticAssigneeAddComment ? optimisticAssigneeAddComment.reportAction.reportActionID : 0, diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index 63a79c6ce1d1..e95f6143f904 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -183,7 +183,7 @@ const TaskAssigneeSelectorModal = (props) => { // This would cause the app to crash, so we need to make sure we have a DM thread TaskUtils.setAssigneeValue(option.login, props.task.shareDestination, OptionsListUtils.isCurrentUser(option)); // Pass through the selected assignee - TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, '', '', option.login); + TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, {assignee: option.login}); } }; diff --git a/src/pages/tasks/TaskDescriptionPage.js b/src/pages/tasks/TaskDescriptionPage.js index 1c894886d291..747d7f44c83f 100644 --- a/src/pages/tasks/TaskDescriptionPage.js +++ b/src/pages/tasks/TaskDescriptionPage.js @@ -41,7 +41,7 @@ function TaskDescriptionPage(props) { (values) => { // Set the description of the report in the store and then call TaskUtils.editTaskReport // to update the description of the report on the server - TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, '', values.description, ''); + TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, {description: values.description}); }, [props], ); diff --git a/src/pages/tasks/TaskTitlePage.js b/src/pages/tasks/TaskTitlePage.js index 333c7135e46b..046294ec95fb 100644 --- a/src/pages/tasks/TaskTitlePage.js +++ b/src/pages/tasks/TaskTitlePage.js @@ -59,7 +59,7 @@ function TaskTitlePage(props) { // Set the description of the report in the store and then call TaskUtils.editTaskReport // to update the description of the report on the server - TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, values.title, '', ''); + TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, {title: values.title}); }, [props], );