Skip to content
New issue

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

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

Already on GitHub? # to your account

Resolve User Country Identification and Address Form Display Issue #23841

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 4 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export default {
// an international code
COUNTRY_CODE: 'countryCode',

// The 'country' field in this code represents the return country based on the user's IP address.
// It is expected to provide a two-letter country code such as US for United States, and so on.
COUNTRY: 'country',

// Contains all the users settings for the Settings page and sub pages
USER: 'user',

Expand Down
13 changes: 10 additions & 3 deletions src/pages/settings/Profile/PersonalDetails/AddressPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import FullscreenLoadingIndicator from '../../../../components/FullscreenLoading
const propTypes = {
/* Onyx Props */

// The user's country based on IP address
country: PropTypes.string,

/** User's private personal details */
privatePersonalDetails: PropTypes.shape({
/** User's home address */
Expand All @@ -40,6 +43,7 @@ const propTypes = {
};

const defaultProps = {
country: '',
privatePersonalDetails: {
address: {
street: '',
Expand All @@ -59,10 +63,10 @@ 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, country}) {
usePrivatePersonalDetails();
const {translate} = useLocalize();
const [currentCountry, setCurrentCountry] = useState(PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country')) || CONST.COUNTRY.US);
const [currentCountry, setCurrentCountry] = useState(PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country')) || country || CONST.COUNTRY.US);
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 @@ -172,7 +176,7 @@ function AddressPage({privatePersonalDetails}) {
<View style={styles.mhn5}>
<CountryPicker
inputID="country"
defaultValue={PersonalDetails.getCountryISO(address.country)}
defaultValue={currentCountry}
onValueChange={handleAddressChange}
/>
</View>
Expand Down Expand Up @@ -223,6 +227,9 @@ AddressPage.propTypes = propTypes;
AddressPage.defaultProps = defaultProps;

export default withOnyx({
country: {
key: ONYXKEYS.COUNTRY,
},
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
Expand Down