diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 24b698c24619..a3aa28c44609 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -130,7 +130,10 @@ const ROUTES = { route: 'settings/profile/contact-methods/:contactMethod/details', getRoute: (contactMethod: string) => `settings/profile/contact-methods/${encodeURIComponent(contactMethod)}/details` as const, }, - 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: { route: 'settings/security/two-factor-auth', getRoute: (backTo?: string) => getUrlWithBackToParam('settings/security/two-factor-auth', backTo), diff --git a/src/libs/Navigation/linkingConfig.ts b/src/libs/Navigation/linkingConfig.ts index bb06bf7e4528..92a04778b9a6 100644 --- a/src/libs/Navigation/linkingConfig.ts +++ b/src/libs/Navigation/linkingConfig.ts @@ -171,7 +171,7 @@ const linkingConfig: LinkingOptions = { 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..a17dd8f2c17e 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,6 +111,14 @@ 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]); + 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..70d137d2a5fd 100644 --- a/src/pages/settings/Profile/Contacts/NewContactMethodPage.js +++ b/src/pages/settings/Profile/Contacts/NewContactMethodPage.js @@ -1,7 +1,7 @@ import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React, {useRef} from 'react'; +import React, {useCallback, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -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,14 @@ 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]); + return ( { @@ -104,7 +114,7 @@ function NewContactMethodPage(props) { > Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route)} + onBackButtonPress={onBackButtonPress} />