Skip to content

Commit

Permalink
Merge pull request #15499 from s77rt/with-report-or-notfound
Browse files Browse the repository at this point in the history
Show NotFoundPage if report does not exist in sub report views
  • Loading branch information
AndrewGable authored Feb 28, 2023
2 parents ef46d29 + 15bcf15 commit cda177c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import MenuItem from '../components/MenuItem';
import Text from '../components/Text';
import CONST from '../CONST';
import reportPropTypes from './reportPropTypes';
import withReportOrNavigateHome from './home/report/withReportOrNavigateHome';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';

const propTypes = {
Expand Down Expand Up @@ -181,7 +181,7 @@ ReportDetailsPage.propTypes = propTypes;

export default compose(
withLocalize,
withReportOrNavigateHome,
withReportOrNotFound,
withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportParticipantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import compose from '../libs/compose';
import * as ReportUtils from '../libs/ReportUtils';
import reportPropTypes from './reportPropTypes';
import withReportOrNavigateHome from './home/report/withReportOrNavigateHome';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';

const propTypes = {
Expand Down Expand Up @@ -118,7 +118,7 @@ ReportParticipantsPage.displayName = 'ReportParticipantsPage';

export default compose(
withLocalize,
withReportOrNavigateHome,
withReportOrNotFound,
withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Picker from '../components/Picker';
import * as ValidationUtils from '../libs/ValidationUtils';
import OfflineWithFeedback from '../components/OfflineWithFeedback';
import reportPropTypes from './reportPropTypes';
import withReportOrNavigateHome from './home/report/withReportOrNavigateHome';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import Form from '../components/Form';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';

Expand Down Expand Up @@ -220,7 +220,7 @@ ReportSettingsPage.propTypes = propTypes;

export default compose(
withLocalize,
withReportOrNavigateHome,
withReportOrNotFound,
withOnyx({
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {Component} from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import getComponentDisplayName from '../../../libs/getComponentDisplayName';
import Navigation from '../../../libs/Navigation/Navigation';
import NotFoundPage from '../../ErrorPage/NotFoundPage';
import ONYXKEYS from '../../../ONYXKEYS';
import reportPropTypes from '../../reportPropTypes';

Expand All @@ -22,15 +22,12 @@ export default function (WrappedComponent) {
report: {},
};

class WithReportOrNavigateHome extends Component {
componentDidMount() {
if (!_.isEmpty(this.props.report)) {
return;
class WithReportOrNotFound extends Component {
render() {
if (_.isEmpty(this.props.report) || !this.props.report.reportID) {
return <NotFoundPage />;
}
Navigation.dismissModal();
}

render() {
const rest = _.omit(this.props, ['forwardedRef']);

return (
Expand All @@ -43,17 +40,18 @@ export default function (WrappedComponent) {
}
}

WithReportOrNavigateHome.propTypes = propTypes;
WithReportOrNavigateHome.defaultProps = defaultProps;
WithReportOrNavigateHome.displayName = `withReportOrNavigateHome(${getComponentDisplayName(WrappedComponent)})`;
const withReportOrNavigateHome = React.forwardRef((props, ref) => (
WithReportOrNotFound.propTypes = propTypes;
WithReportOrNotFound.defaultProps = defaultProps;
WithReportOrNotFound.displayName = `withReportOrNotFound(${getComponentDisplayName(WrappedComponent)})`;
// eslint-disable-next-line rulesdir/no-negated-variables
const withReportOrNotFound = React.forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<WithReportOrNavigateHome {...props} forwardedRef={ref} />
<WithReportOrNotFound {...props} forwardedRef={ref} />
));

return withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`,
},
})(withReportOrNavigateHome);
})(withReportOrNotFound);
}

0 comments on commit cda177c

Please sign in to comment.