Skip to content

Commit

Permalink
Merge pull request #28404 from saranshbalyan-1234/rerender-country-st…
Browse files Browse the repository at this point in the history
…ate-on-address-page--deep-link

rerender country and state if visited via deep link
  • Loading branch information
techievivek authored Oct 2, 2023
2 parents e33bc0a + a70225e commit d16686d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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, useEffect} from 'react';
import React, {useState, useCallback, useEffect, useMemo} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST';
Expand Down Expand Up @@ -71,16 +71,24 @@ function updateAddress(values) {
function AddressPage({privatePersonalDetails, route}) {
usePrivatePersonalDetails();
const {translate} = useLocalize();
const address = useMemo(() => lodashGet(privatePersonalDetails, 'address') || {}, [privatePersonalDetails]);
const countryFromUrl = lodashGet(route, 'params.country');
const [currentCountry, setCurrentCountry] = useState(countryFromUrl || PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country')));
const isUSAForm = currentCountry === CONST.COUNTRY.US;
const [currentCountry, setCurrentCountry] = useState(address.country);
const zipSampleFormat = lodashGet(CONST.COUNTRY_ZIP_REGEX_DATA, [currentCountry, 'samples'], '');
const zipFormat = translate('common.zipCodeExampleFormat', {zipSampleFormat});

const address = lodashGet(privatePersonalDetails, 'address') || {};
const isUSAForm = currentCountry === CONST.COUNTRY.US;
const isLoadingPersonalDetails = lodashGet(privatePersonalDetails, 'isLoading', true);
const [street1, street2] = (address.street || '').split('\n');
const [state, setState] = useState(address.state);

useEffect(() => {
if (!address) {
return;
}
setState(address.state);
setCurrentCountry(address.country);
}, [address]);

/**
* @param {Function} translate - translate function
* @param {Boolean} isUSAForm - selected country ISO code is US
Expand Down

0 comments on commit d16686d

Please sign in to comment.