From 41f5bad527697ddc1a102cd8f6db9a2a9b77d4a8 Mon Sep 17 00:00:00 2001 From: Aman Ansar Date: Tue, 3 Aug 2021 04:05:02 +0530 Subject: [PATCH 1/3] handle navigation when reportID isn't valid --- src/libs/actions/Report.js | 12 ++++++++++-- src/pages/home/ReportScreen.js | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) 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..e5fb587dfc94c 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 = { @@ -62,7 +63,11 @@ class ReportScreen extends React.Component { */ getReportID() { const params = this.props.route.params; - return Number.parseInt(params.reportID, 10); + const id = Number.parseInt(params.reportID, 10); + if (_.isNaN(id)) { + handleInaccessibleReport(); + } + return id; } /** From 7635fab4af82e34f8e40f1f2900a9fa7ff6d0236 Mon Sep 17 00:00:00 2001 From: Aman Ansar Date: Thu, 5 Aug 2021 01:03:19 +0530 Subject: [PATCH 2/3] improvement --- src/pages/home/ReportScreen.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index e5fb587dfc94c..d34c11b92e1d8 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -63,11 +63,7 @@ class ReportScreen extends React.Component { */ getReportID() { const params = this.props.route.params; - const id = Number.parseInt(params.reportID, 10); - if (_.isNaN(id)) { - handleInaccessibleReport(); - } - return id; + return Number.parseInt(params.reportID, 10); } /** @@ -94,6 +90,9 @@ class ReportScreen extends React.Component { */ storeCurrentlyViewedReport() { const reportID = this.getReportID(); + if (_.isNaN(reportID)) { + handleInaccessibleReport(); + } updateCurrentlyViewedReportID(reportID); } From b40dfc0b36c762ff32f409a2b7e566fa2f9472c1 Mon Sep 17 00:00:00 2001 From: Aman Ansar Date: Thu, 5 Aug 2021 22:39:08 +0530 Subject: [PATCH 3/3] minor fix --- src/pages/home/ReportScreen.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index d34c11b92e1d8..13568cdbc257d 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -92,6 +92,7 @@ class ReportScreen extends React.Component { const reportID = this.getReportID(); if (_.isNaN(reportID)) { handleInaccessibleReport(); + return; } updateCurrentlyViewedReportID(reportID); }