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/28007: City field is not clear when choosing new country #28362

Merged
Show file tree
Hide file tree
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
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: '',
Comment on lines +211 to +212
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ollyws This minor change is to make sure that when selecting address, the country is updated first. Because state and city are reset after country change

Copy link
Contributor

@Ollyws Ollyws Sep 28, 2023

Choose a reason for hiding this comment

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

I think this breaks the country selection when you select an address, notice the country remains the same:

Country_example.mp4
VIDEO

Copy link
Contributor Author

@DylanDylann DylanDylann Sep 29, 2023

Choose a reason for hiding this comment

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

@Ollyws

I think this breaks the country selection when you select an address, notice the country remains the same

I think this bug is related to PR #26742. Just tested in staging https://staging.new.expensify.com/ and encountered the same issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah so it is, feel free to report it as a bug if it hasn't been already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will report when i have a chance

// 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
Loading