Skip to content
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
7 changes: 5 additions & 2 deletions src/components/AddressSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ const AddressSearch = (props) => {
const state = GooglePlacesUtils.getAddressComponent(addressComponents, 'administrative_area_level_1', 'short_name');

const values = {};
if (street && street.length > props.value.length) {
// Don't replace if the user has typed something longer. I.e. maybe the user entered the Apt #
if (street && street.length > props.value.trim().length) {
// We are only passing the street number and name if the combined length is longer than the value
// that was initially passed to the autocomplete component. Google Places can truncate details
// like Apt # and this is the best way we have to tell that the new value it's giving us is less
// specific than the one the user entered manually.
values.street = street;
}
if (city) {
Expand Down
16 changes: 7 additions & 9 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ class CompanyStep extends React.Component {
hasNoConnectionToCannabis: 'bankAccount.error.restrictedBusiness',
};

// AddressSearch uses different keys for these fields
this.renamedFields = {
street: 'addressStreet',
state: 'addressState',
city: 'addressCity',
zipCode: 'addressZipCode',
};

this.getErrorText = inputKey => ReimbursementAccountUtils.getErrorText(this.props, this.errorTranslationKeys, inputKey);
this.clearError = inputKey => ReimbursementAccountUtils.clearError(this.props, inputKey);
this.clearErrors = inputKeys => ReimbursementAccountUtils.clearErrors(this.props, inputKeys);
Expand Down Expand Up @@ -226,9 +218,15 @@ class CompanyStep extends React.Component {
state: this.getErrors().addressState,
}}
onFieldChange={(values) => {
const renamedFields = {
street: 'addressStreet',
state: 'addressState',
city: 'addressCity',
zipCode: 'addressZipCode',
};
const renamedValues = {};
_.each(values, (value, inputKey) => {
const renamedInputKey = lodashGet(this.renamedFields, inputKey, inputKey);
const renamedInputKey = lodashGet(renamedFields, inputKey, inputKey);
renamedValues[renamedInputKey] = value;
});
this.setValue(renamedValues);
Expand Down