From d41ed6851d50b9e673d9933abaffb7602a56d989 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 28 Aug 2024 14:24:48 +0700 Subject: [PATCH 1/3] fix: prevent not here page open twice --- src/pages/ErrorPage/NotFoundPage.tsx | 24 +++++++++++++++++-- .../home/report/withReportOrNotFound.tsx | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/pages/ErrorPage/NotFoundPage.tsx b/src/pages/ErrorPage/NotFoundPage.tsx index cfdeab9c51c7..38d096711fa7 100644 --- a/src/pages/ErrorPage/NotFoundPage.tsx +++ b/src/pages/ErrorPage/NotFoundPage.tsx @@ -2,18 +2,38 @@ import React from 'react'; import type {FullPageNotFoundViewProps} from '@components/BlockingViews/FullPageNotFoundView'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import ScreenWrapper from '@components/ScreenWrapper'; +import useWindowDimensions from '@hooks/useWindowDimensions'; +import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; +import ROUTES from '@src/ROUTES'; type NotFoundPageProps = { onBackButtonPress?: () => void; + isReportRelatedPage?: boolean; } & FullPageNotFoundViewProps; // eslint-disable-next-line rulesdir/no-negated-variables -function NotFoundPage({onBackButtonPress, ...fullPageNotFoundViewProps}: NotFoundPageProps) { +function NotFoundPage({onBackButtonPress = () => Navigation.goBack(), isReportRelatedPage, ...fullPageNotFoundViewProps}: NotFoundPageProps) { + const {isSmallScreen} = useWindowDimensions(); + return ( { + if (!isReportRelatedPage || !isSmallScreen) { + onBackButtonPress(); + return; + } + const topmostReportId = Navigation.getTopmostReportId(); + const report = ReportUtils.getReport(topmostReportId ?? ''); + // detect the report is invalid + if (topmostReportId && (!report || report.errorFields?.notFound)) { + Navigation.goBack(ROUTES.HOME, true, true); + return; + } + onBackButtonPress(); + }} // eslint-disable-next-line react/jsx-props-no-spreading {...fullPageNotFoundViewProps} /> diff --git a/src/pages/home/report/withReportOrNotFound.tsx b/src/pages/home/report/withReportOrNotFound.tsx index 7f6165a031ee..c3fb747264ac 100644 --- a/src/pages/home/report/withReportOrNotFound.tsx +++ b/src/pages/home/report/withReportOrNotFound.tsx @@ -84,7 +84,7 @@ export default function ( } if (shouldShowNotFoundPage) { - return ; + return ; } } From 30d0421cead09753d77271ff1f29efbeaa29b7c8 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 2 Sep 2024 15:24:27 +0700 Subject: [PATCH 2/3] fix: use dismissModal instead of goBack --- src/pages/ErrorPage/NotFoundPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ErrorPage/NotFoundPage.tsx b/src/pages/ErrorPage/NotFoundPage.tsx index 38d096711fa7..2d9b3fc920c2 100644 --- a/src/pages/ErrorPage/NotFoundPage.tsx +++ b/src/pages/ErrorPage/NotFoundPage.tsx @@ -29,7 +29,7 @@ function NotFoundPage({onBackButtonPress = () => Navigation.goBack(), isReportRe const report = ReportUtils.getReport(topmostReportId ?? ''); // detect the report is invalid if (topmostReportId && (!report || report.errorFields?.notFound)) { - Navigation.goBack(ROUTES.HOME, true, true); + Navigation.dismissModal(); return; } onBackButtonPress(); From d3101eda0564d071bca0f343a002ef00746ded05 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 2 Sep 2024 20:36:33 +0700 Subject: [PATCH 3/3] fix: import --- src/pages/ErrorPage/NotFoundPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/ErrorPage/NotFoundPage.tsx b/src/pages/ErrorPage/NotFoundPage.tsx index 2d9b3fc920c2..166358cf9bda 100644 --- a/src/pages/ErrorPage/NotFoundPage.tsx +++ b/src/pages/ErrorPage/NotFoundPage.tsx @@ -5,7 +5,6 @@ import ScreenWrapper from '@components/ScreenWrapper'; import useWindowDimensions from '@hooks/useWindowDimensions'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; -import ROUTES from '@src/ROUTES'; type NotFoundPageProps = { onBackButtonPress?: () => void;