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

rerender country and state if visited via deep link #28404

Merged
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions src/pages/settings/Profile/PersonalDetails/AddressPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function AddressPage({privatePersonalDetails, route}) {
usePrivatePersonalDetails();
const {translate} = useLocalize();
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 All @@ -81,12 +80,23 @@ function AddressPage({privatePersonalDetails, route}) {
const isLoadingPersonalDetails = lodashGet(privatePersonalDetails, 'isLoading', true);
const [street1, street2] = (address.street || '').split('\n');
const [state, setState] = useState(address.state);
const [currentCountry, setCurrentCountry] = useState(PersonalDetails.getCountryISO(address.country));
Copy link
Contributor

Choose a reason for hiding this comment

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

There are some linter errors

image


saranshbalyan-1234 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @param {Function} translate - translate function
* @param {Boolean} isUSAForm - selected country ISO code is US
* @param {Object} values - form input values
* @returns {Object} - An object containing the errors for each inputID
*/

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There are some linter errors still
image

You can check those by running npm run lint (ignore the errors in /vendor/bundle/ruby)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the wrong place to put useEffect, it's currently between validate function and JSdoc for the said function

It should be placed after const [state, setState] = useState(address.state); (make sure there's an empty line above and below useEffect)

Copy link
Contributor

@eVoloshchak eVoloshchak Sep 29, 2023

Choose a reason for hiding this comment

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

image

if(!address) return
setState(address.state)
setCurrentCountry(address.country)
}, [address]);
saranshbalyan-1234 marked this conversation as resolved.
Show resolved Hide resolved

saranshbalyan-1234 marked this conversation as resolved.
Show resolved Hide resolved

const validate = useCallback((values) => {
const errors = {};
const requiredFields = ['addressLine1', 'city', 'country', 'state'];
Expand Down Expand Up @@ -256,4 +266,4 @@ export default withOnyx({
privatePersonalDetails: {
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
},
})(AddressPage);
})(AddressPage);
saranshbalyan-1234 marked this conversation as resolved.
Show resolved Hide resolved