Skip to content

Commit

Permalink
Merge pull request #30289 from suneox/fix/30101-go-back-from-flag-as-…
Browse files Browse the repository at this point in the history
…offensive-page

fix go back from flag comment page to report
  • Loading branch information
iwiznia authored Nov 28, 2023
2 parents 0d617fe + e43e3db commit fb39883
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ const propTypes = {

/** Single execution function to prevent concurrent navigation actions */
singleExecution: PropTypes.func,

/** Whether we should navigate to report page when the route have a topMostReport */
shouldNavigateToTopMostReport: PropTypes.bool,
};

export default propTypes;
8 changes: 7 additions & 1 deletion src/components/HeaderWithBackButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function HeaderWithBackButton({
children = null,
shouldOverlay = false,
singleExecution = (func) => func,
shouldNavigateToTopMostReport = false,
}) {
const styles = useThemeStyles();
const [isDownloadButtonActive, temporarilyDisableDownloadButton] = useThrottledButtonState();
Expand All @@ -74,7 +75,12 @@ function HeaderWithBackButton({
if (isKeyboardShown) {
Keyboard.dismiss();
}
onBackButtonPress();
const topmostReportId = Navigation.getTopmostReportId();
if (shouldNavigateToTopMostReport && topmostReportId) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(topmostReportId));
} else {
onBackButtonPress();
}
}}
style={[styles.touchableButtonImage]}
role="button"
Expand Down
10 changes: 9 additions & 1 deletion src/pages/FlagCommentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as Report from '@userActions/Report';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import reportActionPropTypes from './home/report/reportActionPropTypes';
import withReportAndReportActionOrNotFound from './home/report/withReportAndReportActionOrNotFound';
import reportPropTypes from './reportPropTypes';
Expand Down Expand Up @@ -161,7 +162,14 @@ function FlagCommentPage(props) {
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!ReportUtils.shouldShowFlagComment(getActionToFlag(), props.report)}>
<HeaderWithBackButton title={props.translate('reportActionContextMenu.flagAsOffensive')} />
<HeaderWithBackButton
title={props.translate('reportActionContextMenu.flagAsOffensive')}
shouldNavigateToTopMostReport
onBackButtonPress={() => {
Navigation.goBack();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID));
}}
/>
<ScrollView
contentContainerStyle={safeAreaPaddingBottomStyle}
style={styles.settingsPageBackground}
Expand Down
6 changes: 1 addition & 5 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,8 @@ function ReportDetailsPage(props) {
<FullPageNotFoundView shouldShow={_.isEmpty(props.report)}>
<HeaderWithBackButton
title={props.translate('common.details')}
shouldNavigateToTopMostReport
onBackButtonPress={() => {
const topMostReportID = Navigation.getTopmostReportId();
if (topMostReportID) {
Navigation.goBack(ROUTES.HOME);
return;
}
Navigation.goBack();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID));
}}
Expand Down

0 comments on commit fb39883

Please sign in to comment.