diff --git a/src/languages/en.js b/src/languages/en.js index 1e6d17c7cc85..1c23684cd2fb 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -1239,6 +1239,7 @@ export default { assignTask: 'Assign task', assignee: 'Assignee', assigneeError: 'There was an error assigning this task, please try another assignee', + assignMe: 'Assign to me', confirmTask: 'Confirm task', confirmError: 'Please enter a title and select a share destination', title: 'Title', diff --git a/src/languages/es.js b/src/languages/es.js index 6035919e0dfb..1bc20e39c5bd 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -1245,6 +1245,7 @@ export default { assignTask: 'Asignar tarea', assignee: 'Cesionario', assigneeError: 'Hubo un error al asignar esta tarea, intente con otro cesionario', + assignMe: 'Asignar a mí mismo', confirmTask: 'Confirmar tarea', confirmError: 'Por favor introduce un título y selecciona un destino de tarea', title: 'Título', diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0b3c4bd35b51..9d9185411aca 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -558,6 +558,7 @@ function getOptions( recentReports: [], personalDetails: [], userToInvite: null, + currentUserOption: null, }; } @@ -699,8 +700,13 @@ function getOptions( }); } + let currentUserOption = _.find(allPersonalDetailsOptions, (personalDetailsOption) => personalDetailsOption.login === currentUserLogin); + if (searchValue && !isSearchStringMatch(searchValue, currentUserOption.searchText)) { + currentUserOption = null; + } + let userToInvite = null; - const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0; + const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption; const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => option.login === searchValue.toLowerCase()); if ( @@ -757,6 +763,7 @@ function getOptions( personalDetails: personalDetailsOptions, recentReports: recentReportOptions, userToInvite, + currentUserOption, }; } diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 0de8dd3bb30c..729f80e7e18b 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -424,21 +424,24 @@ function setShareDestinationValue(shareDestination) { * It also sets the shareDestination as that chat report if a share destination isn't already set * @param {string} assignee * @param {string} shareDestination + * @param {boolean} isCurrentUser */ -function setAssigneeValue(assignee, shareDestination) { - let newChat = {}; - const chat = ReportUtils.getChatByParticipants([assignee]); - if (!chat) { - newChat = ReportUtils.buildOptimisticChatReport([assignee]); - } - const reportID = chat ? chat.reportID : newChat.reportID; +function setAssigneeValue(assignee, shareDestination, isCurrentUser = false) { + if (!isCurrentUser) { + let newChat = {}; + const chat = ReportUtils.getChatByParticipants([assignee]); + if (!chat) { + newChat = ReportUtils.buildOptimisticChatReport([assignee]); + } + const reportID = chat ? chat.reportID : newChat.reportID; - if (!shareDestination) { - setShareDestinationValue(reportID); - } + if (!shareDestination) { + setShareDestinationValue(reportID); + } - Report.openReport(reportID, [assignee], newChat); + Report.openReport(reportID, [assignee], newChat); + } // This is only needed for creation of a new task and so it should only be stored locally Onyx.merge(ONYXKEYS.TASK, {assignee}); diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index 4b1abb489093..4e8cdd952402 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -74,6 +74,7 @@ const TaskAssigneeSelectorModal = (props) => { const [filteredRecentReports, setFilteredRecentReports] = useState([]); const [filteredPersonalDetails, setFilteredPersonalDetails] = useState([]); const [filteredUserToInvite, setFilteredUserToInvite] = useState(null); + const [filteredCurrentUserOption, setFilteredCurrentUserOption] = useState(null); useEffect(() => { const results = OptionsListUtils.getNewChatOptions(props.reports, props.personalDetails, props.betas, '', [], CONST.EXPENSIFY_EMAILS, false); @@ -81,10 +82,11 @@ const TaskAssigneeSelectorModal = (props) => { setFilteredRecentReports(results.recentReports); setFilteredPersonalDetails(results.personalDetails); setFilteredUserToInvite(results.userToInvite); + setFilteredCurrentUserOption(results.currentUserOption); }, [props]); const updateOptions = useCallback(() => { - const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getNewChatOptions( + const {recentReports, personalDetails, userToInvite, currentUserOption} = OptionsListUtils.getNewChatOptions( props.reports, props.personalDetails, props.betas, @@ -94,11 +96,12 @@ const TaskAssigneeSelectorModal = (props) => { false, ); - setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0, Boolean(userToInvite), searchValue)); + setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue)); setFilteredUserToInvite(userToInvite); setFilteredRecentReports(recentReports); setFilteredPersonalDetails(personalDetails); + setFilteredCurrentUserOption(currentUserOption); }, [props, searchValue]); useEffect(() => { @@ -122,6 +125,16 @@ const TaskAssigneeSelectorModal = (props) => { const sectionsList = []; let indexOffset = 0; + if (filteredCurrentUserOption) { + sectionsList.push({ + title: props.translate('newTaskPage.assignMe'), + data: [filteredCurrentUserOption], + shouldShow: true, + indexOffset, + }); + indexOffset += 1; + } + sectionsList.push({ title: props.translate('common.recents'), data: filteredRecentReports, @@ -136,18 +149,18 @@ const TaskAssigneeSelectorModal = (props) => { shouldShow: filteredPersonalDetails?.length > 0, indexOffset, }); - indexOffset += filteredRecentReports?.length; + indexOffset += filteredPersonalDetails?.length; if (filteredUserToInvite) { sectionsList.push({ data: [filteredUserToInvite], - shouldShow: filteredUserToInvite?.length > 0, + shouldShow: true, indexOffset, }); } return sectionsList; - }, [filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, props]); + }, [filteredCurrentUserOption, filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, props]); const selectReport = (option) => { if (!option) { @@ -159,7 +172,7 @@ const TaskAssigneeSelectorModal = (props) => { if (!props.route.params && option.login) { // Clear out the state value, set the assignee and navigate back to the NewTaskPage setSearchValue(''); - TaskUtils.setAssigneeValue(option.login, props.task.shareDestination); + TaskUtils.setAssigneeValue(option.login, props.task.shareDestination, OptionsListUtils.isCurrentUser(option)); return Navigation.goBack(); } @@ -167,7 +180,7 @@ const TaskAssigneeSelectorModal = (props) => { if (props.route.params.reportID && props.task.report.reportID === props.route.params.reportID) { // 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 - TaskUtils.setAssigneeValue(option.login, props.task.shareDestination); + 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); }