Skip to content

Commit

Permalink
Merge pull request #28362 from DylanDylann/fix/28007-city-field-is-no…
Browse files Browse the repository at this point in the history
…t-clear-when-select-another-country

Fix/28007: City field is not clear when choosing new country
  • Loading branch information
AndrewGable authored Oct 2, 2023
2 parents 01f8e40 + 42c0743 commit ec94bae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/components/AddressSearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ function AddressSearch(props) {

// Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise.
street2: subpremise,

// Make sure country is updated first, since city and state will be reset if the country changes
country: '',
// When locality is not returned, many countries return the city as postalTown (e.g. 5 New Street
// Square, London), otherwise as sublocality (e.g. 384 Court Street Brooklyn). If postalTown is
// returned, the sublocality will be a city subdivision so shouldn't take precedence (e.g.
// Salagatan, Upssala, Sweden).
city: locality || postalTown || sublocality || cityAutocompleteFallback,
zipCode,
country: '',

state: state || stateAutoCompleteFallback,
lat: lodashGet(details, 'geometry.location.lat', 0),
lng: lodashGet(details, 'geometry.location.lng', 0),
Expand Down
13 changes: 10 additions & 3 deletions src/pages/settings/Profile/PersonalDetails/AddressPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function AddressPage({privatePersonalDetails, route}) {
const isLoadingPersonalDetails = lodashGet(privatePersonalDetails, 'isLoading', true);
const [street1, street2] = (address.street || '').split('\n');
const [state, setState] = useState(address.state);
const [city, setCity] = useState(address.city);

useEffect(() => {
if (!address) {
Expand Down Expand Up @@ -135,15 +136,20 @@ function AddressPage({privatePersonalDetails, route}) {
}, []);

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

useEffect(() => {
Expand Down Expand Up @@ -235,9 +241,10 @@ function AddressPage({privatePersonalDetails, route}) {
label={translate('common.city')}
accessibilityLabel={translate('common.city')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
defaultValue={address.city || ''}
value={city || ''}
maxLength={CONST.FORM_CHARACTER_LIMIT}
spellCheck={false}
onValueChange={handleAddressChange}
/>
<View style={styles.formSpaceVertical} />
<TextInput
Expand Down

0 comments on commit ec94bae

Please sign in to comment.