diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 6a62a389f85e..0cbbedf1fbe3 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -652,12 +652,16 @@ function setAssigneeChatReport(chatReport: OnyxTypes.Report) { * If there is no existing chat, it creates an optimistic chat report * It also sets the shareDestination as that chat report if a share destination isn't already set */ -function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareToReportID: string, isCurrentUser = false): OnyxEntry { +function setAssigneeValue(assigneeEmail: string, assigneeAccountID: number, shareToReportID: string, isCurrentUser = false, report: OnyxEntry): OnyxEntry { let chatReport: OnyxEntry = null; if (!isCurrentUser) { - const reportID = shareToReportID; - chatReport = ReportUtils.getChatByReportID(reportID); + if(report) { + chatReport = report; + } + else { + chatReport = ReportUtils.getChatByParticipants([assigneeAccountID]); + } if (!chatReport) { chatReport = ReportUtils.buildOptimisticChatReport([assigneeAccountID]); chatReport.isOptimisticReport = true; @@ -710,14 +714,14 @@ function setParentReportID(parentReportID: string) { /** * Clears out the task info from the store and navigates to the NewTaskDetails page */ -function clearOutTaskInfoAndNavigate(reportID: string, accountID = 0) { +function clearOutTaskInfoAndNavigate(reportID: string, accountID = 0, report: OnyxEntry) { clearOutTaskInfo(); if (reportID && reportID !== '0') { setParentReportID(reportID); } if (accountID > 0) { const accountLogin = allPersonalDetails?.[accountID]?.login ?? ''; - setAssigneeValue(accountLogin, accountID, reportID); + setAssigneeValue(accountLogin, accountID, reportID, false, report); } Navigation.navigate(ROUTES.NEW_TASK_DETAILS); } diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 4bef463a3c55..46ff636d2561 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -162,7 +162,7 @@ function AttachmentPickerWithMenuItems({ { icon: Expensicons.Task, text: translate('newTaskPage.assignTask'), - onSelected: () => Task.clearOutTaskInfoAndNavigate(reportID), + onSelected: () => Task.clearOutTaskInfoAndNavigate(reportID, 0, report), }, ]; }, [report, reportID, translate]); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 24603de5679c..b3729e0bd7a4 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -178,7 +178,7 @@ function FloatingActionButtonAndPopover(props) { IOU.startMoneyRequest(CONST.IOU.TYPE.SEND, props.quickAction.chatReportID); return; case CONST.QUICK_ACTIONS.ASSIGN_TASK: - Task.clearOutTaskInfoAndNavigate(props.quickAction.chatReportID, _.get(props.quickAction, 'targetAccountID', 0)); + Task.clearOutTaskInfoAndNavigate(props.quickAction.chatReportID, _.get(props.quickAction, 'targetAccountID', 0), quickActionReport); return; default: return ''; diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 0ffb33b7590b..82ca515d95f6 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -181,6 +181,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro option?.accountID ?? -1, report.reportID, OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? ''}), + report, ); // Pass through the selected assignee @@ -194,6 +195,7 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro option.accountID, task?.shareDestination ?? '', OptionsListUtils.isCurrentUser({...option, accountID: option?.accountID ?? -1, login: option?.login ?? undefined}), + report, ); Navigation.goBack(ROUTES.NEW_TASK); }