Skip to content

Commit

Permalink
Merge pull request #32065 from ZhenjaHorbach/save-the-world-navigatio…
Browse files Browse the repository at this point in the history
…n-problem-on-teachers-contact-page

Save the World - Navigation problem on teachers contact page after a reload
  • Loading branch information
tylerkaraszewski authored Nov 30, 2023
2 parents fa96a12 + 3f8545a commit 71cf44f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/linkingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const linkingConfig: LinkingOptions<RootStackParamList> = {
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: {
Expand Down
12 changes: 10 additions & 2 deletions src/pages/settings/Profile/Contacts/ContactMethodsPage.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<ScreenWrapper
shouldEnableKeyboardAvoidingView={false}
Expand All @@ -136,7 +144,7 @@ function ContactMethodsPage(props) {
<Button
success
text={props.translate('contacts.newContactMethod')}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_NEW_CONTACT_METHOD)}
onPress={onNewContactMethodButtonPress}
pressOnEnter
/>
</FixedFooter>
Expand Down
14 changes: 12 additions & 2 deletions src/pages/settings/Profile/Contacts/NewContactMethodPage.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<ScreenWrapper
onEntryTransitionEnd={() => {
Expand All @@ -104,7 +114,7 @@ function NewContactMethodPage(props) {
>
<HeaderWithBackButton
title={props.translate('contacts.newContactMethod')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_CONTACT_METHODS.route)}
onBackButtonPress={onBackButtonPress}
/>
<FormProvider
formID={ONYXKEYS.FORMS.NEW_CONTACT_METHOD_FORM}
Expand Down

0 comments on commit 71cf44f

Please sign in to comment.