diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 673cb09232de..c8777098a6b8 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2255,6 +2255,19 @@ function navigateToDetailsPage(report) { Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report.reportID)); } +/** + * Go back to the details page of a given report + * + * @param {Object} report + */ +function goBackToDetailsPage(report) { + if (isOneOnOneChat(report)) { + Navigation.goBack(ROUTES.PROFILE.getRoute(report.participantAccountIDs[0])); + return; + } + Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report.reportID)); +} + /** * Generate a random reportID up to 53 bits aka 9,007,199,254,740,991 (Number.MAX_SAFE_INTEGER). * There were approximately 98,000,000 reports with sequential IDs generated before we started using this approach, those make up roughly one billionth of the space for these numbers, @@ -4414,6 +4427,7 @@ export { hasSingleParticipant, getReportRecipientAccountIDs, isOneOnOneChat, + goBackToDetailsPage, getTransactionReportName, getTransactionDetails, getTaskAssigneeChatOnyxData, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index ffb68203cad0..d39cc48859a7 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1371,11 +1371,12 @@ function saveReportActionDraftNumberOfLines(reportID, reportActionID, numberOfLi * @param {boolean} navigate * @param {String} parentReportID * @param {String} parentReportActionID + * @param {Object} report */ -function updateNotificationPreference(reportID, previousValue, newValue, navigate, parentReportID = 0, parentReportActionID = 0) { +function updateNotificationPreference(reportID, previousValue, newValue, navigate, parentReportID = 0, parentReportActionID = 0, report = {}) { if (previousValue === newValue) { - if (navigate) { - Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID)); + if (navigate && report.reportID) { + ReportUtils.goBackToDetailsPage(report); } return; } @@ -1407,7 +1408,7 @@ function updateNotificationPreference(reportID, previousValue, newValue, navigat } API.write('UpdateReportNotificationPreference', {reportID, notificationPreference: newValue}, {optimisticData, failureData}); if (navigate) { - Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID)); + ReportUtils.goBackToDetailsPage(report); } } diff --git a/src/pages/settings/Report/NotificationPreferencePage.js b/src/pages/settings/Report/NotificationPreferencePage.js index 75e9e0d5c5e8..c6044bd81efe 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.js +++ b/src/pages/settings/Report/NotificationPreferencePage.js @@ -6,13 +6,11 @@ import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import compose from '@libs/compose'; -import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; import withReportOrNotFound from '@pages/home/report/withReportOrNotFound'; import reportPropTypes from '@pages/reportPropTypes'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; const propTypes = { ...withLocalizePropTypes, @@ -41,11 +39,13 @@ function NotificationPreferencePage(props) { Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID))} + onBackButtonPress={() => ReportUtils.goBackToDetailsPage(props.report)} /> Report.updateNotificationPreference(props.report.reportID, props.report.notificationPreference, option.value, true)} + onSelectRow={(option) => + Report.updateNotificationPreference(props.report.reportID, props.report.notificationPreference, option.value, true, undefined, undefined, props.report) + } initiallyFocusedOptionKey={_.find(notificationPreferenceOptions, (locale) => locale.isSelected).keyForList} />