diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index a4fc61910be2..1a526a9cdd9b 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -184,29 +184,29 @@ function TaskAssigneeSelectorModal(props) { return sectionsList; }, [filteredCurrentUserOption, filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, props]); - const selectReport = (option) => { - if (!option) { - return; - } - - // Check to see if we're creating a new task - // If there's no route params, we're creating a new task - if (!props.route.params && option.accountID) { - Task.setAssigneeValue(option.login, option.accountID, props.task.shareDestination, OptionsListUtils.isCurrentUser(option)); - return Navigation.goBack(ROUTES.NEW_TASK); - } - - // Check to see if we're editing a task and if so, update the assignee - if (report) { - if (option.accountID !== report.managerID) { - const assigneeChatReport = Task.setAssigneeValue(option.login, option.accountID, props.route.params.reportID, OptionsListUtils.isCurrentUser(option)); + const selectReport = useCallback( + (option) => { + if (!option) { + return; + } - // Pass through the selected assignee - Task.editTaskAssignee(report, props.session.accountID, option.login, option.accountID, assigneeChatReport); + // Check to see if we're editing a task and if so, update the assignee + if (report) { + if (option.accountID !== report.managerID) { + const assigneeChatReport = Task.setAssigneeValue(option.login, option.accountID, report.reportID, OptionsListUtils.isCurrentUser(option)); + + // Pass through the selected assignee + Task.editTaskAssignee(report, props.session.accountID, option.login, option.accountID, assigneeChatReport); + } + Navigation.dismissModal(report.reportID); + // If there's no report, we're creating a new task + } else if (option.accountID) { + Task.setAssigneeValue(option.login, option.accountID, props.task.shareDestination, OptionsListUtils.isCurrentUser(option)); + Navigation.goBack(ROUTES.NEW_TASK); } - return Navigation.dismissModal(report.reportID); - } - }; + }, + [props.session.accountID, props.task.shareDestination, report], + ); const isOpen = ReportUtils.isOpenTaskReport(report); const canModifyTask = Task.canModifyTask(report, props.currentUserPersonalDetails.accountID, lodashGet(props.rootParentReportPolicy, 'role', ''));