Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dedicated route for CountryPicker in AddressPage #26742

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0479a7e
Implement dedicated route for CountryPicker in AddressPage
ygshbht Sep 5, 2023
b5a0ebc
Comment correction
ygshbht Sep 5, 2023
3cbd8d2
Remove unused dependencies in CountrySelection
ygshbht Sep 6, 2023
53286fd
CountrySelection refactoring
ygshbht Sep 6, 2023
d88cc41
CountrySelection remove defaultProps
ygshbht Sep 6, 2023
b8cacd7
Make CountryPickerMenuItem a new component on its own page
ygshbht Sep 6, 2023
f4ae5b2
CountrySelection Navigation bugfix after selecting country
ygshbht Sep 6, 2023
ae6ebcf
Delete Old CountryPicker Modal
ygshbht Sep 6, 2023
9cfcc96
Add display name to CountryPickerMenuitem
ygshbht Sep 6, 2023
ff87483
Remove memoing CountryPickerMenuItem
ygshbht Sep 6, 2023
f161188
Comment modifications to CountrySelection and related files
ygshbht Sep 6, 2023
ce5463c
Merge branch 'fix/address-page-country-picker-navigation' of https://…
ygshbht Sep 6, 2023
ba351d1
CountySelectionPage & related files refactoring and comments
ygshbht Sep 7, 2023
55253e7
Rename CountrySelection to CountrySelectionPage
ygshbht Sep 7, 2023
4252fba
Rename CountrySelection to CountrySelectionPage
ygshbht Sep 7, 2023
178d100
AddressPage: revalidate input forms when country name changes
ygshbht Sep 7, 2023
3ec7cd8
Merge https://github.com/Expensify/App into fix/address-page-country-…
ygshbht Sep 13, 2023
c7dfa90
CountyPicker refactoring
ygshbht Sep 19, 2023
fc551b8
Rename CountryPickerMenuItem to CountrySelector
ygshbht Sep 19, 2023
137790c
Refactoring src/pages/settings/Profile/PersonalDetails/CountrySelecti…
ygshbht Sep 19, 2023
a49e1aa
Refactor src/pages/settings/Profile/PersonalDetails/AddressPage.js
ygshbht Sep 19, 2023
19a1e7e
Refactor src/components/CountrySelector.js
ygshbht Sep 19, 2023
2cca5c0
Pull from remote
ygshbht Sep 19, 2023
9104539
Disable eslint warning CountrySelector
ygshbht Sep 19, 2023
e81fe77
CountrySelector refactoring
ygshbht Sep 20, 2023
cdfe3b8
Merge branch 'main' into fix/address-page-country-picker-navigation
ygshbht Sep 22, 2023
a96a739
Format code
ygshbht Sep 23, 2023
136f90c
Merge https://github.com/Expensify/App into fix/address-page-country-…
ygshbht Sep 25, 2023
a017ee9
Merge branch 'fix/address-page-country-picker-navigation' of https://…
ygshbht Sep 25, 2023
9d19973
Formatting
ygshbht Sep 25, 2023
3af7931
Formatting
ygshbht Sep 25, 2023
945056d
set default prop value of 'value' of CountrySelector to undefined
ygshbht Sep 26, 2023
d2331d3
Merge https://github.com/Expensify/App into fix/address-page-country-…
ygshbht Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export default {
SETTINGS_PERSONAL_DETAILS_LEGAL_NAME: 'settings/profile/personal-details/legal-name',
SETTINGS_PERSONAL_DETAILS_DATE_OF_BIRTH: 'settings/profile/personal-details/date-of-birth',
SETTINGS_PERSONAL_DETAILS_ADDRESS: 'settings/profile/personal-details/address',
SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY: { route:`settings/profile/personal-details/address/country`, getRoute: (country: string, backTo?: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very weird formatting but not a blocker.

let route = `settings/profile/personal-details/address/country?country=${country}`;
if (backTo) {
route += `&backTo=${encodeURIComponent(backTo)}`;
}
return route;
}},
SETTINGS_CONTACT_METHODS: 'settings/profile/contact-methods',
SETTINGS_CONTACT_METHOD_DETAILS: { 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',
Expand Down
105 changes: 0 additions & 105 deletions src/components/CountryPicker/CountrySelectorModal.js

This file was deleted.

88 changes: 0 additions & 88 deletions src/components/CountryPicker/index.js

This file was deleted.

77 changes: 77 additions & 0 deletions src/components/CountrySelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, {useEffect} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import styles from '../styles/styles';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import useLocalize from '../hooks/useLocalize';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import FormHelpMessage from './FormHelpMessage';

const propTypes = {
/** Form error text. e.g when no country is selected */
errorText: PropTypes.string,

/** Callback called when the country changes. */
onInputChange: PropTypes.func.isRequired,

/** Current selected country */
value: PropTypes.string,

/** inputID used by the Form component */
// eslint-disable-next-line react/no-unused-prop-types
inputID: PropTypes.string.isRequired,

/** React ref being forwarded to the MenuItemWithTopDescription */
forwardedRef: PropTypes.func,
};

const defaultProps = {
errorText: '',
value: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting an empty string as default prevents the Form from passing the value. it has to be undefined

value: undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

forwardedRef: () => {},
};

function CountrySelector({errorText, value: countryCode, onInputChange, forwardedRef}) {
const {translate} = useLocalize();

const title = countryCode ? translate(`allCountries.${countryCode}`) : '';
const countryTitleDescStyle = title.length === 0 ? styles.textNormal : null;

useEffect(() => {
// This will cause the form to revalidate and remove any error related to country name
onInputChange(countryCode);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [countryCode]);
mountiny marked this conversation as resolved.
Show resolved Hide resolved

return (
<View>
<MenuItemWithTopDescription
shouldShowRightIcon
title={title}
ref={forwardedRef}
descriptionTextStyle={countryTitleDescStyle}
description={translate('common.country')}
onPress={() => {
const activeRoute = Navigation.getActiveRoute().replace(/\?.*/, '');
Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY.getRoute(countryCode, activeRoute));
}}
/>
<View style={styles.ml5}>
<FormHelpMessage message={errorText} />
</View>
</View>
);
}

CountrySelector.propTypes = propTypes;
CountrySelector.defaultProps = defaultProps;
CountrySelector.displayName = 'CountrySelector';

export default React.forwardRef((props, ref) => (
<CountrySelector
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
forwardedRef={ref}
/>
));
1 change: 1 addition & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const SettingsModalStackNavigator = createModalStackNavigator({
Settings_PersonalDetails_LegalName: () => require('../../../pages/settings/Profile/PersonalDetails/LegalNamePage').default,
Settings_PersonalDetails_DateOfBirth: () => require('../../../pages/settings/Profile/PersonalDetails/DateOfBirthPage').default,
Settings_PersonalDetails_Address: () => require('../../../pages/settings/Profile/PersonalDetails/AddressPage').default,
Settings_PersonalDetails_Address_Country: () => require('../../../pages/settings/Profile/PersonalDetails/CountrySelectionPage').default,
Settings_ContactMethods: () => require('../../../pages/settings/Profile/Contacts/ContactMethodsPage').default,
Settings_ContactMethodDetails: () => require('../../../pages/settings/Profile/Contacts/ContactMethodDetailsPage').default,
Settings_NewContactMethod: () => require('../../../pages/settings/Profile/Contacts/NewContactMethodPage').default,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export default {
path: ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS,
exact: true,
},
Settings_PersonalDetails_Address_Country: {
path: ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY.route,
exact: true,
},
Settings_TwoFactorAuth: {
path: ROUTES.SETTINGS_2FA,
exact: true,
Expand Down
34 changes: 25 additions & 9 deletions src/pages/settings/Profile/PersonalDetails/AddressPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashGet from 'lodash/get';
import _ from 'underscore';
import React, {useState, useCallback} from 'react';
import React, {useState, useCallback, useEffect} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST';
Expand All @@ -15,13 +15,13 @@ import styles from '../../../../styles/styles';
import * as PersonalDetails from '../../../../libs/actions/PersonalDetails';
import * as ValidationUtils from '../../../../libs/ValidationUtils';
import AddressSearch from '../../../../components/AddressSearch';
import CountryPicker from '../../../../components/CountryPicker';
import StatePicker from '../../../../components/StatePicker';
import Navigation from '../../../../libs/Navigation/Navigation';
import ROUTES from '../../../../ROUTES';
import useLocalize from '../../../../hooks/useLocalize';
import usePrivatePersonalDetails from '../../../../hooks/usePrivatePersonalDetails';
import FullscreenLoadingIndicator from '../../../../components/FullscreenLoadingIndicator';
import CountrySelector from '../../../../components/CountrySelector';

const propTypes = {
/* Onyx Props */
Expand All @@ -37,6 +37,15 @@ const propTypes = {
country: PropTypes.string,
}),
}),

/** Route from navigation */
ygshbht marked this conversation as resolved.
Show resolved Hide resolved
route: PropTypes.shape({
/** Params from the route */
params: PropTypes.shape({
/** Currently selected country */
country: PropTypes.string,
}),
}).isRequired,
};

const defaultProps = {
Expand All @@ -59,10 +68,11 @@ function updateAddress(values) {
PersonalDetails.updateAddress(values.addressLine1.trim(), values.addressLine2.trim(), values.city.trim(), values.state.trim(), values.zipPostCode.trim().toUpperCase(), values.country);
}

function AddressPage({privatePersonalDetails}) {
function AddressPage({privatePersonalDetails, route}) {
usePrivatePersonalDetails();
const {translate} = useLocalize();
const [currentCountry, setCurrentCountry] = useState(PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country')));
const countryFromUrl = lodashGet(route, 'params.country');
const [currentCountry, setCurrentCountry] = useState(countryFromUrl || PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country')));
const isUSAForm = currentCountry === CONST.COUNTRY.US;
const zipSampleFormat = lodashGet(CONST.COUNTRY_ZIP_REGEX_DATA, [currentCountry, 'samples'], '');
const zipFormat = translate('common.zipCodeExampleFormat', {zipSampleFormat});
Expand Down Expand Up @@ -116,7 +126,7 @@ function AddressPage({privatePersonalDetails}) {
return errors;
}, []);

const handleAddressChange = (value, key) => {
const handleAddressChange = useCallback((value, key) => {
if (key !== 'country' && key !== 'state') {
return;
}
Expand All @@ -126,7 +136,14 @@ function AddressPage({privatePersonalDetails}) {
return;
}
setState(value);
};
}, []);

useEffect(() => {
if (!countryFromUrl) {
return;
}
handleAddressChange(countryFromUrl, 'country');
}, [countryFromUrl, handleAddressChange]);

return (
<ScreenWrapper
Expand Down Expand Up @@ -178,10 +195,9 @@ function AddressPage({privatePersonalDetails}) {
/>
<View style={styles.formSpaceVertical} />
<View style={styles.mhn5}>
<CountryPicker
<CountrySelector
inputID="country"
defaultValue={currentCountry}
onValueChange={handleAddressChange}
value={currentCountry}
/>
</View>
<View style={styles.formSpaceVertical} />
Expand Down
Loading
Loading