From 501e0034870719e87d074056270f23de98c64a15 Mon Sep 17 00:00:00 2001 From: BhuvaneshPatil Date: Tue, 26 Sep 2023 22:30:00 +0530 Subject: [PATCH 1/4] fix: add proper fallback routes for private notes pages --- src/pages/PrivateNotes/PrivateNotesEditPage.js | 3 ++- src/pages/PrivateNotes/PrivateNotesListPage.js | 8 ++++++++ src/pages/PrivateNotes/PrivateNotesViewPage.js | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index de3fafa7018d..88072047eaac 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -91,7 +91,7 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) { Keyboard.dismiss(); // Take user back to the PrivateNotesView page - Navigation.goBack(ROUTES.HOME); + Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, route.params.accountID)); }; return ( @@ -106,6 +106,7 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) { Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(lodashGet(report, 'reportID', ''), lodashGet(route, 'params.accountID', '')))} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} /> diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index ab096285788d..aa12468b60c1 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -15,6 +15,7 @@ import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndica import * as Report from '../../libs/actions/Report'; import personalDetailsPropType from '../personalDetailsPropType'; import * as UserUtils from '../../libs/UserUtils'; +import * as ReportUtils from '../../libs/ReportUtils'; import reportPropTypes from '../reportPropTypes'; import ScreenWrapper from '../../components/ScreenWrapper'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; @@ -116,6 +117,12 @@ function PrivateNotesListPage({report, personalDetailsList, network, session}) { .value(); }, [report, personalDetailsList, session, translate]); + const participantAccountIDs = lodashGet(report, 'participantAccountIDs', []); + const fallbackPath = + participantAccountIDs.length === 1 && !(ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)) || ReportUtils.isChatRoom(report)) + ? ROUTES.PROFILE.getRoute(participantAccountIDs[0]) + : ROUTES.REPORT_WITH_ID_DETAILS.getRoute(lodashGet(report, 'reportID', '')); + return ( Navigation.goBack(fallbackPath)} onCloseButtonPress={() => Navigation.dismissModal()} /> {report.isLoadingPrivateNotes && _.isEmpty(lodashGet(report, 'privateNotes', {})) ? ( diff --git a/src/pages/PrivateNotes/PrivateNotesViewPage.js b/src/pages/PrivateNotes/PrivateNotesViewPage.js index d09f1bbdee47..fd68b25c7006 100644 --- a/src/pages/PrivateNotes/PrivateNotesViewPage.js +++ b/src/pages/PrivateNotes/PrivateNotesViewPage.js @@ -66,6 +66,7 @@ function PrivateNotesViewPage({route, personalDetailsList, session, report}) { > Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(lodashGet(report, 'reportID', '')))} subtitle={isCurrentUserNote ? translate('privateNotes.myNote') : `${lodashGet(personalDetailsList, [route.params.accountID, 'login'], '')} note`} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} From ba36c1345ef79bfdce9042c0e4622289cd1de41f Mon Sep 17 00:00:00 2001 From: BhuvaneshPatil Date: Wed, 27 Sep 2023 19:04:13 +0530 Subject: [PATCH 2/4] revert changes for list page --- src/pages/PrivateNotes/PrivateNotesListPage.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index aa12468b60c1..ab096285788d 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -15,7 +15,6 @@ import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndica import * as Report from '../../libs/actions/Report'; import personalDetailsPropType from '../personalDetailsPropType'; import * as UserUtils from '../../libs/UserUtils'; -import * as ReportUtils from '../../libs/ReportUtils'; import reportPropTypes from '../reportPropTypes'; import ScreenWrapper from '../../components/ScreenWrapper'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; @@ -117,12 +116,6 @@ function PrivateNotesListPage({report, personalDetailsList, network, session}) { .value(); }, [report, personalDetailsList, session, translate]); - const participantAccountIDs = lodashGet(report, 'participantAccountIDs', []); - const fallbackPath = - participantAccountIDs.length === 1 && !(ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)) || ReportUtils.isChatRoom(report)) - ? ROUTES.PROFILE.getRoute(participantAccountIDs[0]) - : ROUTES.REPORT_WITH_ID_DETAILS.getRoute(lodashGet(report, 'reportID', '')); - return ( Navigation.goBack(fallbackPath)} onCloseButtonPress={() => Navigation.dismissModal()} /> {report.isLoadingPrivateNotes && _.isEmpty(lodashGet(report, 'privateNotes', {})) ? ( From 78a6926cc35c1f78bb4918e9c1cbd497fa5195a9 Mon Sep 17 00:00:00 2001 From: BhuvaneshPatil Date: Thu, 28 Sep 2023 11:38:00 +0530 Subject: [PATCH 3/4] nit: remove lodash usage and get property values directly --- src/pages/PrivateNotes/PrivateNotesEditPage.js | 2 +- src/pages/PrivateNotes/PrivateNotesViewPage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index 88072047eaac..b833b9800b97 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -106,7 +106,7 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) { Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(lodashGet(report, 'reportID', ''), lodashGet(route, 'params.accountID', '')))} + onBackButtonPress={() => Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.repotID, route.params.accountID))} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} /> diff --git a/src/pages/PrivateNotes/PrivateNotesViewPage.js b/src/pages/PrivateNotes/PrivateNotesViewPage.js index fd68b25c7006..4998fb4cdacd 100644 --- a/src/pages/PrivateNotes/PrivateNotesViewPage.js +++ b/src/pages/PrivateNotes/PrivateNotesViewPage.js @@ -66,7 +66,7 @@ function PrivateNotesViewPage({route, personalDetailsList, session, report}) { > Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(lodashGet(report, 'reportID', '')))} + onBackButtonPress={() => Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID))} subtitle={isCurrentUserNote ? translate('privateNotes.myNote') : `${lodashGet(personalDetailsList, [route.params.accountID, 'login'], '')} note`} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} From b5a74370e0dba55c22f1db66c9bd6dcb3ece73e3 Mon Sep 17 00:00:00 2001 From: BhuvaneshPatil Date: Fri, 29 Sep 2023 18:31:49 +0530 Subject: [PATCH 4/4] add fallback route to view page --- src/pages/PrivateNotes/PrivateNotesViewPage.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/PrivateNotes/PrivateNotesViewPage.js b/src/pages/PrivateNotes/PrivateNotesViewPage.js index 4998fb4cdacd..654e04e3d6ec 100644 --- a/src/pages/PrivateNotes/PrivateNotesViewPage.js +++ b/src/pages/PrivateNotes/PrivateNotesViewPage.js @@ -55,6 +55,16 @@ function PrivateNotesViewPage({route, personalDetailsList, session, report}) { const isCurrentUserNote = Number(session.accountID) === Number(route.params.accountID); const privateNote = lodashGet(report, ['privateNotes', route.params.accountID, 'note'], ''); + const getFallbackRoute = () => { + const privateNotes = lodashGet(report, 'privateNotes', {}); + + if (_.keys(privateNotes).length === 1) { + return ROUTES.HOME; + } + + return ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID); + }; + return ( Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID))} + onBackButtonPress={() => Navigation.goBack(getFallbackRoute())} subtitle={isCurrentUserNote ? translate('privateNotes.myNote') : `${lodashGet(personalDetailsList, [route.params.accountID, 'login'], '')} note`} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()}