diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 09e9875d19e42..9976e32ca4ab6 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -396,9 +396,8 @@ function fetchChatReportsByIDs(chatList, shouldRedirectIfInacessible = false) { }) .catch((err) => { if (err.message === CONST.REPORT.ERROR.INACCESSIBLE_REPORT) { - Growl.error(translateLocal('notFound.chatYouLookingForCannotBeFound')); // eslint-disable-next-line no-use-before-define - navigateToConciergeChat(); + handleInaccessibleReport(); } }); } @@ -1365,6 +1364,14 @@ function navigateToConciergeChat() { Navigation.closeDrawer(); } +/** + * Handle the navigation when report is inaccessible + */ +function handleInaccessibleReport() { + Growl.error(translateLocal('notFound.chatYouLookingForCannotBeFound')); + navigateToConciergeChat(); +} + export { fetchAllReports, fetchActions, @@ -1389,4 +1396,5 @@ export { getSimplifiedIOUReport, syncChatAndIOUReports, navigateToConciergeChat, + handleInaccessibleReport, }; diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index dfe7cea28c1b0..13568cdbc257d 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,6 +1,7 @@ import React from 'react'; import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; +import _ from 'underscore'; import styles from '../../styles/styles'; import ReportView from './report/ReportView'; import ScreenWrapper from '../../components/ScreenWrapper'; @@ -8,7 +9,7 @@ import HeaderView from './HeaderView'; import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; -import {updateCurrentlyViewedReportID} from '../../libs/actions/Report'; +import {handleInaccessibleReport, updateCurrentlyViewedReportID} from '../../libs/actions/Report'; import ONYXKEYS from '../../ONYXKEYS'; const propTypes = { @@ -89,6 +90,10 @@ class ReportScreen extends React.Component { */ storeCurrentlyViewedReport() { const reportID = this.getReportID(); + if (_.isNaN(reportID)) { + handleInaccessibleReport(); + return; + } updateCurrentlyViewedReportID(reportID); }