From 621f19cc13de4277cd7114964b10c6fcdf88fbcf Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 25 Apr 2024 08:44:44 +0700 Subject: [PATCH 1/7] Navigate back to correct page from private note edit page --- ios/Podfile.lock | 2 +- src/libs/ReportUtils.ts | 16 ++++++++++++++++ src/pages/PrivateNotes/PrivateNotesEditPage.tsx | 14 ++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index ed387a8d522f..b59f4ef01158 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2558,7 +2558,7 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2 VisionCamera: 3033e0dd5272d46e97bcb406adea4ae0e6907abf - Yoga: 64cd2a583ead952b0315d5135bf39e053ae9be70 + Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312 PODFILE CHECKSUM: a25a81f2b50270f0c0bd0aff2e2ebe4d0b4ec06d diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f92106d40b6e..535c57b4558e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3134,6 +3134,21 @@ function goBackToDetailsPage(report: OnyxEntry) { Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report?.reportID ?? '')); } +/** + * Go back to the previous page from the edit private page of a given report + */ +function goBackFromPrivateNotes(report: OnyxEntry, session: OnyxEntry) { + if (isEmpty(report) || isEmpty(session) || !session.accountID) { + return; + } + const currentUserPrivateNote = report.privateNotes?.[session.accountID]?.note ?? ''; + if (isEmpty(currentUserPrivateNote)) { + goBackToDetailsPage(report); + return; + } + Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.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, @@ -6289,6 +6304,7 @@ export { getWorkspaceChats, getWorkspaceIcon, goBackToDetailsPage, + goBackFromPrivateNotes, hasActionsWithErrors, hasAutomatedExpensifyAccountIDs, hasExpensifyGuidesEmails, diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx index f9560edf7486..a47782cc6445 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx @@ -5,7 +5,7 @@ import Str from 'expensify-common/lib/str'; import lodashDebounce from 'lodash/debounce'; import React, {useCallback, useMemo, useRef, useState} from 'react'; import {Keyboard} from 'react-native'; -import type {OnyxCollection} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; @@ -31,12 +31,15 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/PrivateNotesForm'; -import type {PersonalDetails, Report} from '@src/types/onyx'; +import type {PersonalDetails, Report, Session} from '@src/types/onyx'; import type {Note} from '@src/types/onyx/Report'; type PrivateNotesEditPageOnyxProps = { /** All of the personal details for everyone */ personalDetailsList: OnyxCollection; + + /** Session info for the currently logged in user. */ + session: OnyxEntry; }; type PrivateNotesEditPageProps = WithReportAndPrivateNotesOrNotFoundProps & @@ -46,7 +49,7 @@ type PrivateNotesEditPageProps = WithReportAndPrivateNotesOrNotFoundProps & report: Report; }; -function PrivateNotesEditPage({route, personalDetailsList, report}: PrivateNotesEditPageProps) { +function PrivateNotesEditPage({route, personalDetailsList, report, session}: PrivateNotesEditPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -117,7 +120,7 @@ function PrivateNotesEditPage({route, personalDetailsList, report}: PrivateNotes > Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID))} + onBackButtonPress={() => ReportUtils.goBackFromPrivateNotes(report, session)} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} /> @@ -181,5 +184,8 @@ export default withReportAndPrivateNotesOrNotFound('privateNotes.title')( personalDetailsList: { key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, + session: { + key: ONYXKEYS.SESSION, + }, })(PrivateNotesEditPage), ); From dfcc2e7d795ca73ab82f10311f19fece92e97c66 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 25 Apr 2024 08:54:38 +0700 Subject: [PATCH 2/7] fix ts check --- src/pages/PrivateNotes/PrivateNotesEditPage.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx index a47782cc6445..b1466fc89687 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx @@ -37,9 +37,6 @@ import type {Note} from '@src/types/onyx/Report'; type PrivateNotesEditPageOnyxProps = { /** All of the personal details for everyone */ personalDetailsList: OnyxCollection; - - /** Session info for the currently logged in user. */ - session: OnyxEntry; }; type PrivateNotesEditPageProps = WithReportAndPrivateNotesOrNotFoundProps & @@ -184,8 +181,5 @@ export default withReportAndPrivateNotesOrNotFound('privateNotes.title')( personalDetailsList: { key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, - session: { - key: ONYXKEYS.SESSION, - }, })(PrivateNotesEditPage), ); From d150b37a225339dad575a8f21eabd1fd3f4cff18 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 25 Apr 2024 09:37:29 +0700 Subject: [PATCH 3/7] fix lint --- src/pages/PrivateNotes/PrivateNotesEditPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx index b1466fc89687..19cbe0bbea42 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx @@ -5,7 +5,7 @@ import Str from 'expensify-common/lib/str'; import lodashDebounce from 'lodash/debounce'; import React, {useCallback, useMemo, useRef, useState} from 'react'; import {Keyboard} from 'react-native'; -import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import type {OnyxCollection} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; @@ -31,7 +31,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/PrivateNotesForm'; -import type {PersonalDetails, Report, Session} from '@src/types/onyx'; +import type {PersonalDetails, Report} from '@src/types/onyx'; import type {Note} from '@src/types/onyx/Report'; type PrivateNotesEditPageOnyxProps = { From 1f322c4cefa69f52757cca04631cbac8f6f1fb2a Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 25 Apr 2024 16:17:13 +0700 Subject: [PATCH 4/7] revert podfile change --- ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b59f4ef01158..ed387a8d522f 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2558,7 +2558,7 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2 VisionCamera: 3033e0dd5272d46e97bcb406adea4ae0e6907abf - Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312 + Yoga: 64cd2a583ead952b0315d5135bf39e053ae9be70 PODFILE CHECKSUM: a25a81f2b50270f0c0bd0aff2e2ebe4d0b4ec06d From d2dcecab189c020810752caaae660f922de04cc2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 26 Apr 2024 17:49:34 +0700 Subject: [PATCH 5/7] modify go back logic base on navigateToDetailsPage function --- src/libs/ReportUtils.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0ae129a198f1..bcd748d2e6be 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3144,8 +3144,22 @@ function goBackFromPrivateNotes(report: OnyxEntry, session: OnyxEntry Date: Thu, 2 May 2024 12:59:24 +0700 Subject: [PATCH 6/7] fix lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8bafd820f57e..18e3b1ae48bb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3286,7 +3286,7 @@ function goBackFromPrivateNotes(report: OnyxEntry, session: OnyxEntry Date: Tue, 14 May 2024 15:09:36 +0700 Subject: [PATCH 7/7] merge main --- src/libs/ReportUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7d54353a7b44..87cee0a27ccd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3346,7 +3346,9 @@ function goBackFromPrivateNotes(report: OnyxEntry, session: OnyxEntry accountID !== currentUserAccountID || !isOneOnOneChat(report)); if (isOneOnOneChat(report)) { Navigation.goBack(ROUTES.PROFILE.getRoute(participantAccountIDs[0]));