From dae4c62c0ffbe41b2fa7295818b9c0732fe7d30e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 15 Nov 2023 15:10:55 +0700 Subject: [PATCH 01/11] fix improve private notes flow --- .../PrivateNotes/PrivateNotesEditPage.js | 1 - .../PrivateNotes/PrivateNotesListPage.js | 30 +++++++++++-------- src/pages/ReportDetailsPage.js | 16 ++++++++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index f38dabee9183..cb31a15023d1 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -116,7 +116,6 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) { > Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, route.params.accountID))} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index 4d5b348c4b9f..6fdd96d77eb9 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -1,3 +1,4 @@ +import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useMemo} from 'react'; @@ -5,15 +6,15 @@ import {ScrollView} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import MenuItem from '@components/MenuItem'; +import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {withNetwork} from '@components/OnyxProvider'; import ScreenWrapper from '@components/ScreenWrapper'; +import Text from '@components/Text'; import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import useLocalize from '@hooks/useLocalize'; import compose from '@libs/compose'; import Navigation from '@libs/Navigation/Navigation'; -import * as UserUtils from '@libs/UserUtils'; import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound'; import personalDetailsPropType from '@pages/personalDetailsPropType'; import reportPropTypes from '@pages/reportPropTypes'; @@ -66,7 +67,6 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { */ function getMenuItem(item, index) { const keyTitle = item.translationKey ? translate(item.translationKey) : item.title; - return ( - ); @@ -97,10 +99,10 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { return _.chain(lodashGet(report, 'privateNotes', {})) .map((privateNote, accountID) => ({ title: Number(lodashGet(session, 'accountID', null)) === Number(accountID) ? translate('privateNotes.myNote') : lodashGet(personalDetailsList, [accountID, 'login'], ''), - icon: UserUtils.getAvatar(lodashGet(personalDetailsList, [accountID, 'avatar'], UserUtils.getDefaultAvatar(accountID)), accountID), - iconType: CONST.ICON_TYPE_AVATAR, - action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, accountID)), + action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, accountID)), brickRoadIndicator: privateNoteBrickRoadIndicator(accountID), + note: lodashGet(privateNote, 'note', ''), + disabled: Number(session.accountID) !== Number(accountID), })) .value(); }, [report, personalDetailsList, session, translate]); @@ -115,6 +117,7 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} /> + {translate('privateNotes.personalNoteMessage')} {_.map(privateNotes, (item, index) => getMenuItem(item, index))} ); @@ -131,6 +134,9 @@ export default compose( personalDetailsList: { key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, + session: { + key: ONYXKEYS.SESSION, + }, }), withNetwork(), )(PrivateNotesListPage); diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index de25fdc3a081..3272e15dac7f 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -1,3 +1,4 @@ +import {isEmpty} from 'lodash'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useMemo} from 'react'; @@ -139,7 +140,15 @@ function ReportDetailsPage(props) { translationKey: 'privateNotes.title', icon: Expensicons.Pencil, isAnonymousAction: false, - action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID)), + action: () => { + const currentUserPrivateNote = lodashGet(props.report, ['privateNotes', props.session.accountID, 'note'], ''); + if (isEmpty(currentUserPrivateNote)) { + Report.getReportPrivateNote(props.report.reportID); + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(props.report.reportID, props.session.accountID)); + return; + } + Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID)); + }, brickRoadIndicator: Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '', }); } @@ -156,7 +165,7 @@ function ReportDetailsPage(props) { } return items; - }, [props.report, isMoneyRequestReport, participants.length, isArchivedRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat, isPolicyMember]); + }, [props.report, isMoneyRequestReport, participants.length, isArchivedRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat, isPolicyMember, props.session.accountID]); const displayNamesWithTooltips = useMemo(() => { const hasMultipleParticipants = participants.length > 1; @@ -271,5 +280,8 @@ export default compose( policies: { key: ONYXKEYS.COLLECTION.POLICY, }, + session: { + key: ONYXKEYS.SESSION, + }, }), )(ReportDetailsPage); From c24c65425bb7cf433938aac819615d5452983e5e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 15 Nov 2023 15:57:41 +0700 Subject: [PATCH 02/11] fix access private notes by deeplink --- src/pages/PrivateNotes/PrivateNotesListPage.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index 6fdd96d77eb9..ef74bb838cee 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -1,7 +1,7 @@ -import Str from 'expensify-common/lib/str'; +import {some} from 'lodash'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React, {useMemo} from 'react'; +import React, {useEffect, useMemo} from 'react'; import {ScrollView} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -107,6 +107,12 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { .value(); }, [report, personalDetailsList, session, translate]); + useEffect(() => { + if (some(privateNotes, (item) => item.note)) { + return; + } + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); + }, [privateNotes, report.reportID, session.accountID]); return ( Date: Wed, 15 Nov 2023 16:56:12 +0700 Subject: [PATCH 03/11] fix goback after save --- src/pages/PrivateNotes/PrivateNotesEditPage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index cb31a15023d1..8d8769763eed 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -105,7 +105,8 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) { Keyboard.dismiss(); // Take user back to the PrivateNotesView page - Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, route.params.accountID)); + + Navigation.goBack(); }; return ( From fd079d20023d3811bd332288a8e35ebf25f92f67 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 15 Nov 2023 18:33:33 +0700 Subject: [PATCH 04/11] fix use underscore some --- src/pages/PrivateNotes/PrivateNotesListPage.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index ef74bb838cee..4133bc0c5629 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -1,4 +1,3 @@ -import {some} from 'lodash'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useEffect, useMemo} from 'react'; @@ -108,7 +107,7 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { }, [report, personalDetailsList, session, translate]); useEffect(() => { - if (some(privateNotes, (item) => item.note)) { + if (_.some(privateNotes, (item) => item.note)) { return; } Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); From ae7dde6e3d35edd3be35a2aa3bf1f4f8b02a38f2 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sat, 18 Nov 2023 08:31:53 +0700 Subject: [PATCH 05/11] fix remove private note navigate user to detail page --- src/pages/PrivateNotes/PrivateNotesEditPage.js | 10 +++++++--- src/pages/PrivateNotes/PrivateNotesListPage.js | 7 ++++--- src/pages/ProfilePage.js | 11 ++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index cf4dd7beded4..bf0905c2d052 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -1,6 +1,7 @@ import {useFocusEffect} from '@react-navigation/native'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; +import {isEmpty} from 'lodash'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useMemo, useRef, useState} from 'react'; @@ -18,6 +19,7 @@ import withLocalize from '@components/withLocalize'; import useLocalize from '@hooks/useLocalize'; import compose from '@libs/compose'; import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; import updateMultilineInputRange from '@libs/UpdateMultilineInputRange'; import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound'; import personalDetailsPropType from '@pages/personalDetailsPropType'; @@ -105,9 +107,11 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) { Keyboard.dismiss(); - // Take user back to the PrivateNotesView page - - Navigation.goBack(); + if (isEmpty(privateNote.trim())) { + ReportUtils.navigateToDetailsPage(report, true); + } else { + Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); + } }; return ( diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index 7a339dd5102b..b7f1032bfa9d 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -1,3 +1,4 @@ +import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useEffect, useMemo} from 'react'; @@ -106,13 +107,13 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { })) .value(); }, [report, personalDetailsList, session, translate]); - + const isFocused = useIsFocused(); useEffect(() => { - if (_.some(privateNotes, (item) => item.note)) { + if (_.some(privateNotes, (item) => item.note) || !isFocused) { return; } Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); - }, [privateNotes, report.reportID, session.accountID]); + }, [privateNotes, report.reportID, session.accountID, isFocused]); return ( Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID))} + onPress={() => { + const currentUserPrivateNote = lodashGet(props.report, ['privateNotes', props.session.accountID, 'note'], ''); + if (isEmpty(currentUserPrivateNote)) { + Report.getReportPrivateNote(props.report.reportID); + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(props.report.reportID, props.session.accountID)); + return; + } + Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID)); + }} wrapperStyle={styles.breakAll} shouldShowRightIcon brickRoadIndicator={Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} From dcb9c2f6cd0cc3e3afe201e78bef589f8abad5d2 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sat, 18 Nov 2023 09:12:15 +0700 Subject: [PATCH 06/11] fix logic --- src/libs/ReportUtils.js | 15 +++++++++++++++ src/pages/PrivateNotes/PrivateNotesEditPage.js | 9 ++++----- src/pages/PrivateNotes/PrivateNotesListPage.js | 4 ++-- src/pages/ProfilePage.js | 8 +------- src/pages/ReportDetailsPage.js | 8 +------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 673cb09232de..c8da692d8682 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2,6 +2,7 @@ import {format} from 'date-fns'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; +import {isEmpty} from 'lodash'; import lodashGet from 'lodash/get'; import lodashIntersection from 'lodash/intersection'; import Onyx from 'react-native-onyx'; @@ -4274,6 +4275,19 @@ function shouldDisableWelcomeMessage(report, policy) { return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy); } +/** + * @param {Object} report + * @param {Object} session + */ +function navigateToPrivateNotes(report, session) { + const currentUserPrivateNote = lodashGet(report, ['privateNotes', session.accountID, 'note'], ''); + if (isEmpty(currentUserPrivateNote)) { + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); + return; + } + Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -4437,4 +4451,5 @@ export { getChannelLogMemberMessage, getRoom, shouldDisableWelcomeMessage, + navigateToPrivateNotes, }; diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index bf0905c2d052..c89f51a3fa24 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -96,9 +96,9 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) { const savePrivateNote = () => { const originalNote = lodashGet(report, ['privateNotes', route.params.accountID, 'note'], ''); - + let editedNote = ''; if (privateNote.trim() !== originalNote.trim()) { - const editedNote = Report.handleUserDeletedLinksInHtml(privateNote.trim(), parser.htmlToMarkdown(originalNote).trim()); + editedNote = Report.handleUserDeletedLinksInHtml(privateNote.trim(), parser.htmlToMarkdown(originalNote).trim()); Report.updatePrivateNotes(report.reportID, route.params.accountID, editedNote); } @@ -106,9 +106,8 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) { debouncedSavePrivateNote(''); Keyboard.dismiss(); - - if (isEmpty(privateNote.trim())) { - ReportUtils.navigateToDetailsPage(report, true); + if (!_.some({...report.privateNotes, [route.params.accountID]: {note: editedNote}}, (item) => item.note)) { + ReportUtils.navigateToDetailsPage(report); } else { Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); } diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index b7f1032bfa9d..c8dc98d912dc 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -109,11 +109,11 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { }, [report, personalDetailsList, session, translate]); const isFocused = useIsFocused(); useEffect(() => { - if (_.some(privateNotes, (item) => item.note) || !isFocused) { + if (_.some(report.privateNotes, (item) => item.note) || !isFocused) { return; } Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); - }, [privateNotes, report.reportID, session.accountID, isFocused]); + }, [report.privateNotes, report.reportID, session.accountID, isFocused]); return ( { - const currentUserPrivateNote = lodashGet(props.report, ['privateNotes', props.session.accountID, 'note'], ''); - if (isEmpty(currentUserPrivateNote)) { - Report.getReportPrivateNote(props.report.reportID); - Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(props.report.reportID, props.session.accountID)); - return; - } - Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID)); + ReportUtils.navigateToPrivateNotes(props.report, props.session); }} wrapperStyle={styles.breakAll} shouldShowRightIcon diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 7770e62bd30c..cae300469f70 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -142,13 +142,7 @@ function ReportDetailsPage(props) { icon: Expensicons.Pencil, isAnonymousAction: false, action: () => { - const currentUserPrivateNote = lodashGet(props.report, ['privateNotes', props.session.accountID, 'note'], ''); - if (isEmpty(currentUserPrivateNote)) { - Report.getReportPrivateNote(props.report.reportID); - Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(props.report.reportID, props.session.accountID)); - return; - } - Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID)); + ReportUtils.navigateToPrivateNotes(props.report, props.session); }, brickRoadIndicator: Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '', }); From 393f62f06abb6067829d22a6b6795bf42a82d4e7 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sat, 18 Nov 2023 09:18:22 +0700 Subject: [PATCH 07/11] fix merge main conflict --- src/pages/ReportDetailsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index c39960d019e1..904137ecfbe0 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -148,7 +148,7 @@ function ReportDetailsPage(props) { } return items; - }, [isArchivedRoom, participants.length, isThread, isMoneyRequestReport, props.report, isGroupDMChat, isPolicyMember, isUserCreatedPolicyRoom]); + }, [isArchivedRoom, participants.length, isThread, isMoneyRequestReport, props.report, isGroupDMChat, isPolicyMember, isUserCreatedPolicyRoom, props.session]); const displayNamesWithTooltips = useMemo(() => { const hasMultipleParticipants = participants.length > 1; From 5b069ef1bec43d8c7b5f1a69320c3acf06270941 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sat, 18 Nov 2023 09:22:15 +0700 Subject: [PATCH 08/11] fix lint --- src/pages/PrivateNotes/PrivateNotesEditPage.js | 1 - src/pages/ProfilePage.js | 1 - src/pages/ReportDetailsPage.js | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.js b/src/pages/PrivateNotes/PrivateNotesEditPage.js index c89f51a3fa24..2c3064d199ef 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.js +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.js @@ -1,7 +1,6 @@ import {useFocusEffect} from '@react-navigation/native'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; -import {isEmpty} from 'lodash'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useMemo, useRef, useState} from 'react'; diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 6b6494dd72db..ab86789a99cc 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -1,6 +1,5 @@ import {parsePhoneNumber} from 'awesome-phonenumber'; import Str from 'expensify-common/lib/str'; -import {isEmpty} from 'lodash'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useEffect} from 'react'; diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 904137ecfbe0..5095074e281e 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -1,5 +1,3 @@ -import {isEmpty} from 'lodash'; -import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useMemo} from 'react'; import {ScrollView, View} from 'react-native'; From e4ccfa9e83a585b9f018981ad4de02cd387cef77 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 21 Nov 2023 11:55:57 +0700 Subject: [PATCH 09/11] fix open private notes using deeplink --- src/pages/PrivateNotes/PrivateNotesListPage.js | 18 ++++++++++++++---- src/pages/ProfilePage.js | 4 +--- src/pages/ReportDetailsPage.js | 4 +--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index c8dc98d912dc..7757dda487bf 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -108,11 +108,21 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { .value(); }, [report, personalDetailsList, session, translate]); const isFocused = useIsFocused(); + + const navigateToEditPageTimeoutRef = React.useRef(null); useEffect(() => { - if (_.some(report.privateNotes, (item) => item.note) || !isFocused) { - return; - } - Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); + navigateToEditPageTimeoutRef.current = setTimeout(() => { + if (_.some(report.privateNotes, (item) => item.note) || !isFocused) { + return; + } + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); + }, CONST.ANIMATED_TRANSITION); + return () => { + if (!navigateToEditPageTimeoutRef.current) { + return; + } + clearTimeout(navigateToEditPageTimeoutRef.current); + }; }, [report.privateNotes, report.reportID, session.accountID, isFocused]); return ( { - ReportUtils.navigateToPrivateNotes(props.report, props.session); - }} + onPress={() => ReportUtils.navigateToPrivateNotes(props.report, props.session)} wrapperStyle={styles.breakAll} shouldShowRightIcon brickRoadIndicator={Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''} diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 54a01cd25b28..da3d2a6beb05 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -138,9 +138,7 @@ function ReportDetailsPage(props) { translationKey: 'privateNotes.title', icon: Expensicons.Pencil, isAnonymousAction: false, - action: () => { - ReportUtils.navigateToPrivateNotes(props.report, props.session); - }, + action: () => ReportUtils.navigateToPrivateNotes(props.report, props.session), brickRoadIndicator: Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '', }); } From 9650b81e607196a213111cc5df6803da223935d9 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 22 Nov 2023 22:41:50 +0700 Subject: [PATCH 10/11] fix remove useRef in settimeout --- src/libs/ReportUtils.js | 1 + .../PrivateNotes/PrivateNotesListPage.js | 30 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 195630dcbd32..26b461bf80ae 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4317,6 +4317,7 @@ function shouldDisableWelcomeMessage(report, policy) { } /** + * Navigates to the appropriate screen based on the presence of a private note for the current user. * @param {Object} report * @param {Object} session */ diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.js b/src/pages/PrivateNotes/PrivateNotesListPage.js index 7757dda487bf..e9a4f11a7202 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.js +++ b/src/pages/PrivateNotes/PrivateNotesListPage.js @@ -58,6 +58,20 @@ const defaultProps = { function PrivateNotesListPage({report, personalDetailsList, session}) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const isFocused = useIsFocused(); + + useEffect(() => { + const navigateToEditPageTimeout = setTimeout(() => { + if (_.some(report.privateNotes, (item) => item.note) || !isFocused) { + return; + } + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); + }, CONST.ANIMATED_TRANSITION); + + return () => { + clearTimeout(navigateToEditPageTimeout); + }; + }, [report.privateNotes, report.reportID, session.accountID, isFocused]); /** * Gets the menu item for each workspace @@ -107,23 +121,7 @@ function PrivateNotesListPage({report, personalDetailsList, session}) { })) .value(); }, [report, personalDetailsList, session, translate]); - const isFocused = useIsFocused(); - const navigateToEditPageTimeoutRef = React.useRef(null); - useEffect(() => { - navigateToEditPageTimeoutRef.current = setTimeout(() => { - if (_.some(report.privateNotes, (item) => item.note) || !isFocused) { - return; - } - Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); - }, CONST.ANIMATED_TRANSITION); - return () => { - if (!navigateToEditPageTimeoutRef.current) { - return; - } - clearTimeout(navigateToEditPageTimeoutRef.current); - }; - }, [report.privateNotes, report.reportID, session.accountID, isFocused]); return ( Date: Tue, 28 Nov 2023 00:11:54 +0700 Subject: [PATCH 11/11] fix lint issue after refactor ReportUtils to ts --- src/libs/ReportUtils.ts | 14 +++++++------- src/types/onyx/Report.ts | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e3347ef52e83..e71e9282e7cb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4,7 +4,6 @@ import Str from 'expensify-common/lib/str'; import {isEmpty} from 'lodash'; import lodashEscape from 'lodash/escape'; import lodashFindLastIndex from 'lodash/findLastIndex'; -import lodashGet from 'lodash/get'; import lodashIntersection from 'lodash/intersection'; import lodashIsEqual from 'lodash/isEqual'; import Onyx, {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; @@ -16,7 +15,7 @@ import CONST from '@src/CONST'; import {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import {Beta, Login, PersonalDetails, Policy, PolicyTags, Report, ReportAction, Transaction} from '@src/types/onyx'; +import {Beta, Login, PersonalDetails, Policy, PolicyTags, Report, ReportAction, Session, Transaction} from '@src/types/onyx'; import {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; import {ChangeLog, IOUMessage, OriginalMessageActionName} from '@src/types/onyx/OriginalMessage'; import {Message, ReportActions} from '@src/types/onyx/ReportAction'; @@ -4220,13 +4219,14 @@ function shouldDisableWelcomeMessage(report: OnyxEntry, policy: OnyxEntr /** * Navigates to the appropriate screen based on the presence of a private note for the current user. - * @param {Object} report - * @param {Object} session */ -function navigateToPrivateNotes(report, session) { - const currentUserPrivateNote = lodashGet(report, ['privateNotes', session.accountID, 'note'], ''); +function navigateToPrivateNotes(report: Report, session: Session) { + if (isEmpty(report) || isEmpty(session)) { + return; + } + const currentUserPrivateNote = report.privateNotes?.[String(session.accountID)]?.note ?? ''; if (isEmpty(currentUserPrivateNote)) { - Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID)); + Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, String(session.accountID))); return; } Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID)); diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 81a92c4bf603..2b84f3946bc3 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -139,6 +139,7 @@ type Report = { isChatRoom?: boolean; participantsList?: Array>; text?: string; + privateNotes?: Record; }; export default Report;