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

Fixed address clear detected & modified the state #5954

Merged
merged 5 commits into from
Oct 22, 2021
Merged
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/components/AddressSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ const AddressSearch = (props) => {
label: props.label,
containerStyles: props.containerStyles,
errorText: props.errorText,
onChangeText: (text) => {
// Ensure whether an address is selected already has address value initialized.
if (!_.isEmpty(googlePlacesRef.current.getAddressText())) {
if (_.isEmpty(text) || !_.isEqual(text, props.value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I'm confused why we're clearing the value if text is not the same as props.value. Can you help me understand?

Also NAB because this is personal preference, but I'm not a fan of the nested if statements – I think something like this would be slightly clearer:

const isTextValid = !_.isEmpty(text) && _.isEqual(text, props.value);
if (!_.isEmpty(googlePlacesRef.current.getAddressText()) && !isTextValid) {
    saveLocationDetails({});
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm confused why we're clearing the value if text is not the same as props.value. Can you help me understand?

Because it text will change whenever you modify the address input & props.value will update only if the address is selected in the autocomplete list.

Yes, it makes sense I'll update the suggested changes here.

saveLocationDetails({});
}
}
},
}}
styles={{
textInputContainer: [styles.flexColumn],
Expand Down