From 0a72a2e9c5df00c06c7a7d72347f1654c9f9351b Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 14 Nov 2023 04:14:47 +0530 Subject: [PATCH 1/2] fixes the issue --- src/libs/ReportUtils.js | 14 ++++++++++++++ src/libs/actions/Report.js | 9 +++++---- .../settings/Report/NotificationPreferencePage.js | 6 ++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index a18594905b55..8156ddab6bda 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2215,6 +2215,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, @@ -4323,6 +4336,7 @@ export { hasSingleParticipant, getReportRecipientAccountIDs, isOneOnOneChat, + goBackToDetailsPage, getTransactionReportName, getTransactionDetails, getTaskAssigneeChatOnyxData, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 22a1bc5441e6..5e918b58f947 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1369,11 +1369,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; } @@ -1405,7 +1406,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..307a539942c7 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,11 @@ 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} /> From afcc4ccf88b20dbd61aec1ceda3819773ef85e5b Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 14 Nov 2023 04:31:11 +0530 Subject: [PATCH 2/2] fix lint --- src/libs/ReportUtils.js | 4 ++-- src/pages/settings/Report/NotificationPreferencePage.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8156ddab6bda..38cd6951ae79 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2220,13 +2220,13 @@ function navigateToDetailsPage(report) { * * @param {Object} report */ -function goBackToDetailsPage(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). diff --git a/src/pages/settings/Report/NotificationPreferencePage.js b/src/pages/settings/Report/NotificationPreferencePage.js index 307a539942c7..c6044bd81efe 100644 --- a/src/pages/settings/Report/NotificationPreferencePage.js +++ b/src/pages/settings/Report/NotificationPreferencePage.js @@ -43,7 +43,9 @@ function NotificationPreferencePage(props) { /> Report.updateNotificationPreference(props.report.reportID, props.report.notificationPreference, option.value, true, undefined, undefined, props.report)} + onSelectRow={(option) => + Report.updateNotificationPreference(props.report.reportID, props.report.notificationPreference, option.value, true, undefined, undefined, props.report) + } initiallyFocusedOptionKey={_.find(notificationPreferenceOptions, (locale) => locale.isSelected).keyForList} />