Skip to content

Commit

Permalink
fix: state field not clear after selecting another country
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Aug 4, 2023
1 parent 65ee88e commit d7db87b
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 @@ -69,7 +69,7 @@ function AddressPage({privatePersonalDetails}) {

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 @@ -116,10 +116,15 @@ function AddressPage({privatePersonalDetails}) {
}, []);

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 @@ -182,7 +187,8 @@ function AddressPage({privatePersonalDetails}) {
<View style={styles.mhn5}>
<StatePicker
inputID="state"
defaultValue={address.state}
defaultValue={state}
onValueChange={handleAddressChange}
/>
</View>
) : (
Expand All @@ -191,9 +197,10 @@ function AddressPage({privatePersonalDetails}) {
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 d7db87b

Please sign in to comment.