Skip to content

Commit

Permalink
Merge pull request #49604 from nkdengineer/fix/49514
Browse files Browse the repository at this point in the history
fix app crashes when opening task assignee page

(cherry picked from commit 734c15f)

(CP triggered by AndrewGable)
  • Loading branch information
flodnv authored and OSBotify committed Sep 23, 2024
1 parent 89f81d5 commit d1eb7b3
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions src/pages/tasks/TaskAssigneeSelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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<Report>;

/** Grab the Share destination of the Task */
task: OnyxEntry<Task>;
};

type TaskAssigneeSelectorModalProps = TaskAssigneeSelectorModalOnyxProps & WithCurrentUserPersonalDetailsProps & WithNavigationTransitionEndProps;
import type {Report} from '@src/types/onyx';

function useOptions() {
const betas = useBetas();
Expand Down Expand Up @@ -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<RouteProp<TaskDetailsNavigatorParamList, typeof SCREENS.TASK.ASSIGNEE>>();
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();
Expand All @@ -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}`];
Expand Down Expand Up @@ -258,13 +249,4 @@ function TaskAssigneeSelectorModal({reports, task}: TaskAssigneeSelectorModalPro

TaskAssigneeSelectorModal.displayName = 'TaskAssigneeSelectorModal';

const TaskAssigneeSelectorModalWithOnyx = withOnyx<TaskAssigneeSelectorModalProps, TaskAssigneeSelectorModalOnyxProps>({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
task: {
key: ONYXKEYS.TASK,
},
})(TaskAssigneeSelectorModal);

export default withNavigationTransitionEnd(withCurrentUserPersonalDetails(TaskAssigneeSelectorModalWithOnyx));
export default withNavigationTransitionEnd(withCurrentUserPersonalDetails(TaskAssigneeSelectorModal));

0 comments on commit d1eb7b3

Please sign in to comment.