diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 8884a69debaa..05ef1758b66b 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -3,8 +3,8 @@ import type {RouteProp} from '@react-navigation/native'; import {useRoute} from '@react-navigation/native'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {InteractionManager, View} from 'react-native'; -import {useOnyx, withOnyx} from 'react-native-onyx'; -import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import {useBetas, useSession} from '@components/OnyxProvider'; @@ -14,9 +14,7 @@ import SelectionList from '@components/SelectionList'; import type {ListItem} from '@components/SelectionList/types'; import UserListItem from '@components/SelectionList/UserListItem'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; -import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import withNavigationTransitionEnd from '@components/withNavigationTransitionEnd'; -import type {WithNavigationTransitionEndProps} from '@components/withNavigationTransitionEnd'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; @@ -33,17 +31,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Report, Task} from '@src/types/onyx'; - -type TaskAssigneeSelectorModalOnyxProps = { - /** All reports shared with the user */ - reports: OnyxCollection; - - /** Grab the Share destination of the Task */ - task: OnyxEntry; -}; - -type TaskAssigneeSelectorModalProps = TaskAssigneeSelectorModalOnyxProps & WithCurrentUserPersonalDetailsProps & WithNavigationTransitionEndProps; +import type {Report} from '@src/types/onyx'; function useOptions() { const betas = useBetas(); @@ -111,11 +99,13 @@ function useOptions() { return {...options, searchValue, debouncedSearchValue, setSearchValue, areOptionsInitialized}; } -function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalProps) { +function TaskAssigneeSelectorModal() { const styles = useThemeStyles(); const route = useRoute>(); const {translate} = useLocalize(); const session = useSession(); + const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); + const [task] = useOnyx(ONYXKEYS.TASK); const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const {userToInvite, recentReports, personalDetails, currentUserOption, searchValue, debouncedSearchValue, setSearchValue, headerMessage, areOptionsInitialized} = useOptions(); @@ -124,9 +114,10 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro if (!route.params?.reportID) { return; } - if (report && !ReportUtils.isTaskReport(report)) { + const reportOnyx = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`]; + if (reportOnyx && !ReportUtils.isTaskReport(reportOnyx)) { Navigation.isNavigationReady().then(() => { - Navigation.dismissModal(report.reportID); + Navigation.dismissModal(reportOnyx.reportID); }); } return reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`]; @@ -258,13 +249,4 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro TaskAssigneeSelectorModal.displayName = 'TaskAssigneeSelectorModal'; -const TaskAssigneeSelectorModalWithOnyx = withOnyx({ - reports: { - key: ONYXKEYS.COLLECTION.REPORT, - }, - task: { - key: ONYXKEYS.TASK, - }, -})(TaskAssigneeSelectorModal); - -export default withNavigationTransitionEnd(withCurrentUserPersonalDetails(TaskAssigneeSelectorModalWithOnyx)); +export default withNavigationTransitionEnd(withCurrentUserPersonalDetails(TaskAssigneeSelectorModal));