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

fix: state field not clear after selecting another country #24148

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Changes from all 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
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
Loading