diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 36eabd05cece..595aa0d11a89 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -380,9 +380,9 @@ function editTaskAndNavigate(report, ownerAccountID, {title, description, assign let optimisticAssigneeAddComment; let assigneeChatReportID; if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID) { - assigneeChatReportID = ReportUtils.getChatByParticipants([assigneeAccountID]).reportID; + assigneeChatReportID = lodashGet(ReportUtils.getChatByParticipants([assigneeAccountID]), ['reportID'], undefined); - if (assigneeChatReportID !== report.parentReportID.toString()) { + if (assigneeChatReportID && assigneeChatReportID !== report.parentReportID.toString()) { optimisticAssigneeAddComment = ReportUtils.buildOptimisticTaskCommentReportAction( report.reportID, reportName, diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index 86b3bca47c8c..784c4c1a14df 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -1,10 +1,10 @@ /* eslint-disable es/no-optional-chaining */ import React, {useState, useEffect, useMemo, useCallback} from 'react'; import {View} from 'react-native'; +import lodashGet from 'lodash/get'; import _ from 'underscore'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; -import lodashGet from 'lodash/get'; import OptionsSelector from '../../components/OptionsSelector'; import * as OptionsListUtils from '../../libs/OptionsListUtils'; import ONYXKEYS from '../../ONYXKEYS'; @@ -108,6 +108,13 @@ function TaskAssigneeSelectorModal(props) { setSearchValue(newSearchTerm); }; + const report = useMemo(() => { + if (!props.route.params || !props.route.params.reportID) { + return null; + } + return props.reports[`${ONYXKEYS.COLLECTION.REPORT}${props.route.params.reportID}`]; + }, [props.reports, props.route.params]); + const sections = useMemo(() => { const sectionsList = []; let indexOffset = 0; @@ -164,13 +171,13 @@ function TaskAssigneeSelectorModal(props) { } // Check to see if we're editing a task and if so, update the assignee - if (props.route.params.reportID && props.task.report.reportID === props.route.params.reportID) { + if (report) { // There was an issue where sometimes a new assignee didn't have a DM thread // This would cause the app to crash, so we need to make sure we have a DM thread - Task.setAssigneeValue(option.login, option.accountID, props.task.shareDestination, OptionsListUtils.isCurrentUser(option)); + Task.setAssigneeValue(option.login, option.accountID, props.route.params.reportID, OptionsListUtils.isCurrentUser(option)); // Pass through the selected assignee - Task.editTaskAndNavigate(props.task.report, props.session.accountID, { + Task.editTaskAndNavigate(report, props.session.accountID, { assignee: option.login, assigneeAccountID: option.accountID, });