diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.js b/src/pages/tasks/TaskAssigneeSelectorModal.js index 7c98fcdc9343..14d2867aa1f4 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.js +++ b/src/pages/tasks/TaskAssigneeSelectorModal.js @@ -1,11 +1,11 @@ /* eslint-disable es/no-optional-chaining */ import {useRoute} from '@react-navigation/native'; import lodashGet from 'lodash/get'; +import lodashPick from 'lodash/pick'; import PropTypes from 'prop-types'; import React, {useCallback, useMemo, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import {useBetas, usePersonalDetails, useSession} from '@components/OnyxProvider'; @@ -110,15 +110,14 @@ function TaskAssigneeSelectorModal({reports, task, rootParentReportPolicy}) { if (!route.params || !route.params.reportID) { return null; } + if (report && !ReportUtils.isTaskReport(report)) { + Navigation.isNavigationReady().then(() => { + Navigation.dismissModal(report.reportID); + }); + } return reports[`${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`]; }, [reports, route]); - if (report && !ReportUtils.isTaskReport(report)) { - Navigation.isNavigationReady().then(() => { - Navigation.dismissModal(report.reportID); - }); - } - const sections = useMemo(() => { const sectionsList = []; let indexOffset = 0; @@ -184,6 +183,8 @@ function TaskAssigneeSelectorModal({reports, task, rootParentReportPolicy}) { [session.accountID, task.shareDestination, report], ); + const handleBackButtonPress = useCallback(() => (lodashGet(route.params, 'reportID') ? Navigation.dismissModal() : Navigation.goBack(ROUTES.NEW_TASK)), [route.params]); + const isOpen = ReportUtils.isOpenTaskReport(report); const canModifyTask = Task.canModifyTask(report, currentUserPersonalDetails.accountID, lodashGet(rootParentReportPolicy, 'role', '')); const isTaskNonEditable = ReportUtils.isTaskReport(report) && (!canModifyTask || !isOpen); @@ -197,20 +198,18 @@ function TaskAssigneeSelectorModal({reports, task, rootParentReportPolicy}) { (lodashGet(route.params, 'reportID') ? Navigation.dismissModal() : Navigation.goBack(ROUTES.NEW_TASK))} + onBackButtonPress={handleBackButtonPress} /> @@ -222,7 +221,6 @@ function TaskAssigneeSelectorModal({reports, task, rootParentReportPolicy}) { TaskAssigneeSelectorModal.displayName = 'TaskAssigneeSelectorModal'; TaskAssigneeSelectorModal.propTypes = propTypes; TaskAssigneeSelectorModal.defaultProps = defaultProps; -TaskAssigneeSelectorModal.whyDidYouRender = true; export default compose( withOnyx({ @@ -240,7 +238,7 @@ export default compose( const rootParentReport = ReportUtils.getRootParentReport(report); return `${ONYXKEYS.COLLECTION.POLICY}${rootParentReport ? rootParentReport.policyID : '0'}`; }, - selector: (policy) => _.pick(policy, ['role']), + selector: (policy) => lodashPick(policy, ['role']), }, }), )(TaskAssigneeSelectorModal);