Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 29056 Back from request money details page does not open request money page #29268

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@
import _ from 'underscore';
import {StackRouter} from '@react-navigation/native';
import lodashFindLast from 'lodash/findLast';
import NAVIGATORS from '../../../../NAVIGATORS';
import SCREENS from '../../../../SCREENS';

/**
* @param {Object} state - react-navigation state
* @returns {Boolean}
*/
const isAtLeastOneCentralPaneNavigatorInState = (state) => _.find(state.routes, (r) => r.name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR);

/**
* @param {Object} state - react-navigation state
* @returns {String|undefined}
*/
const getTopMostReportIDFromRHP = (state) => {
if (!state) {
return;
}
const topmostRightPane = lodashFindLast(state.routes, (route) => route.name === 'RightModalNavigator');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using NAVIGATORS.RIGHT_MODAL_NAVIGATOR here


if (topmostRightPane) {
return getTopMostReportIDFromRHP(topmostRightPane.state);
}

const topmostRoute = lodashFindLast(state.routes);

if (topmostRoute.state) {
return getTopMostReportIDFromRHP(topmostRoute.state);
}

if (topmostRoute.params && topmostRoute.params.reportID) {
return topmostRoute.params.reportID;
}
};
/**
* Adds report route without any specific reportID to the state.
* The report screen will self set proper reportID param based on the helper function findLastAccessedReport (look at ReportScreenWrapper for more info)
*
* @param {Object} state - react-navigation state
*/
const addCentralPaneNavigatorRoute = (state) => {
state.routes.splice(1, 0, {name: NAVIGATORS.CENTRAL_PANE_NAVIGATOR});
const reportID = getTopMostReportIDFromRHP(state);
const centralPaneNavigatorRoute = {
name: NAVIGATORS.CENTRAL_PANE_NAVIGATOR,
state: {
routes: [
{
name: SCREENS.REPORT,
params: {
reportID,
},
},
],
},
};
state.routes.splice(1, 0, centralPaneNavigatorRoute);
// eslint-disable-next-line no-param-reassign
state.index = state.routes.length - 1;
};
Expand Down
13 changes: 12 additions & 1 deletion src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ function ReportDetailsPage(props) {
return (
<ScreenWrapper testID={ReportDetailsPage.displayName}>
<FullPageNotFoundView shouldShow={_.isEmpty(props.report)}>
<HeaderWithBackButton title={props.translate('common.details')} />
<HeaderWithBackButton
title={props.translate('common.details')}
onBackButtonPress={() => {
const topMostReportID = Navigation.getTopmostReportId();
if (topMostReportID) {
Navigation.goBack(ROUTES.HOME);
return;
}
Navigation.goBack();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID));
}}
/>
<ScrollView style={[styles.flex1]}>
<View style={styles.reportDetailsTitleContainer}>
<View style={styles.mb3}>
Expand Down
Loading