Skip to content

Commit

Permalink
Merge pull request #24148 from dukenv0307/fix/23839
Browse files Browse the repository at this point in the history
fix: state field not clear after selecting another country
  • Loading branch information
roryabraham authored Aug 8, 2023
2 parents dec9f16 + 559ff57 commit 0f83752
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/pages/settings/Profile/PersonalDetails/AddressPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function AddressPage({privatePersonalDetails, country}) {

const address = lodashGet(privatePersonalDetails, 'address') || {};
const [street1, street2] = (address.street || '').split('\n');

const [state, setState] = useState(address.state);
/**
* @param {Function} translate - translate function
* @param {Boolean} isUSAForm - selected country ISO code is US
Expand Down Expand Up @@ -120,10 +120,15 @@ function AddressPage({privatePersonalDetails, country}) {
}, []);

const handleAddressChange = (value, key) => {
if (key !== 'country') {
if (key !== 'country' && key !== 'state') {
return;
}
if (key === 'country') {
setCurrentCountry(value);
setState('');
return;
}
setCurrentCountry(value);
setState(value);
};

if (lodashGet(privatePersonalDetails, 'isLoading', true)) {
Expand Down Expand Up @@ -186,7 +191,8 @@ function AddressPage({privatePersonalDetails, country}) {
<View style={styles.mhn5}>
<StatePicker
inputID="state"
defaultValue={address.state}
defaultValue={state}
onValueChange={handleAddressChange}
/>
</View>
) : (
Expand All @@ -195,9 +201,10 @@ function AddressPage({privatePersonalDetails, country}) {
label={translate('common.stateOrProvince')}
accessibilityLabel={translate('common.stateOrProvince')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
defaultValue={address.state || ''}
value={state || ''}
maxLength={CONST.FORM_CHARACTER_LIMIT}
spellCheck={false}
onValueChange={handleAddressChange}
/>
)}
<View style={styles.formSpaceVertical} />
Expand Down

0 comments on commit 0f83752

Please sign in to comment.