From a21abfa0cf72adc214d224f0038e3d6bd5cf2fd7 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Mon, 27 Nov 2023 19:27:40 +0100 Subject: [PATCH 1/7] Fix bug with Save the World - Navigation problem on teachers contact page after a reload --- src/ROUTES.ts | 5 ++++- src/libs/Navigation/linkingConfig.js | 2 +- .../Profile/Contacts/ContactMethodsPage.js | 12 +++++++++++- .../Profile/Contacts/NewContactMethodPage.js | 14 +++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 26589a3db0e0..badc75a1b9cd 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -132,7 +132,10 @@ export default { route: 'settings/profile/contact-methods/:contactMethod/details', getRoute: (contactMethod: string) => `settings/profile/contact-methods/${encodeURIComponent(contactMethod)}/details`, }, - SETTINGS_NEW_CONTACT_METHOD: 'settings/profile/contact-methods/new', + SETTINGS_NEW_CONTACT_METHOD: { + route: 'settings/profile/contact-methods/new', + getRoute: (backTo?: string) => `${getUrlWithBackToParam('settings/profile/contact-methods/new', backTo)}`, + }, SETTINGS_2FA: 'settings/security/two-factor-auth', SETTINGS_STATUS: 'settings/profile/status', SETTINGS_STATUS_SET: 'settings/profile/status/set', diff --git a/src/libs/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js index e0ac35c957a3..b721be60ccd5 100644 --- a/src/libs/Navigation/linkingConfig.js +++ b/src/libs/Navigation/linkingConfig.js @@ -168,7 +168,7 @@ export default { path: ROUTES.SETTINGS_LOUNGE_ACCESS, }, Settings_NewContactMethod: { - path: ROUTES.SETTINGS_NEW_CONTACT_METHOD, + path: ROUTES.SETTINGS_NEW_CONTACT_METHOD.route, exact: true, }, Settings_PersonalDetails_Initial: { diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js index 6e0663a41a72..b07b783893db 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js @@ -111,6 +111,16 @@ function ContactMethodsPage(props) { ); }); + const onNewContactMethodButtonPress = () => { + if (navigateBackTo === ROUTES.SETTINGS_PROFILE) { + Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.route); + + return; + } + + Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.getRoute(navigateBackTo)); + }; + return ( Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD)} + onPress={onNewContactMethodButtonPress} pressOnEnter /> diff --git a/src/pages/settings/Profile/Contacts/NewContactMethodPage.js b/src/pages/settings/Profile/Contacts/NewContactMethodPage.js index 718c414bac87..0dcd0df43fca 100644 --- a/src/pages/settings/Profile/Contacts/NewContactMethodPage.js +++ b/src/pages/settings/Profile/Contacts/NewContactMethodPage.js @@ -61,6 +61,8 @@ function NewContactMethodPage(props) { const styles = useThemeStyles(); const loginInputRef = useRef(null); + const navigateBackTo = lodashGet(props.route, 'params.backTo', ROUTES.SETTINGS_PROFILE); + const validate = React.useCallback( (values) => { const phoneLogin = LoginUtils.getPhoneLogin(values.phoneOrEmail); @@ -89,6 +91,16 @@ function NewContactMethodPage(props) { [], ); + const onBackButtonPress = () => { + if (navigateBackTo === ROUTES.SETTINGS_PROFILE) { + Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route); + + return; + } + + Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.getRoute(navigateBackTo)); + }; + return ( { @@ -104,7 +116,7 @@ function NewContactMethodPage(props) { > Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route)} + onBackButtonPress={onBackButtonPress} /> Date: Mon, 27 Nov 2023 19:42:39 +0100 Subject: [PATCH 2/7] Fix lint error --- src/pages/settings/Profile/Contacts/ContactMethodsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js index b07b783893db..1f4514ea3c47 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js @@ -117,7 +117,7 @@ function ContactMethodsPage(props) { return; } - + Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.getRoute(navigateBackTo)); }; From 7197f4fadf3e21be5ee2a516c56a024710b9c3c5 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Tue, 28 Nov 2023 12:43:35 +0100 Subject: [PATCH 3/7] Add some useCallbacks --- src/pages/settings/Profile/Contacts/ContactMethodsPage.js | 6 +++--- src/pages/settings/Profile/Contacts/NewContactMethodPage.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js index 1f4514ea3c47..23985d4c49c8 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js @@ -1,7 +1,7 @@ import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React from 'react'; +import React, {useCallback} from 'react'; import {ScrollView, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -111,7 +111,7 @@ function ContactMethodsPage(props) { ); }); - const onNewContactMethodButtonPress = () => { + const onNewContactMethodButtonPress = useCallback(() => { if (navigateBackTo === ROUTES.SETTINGS_PROFILE) { Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.route); @@ -119,7 +119,7 @@ function ContactMethodsPage(props) { } Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.getRoute(navigateBackTo)); - }; + }, [navigateBackTo]); return ( { + const onBackButtonPress = useCallback(() => { if (navigateBackTo === ROUTES.SETTINGS_PROFILE) { Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route); @@ -99,7 +99,7 @@ function NewContactMethodPage(props) { } Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.getRoute(navigateBackTo)); - }; + }, [navigateBackTo]); return ( Date: Tue, 28 Nov 2023 13:15:12 +0100 Subject: [PATCH 4/7] Fix extra spaces --- src/pages/settings/Profile/Contacts/ContactMethodsPage.js | 2 -- src/pages/settings/Profile/Contacts/NewContactMethodPage.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js index 23985d4c49c8..a17dd8f2c17e 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js @@ -114,10 +114,8 @@ function ContactMethodsPage(props) { const onNewContactMethodButtonPress = useCallback(() => { if (navigateBackTo === ROUTES.SETTINGS_PROFILE) { Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.route); - return; } - Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.getRoute(navigateBackTo)); }, [navigateBackTo]); diff --git a/src/pages/settings/Profile/Contacts/NewContactMethodPage.js b/src/pages/settings/Profile/Contacts/NewContactMethodPage.js index ad41f0780028..70d137d2a5fd 100644 --- a/src/pages/settings/Profile/Contacts/NewContactMethodPage.js +++ b/src/pages/settings/Profile/Contacts/NewContactMethodPage.js @@ -94,10 +94,8 @@ function NewContactMethodPage(props) { const onBackButtonPress = useCallback(() => { if (navigateBackTo === ROUTES.SETTINGS_PROFILE) { Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route); - return; } - Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.getRoute(navigateBackTo)); }, [navigateBackTo]); From 1f449e787998e62009b1a379344ddfede0de5971 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Thu, 30 Nov 2023 10:19:51 +0100 Subject: [PATCH 5/7] Create minor changes --- src/pages/settings/Profile/Contacts/ContactMethodsPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js index a17dd8f2c17e..289369eb5cbc 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js @@ -119,6 +119,8 @@ function ContactMethodsPage(props) { Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.getRoute(navigateBackTo)); }, [navigateBackTo]); + + return ( Date: Thu, 30 Nov 2023 10:22:02 +0100 Subject: [PATCH 6/7] Create minor changes x2 --- src/pages/settings/Profile/Contacts/ContactMethodsPage.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js index 289369eb5cbc..a17dd8f2c17e 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.js +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.js @@ -119,8 +119,6 @@ function ContactMethodsPage(props) { Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD.getRoute(navigateBackTo)); }, [navigateBackTo]); - - return ( Date: Thu, 30 Nov 2023 10:33:31 +0100 Subject: [PATCH 7/7] Refactor routes --- src/ROUTES.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 992c9598d4fc..a3aa28c44609 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -132,7 +132,7 @@ const ROUTES = { }, SETTINGS_NEW_CONTACT_METHOD: { route: 'settings/profile/contact-methods/new', - getRoute: (backTo?: string) => `${getUrlWithBackToParam('settings/profile/contact-methods/new', backTo)}`, + getRoute: (backTo?: string) => getUrlWithBackToParam('settings/profile/contact-methods/new', backTo), }, SETTINGS_2FA: { route: 'settings/security/two-factor-auth',