-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathNotFoundPage.tsx
49 lines (43 loc) · 2.09 KB
/
NotFoundPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import {useOnyx} from 'react-native-onyx';
import type {FullPageNotFoundViewProps} from '@components/BlockingViews/FullPageNotFoundView';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ScreenWrapper from '@components/ScreenWrapper';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import Navigation from '@libs/Navigation/Navigation';
import ONYXKEYS from '@src/ONYXKEYS';
type NotFoundPageProps = {
onBackButtonPress?: () => void;
isReportRelatedPage?: boolean;
} & FullPageNotFoundViewProps;
// eslint-disable-next-line rulesdir/no-negated-variables
function NotFoundPage({onBackButtonPress = () => Navigation.goBack(), isReportRelatedPage, ...fullPageNotFoundViewProps}: NotFoundPageProps) {
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to go back to the not found page on large screens and to the home page on small screen
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
const topmostReportId = Navigation.getTopmostReportId();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${topmostReportId}`);
return (
<ScreenWrapper testID={NotFoundPage.displayName}>
<FullPageNotFoundView
shouldShow
onBackButtonPress={() => {
if (!isReportRelatedPage || !isSmallScreenWidth) {
onBackButtonPress();
return;
}
// detect the report is invalid
if (topmostReportId && (!report || report.errorFields?.notFound)) {
Navigation.dismissModal();
return;
}
onBackButtonPress();
}}
// eslint-disable-next-line react/jsx-props-no-spreading
{...fullPageNotFoundViewProps}
/>
</ScreenWrapper>
);
}
NotFoundPage.displayName = 'NotFoundPage';
export default NotFoundPage;