-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Update Address search - show all inputs #6569
Changes from 7 commits
2865a78
8f8d148
32a9eb9
91920d6
bf63468
0ea709a
9295c47
27b0d84
3f73b08
5adf0c2
7d44cd8
d7ac198
93642a8
0865523
b0fe744
f8377ad
aed7b8c
e7ff88a
fd5316e
3fd626a
c30f08a
ec758cc
8466121
3cddfcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -206,7 +206,7 @@ function isValidURL(url) { | |||||
* @returns {Object} | ||||||
*/ | ||||||
function validateIdentity(identity) { | ||||||
const requiredFields = ['firstName', 'lastName', 'street', 'city', 'zipCode', 'state', 'ssnLast4', 'dob']; | ||||||
const requiredFields = ['firstName', 'lastName', 'addressStreet', 'addressCity', 'addressZipCode', 'addressState', 'ssnLast4', 'dob']; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is because I changed these names in the IdentityForm.js for consistency, see lines: App/src/pages/ReimbursementAccount/IdentityForm.js Lines 155 to 156 in 970c2d5
IdentityForm is reading values using one key (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unsure what is hard to follow or update, but won't we have to "rename" again if something else decides to use this method which is meant to be generic? Could be better to just leave it generic and then pass in fields we want to validate regardless of what they are named. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, looking at it again, this function could really stay as it is. The thing that was confusing is the IdentityForm reading an input with one key and then calling "onFieldChange" with another key. |
||||||
const errors = {}; | ||||||
|
||||||
// Check that all required fields are filled | ||||||
|
@@ -217,12 +217,12 @@ function validateIdentity(identity) { | |||||
errors[fieldName] = true; | ||||||
}); | ||||||
|
||||||
if (!isValidAddress(identity.street)) { | ||||||
errors.street = true; | ||||||
if (!isValidAddress(identity.addressStreet)) { | ||||||
errors.addressStreet = true; | ||||||
} | ||||||
|
||||||
if (!isValidZipCode(identity.zipCode)) { | ||||||
errors.zipCode = true; | ||||||
if (!isValidZipCode(identity.addressZipCode)) { | ||||||
errors.addressZipCode = true; | ||||||
} | ||||||
|
||||||
// dob field has multiple validations/errors, we are handling it temporarily like this. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,24 +59,28 @@ class ACHContractStep extends React.Component { | |
certifyTrueInformation: 'beneficialOwnersStep.error.certify', | ||
}; | ||
|
||
this.getErrors = () => ReimbursementAccountUtils.getErrors(this.props); | ||
this.clearError = inputKey => ReimbursementAccountUtils.clearError(this.props, inputKey); | ||
this.clearErrors = values => ReimbursementAccountUtils.clearErrors(this.props, values); | ||
this.getErrorText = inputKey => ReimbursementAccountUtils.getErrorText(this.props, this.errorTranslationKeys, inputKey); | ||
} | ||
|
||
/** | ||
* @returns {Object} | ||
*/ | ||
getErrors() { | ||
return lodashGet(this.props, ['reimbursementAccount', 'errors'], {}); | ||
} | ||
|
||
/** | ||
* @returns {Boolean} | ||
*/ | ||
validate() { | ||
let beneficialOwnersErrors = []; | ||
if (this.state.hasOtherBeneficialOwners) { | ||
beneficialOwnersErrors = _.map(this.state.beneficialOwners, ValidationUtils.validateIdentity); | ||
beneficialOwnersErrors = _.map(this.state.beneficialOwners, beneficialOwner => ValidationUtils.validateIdentity({ | ||
firstName: beneficialOwner.firstName, | ||
lastName: beneficialOwner.lastName, | ||
addressStreet: beneficialOwner.street, | ||
addressState: beneficialOwner.state, | ||
addressCity: beneficialOwner.city, | ||
addressZipCode: beneficialOwner.zipCode, | ||
dob: beneficialOwner.dob, | ||
ssnLast4: beneficialOwner.ssnLast4, | ||
aldo-expensify marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})); | ||
} | ||
|
||
const errors = {}; | ||
|
@@ -122,29 +126,44 @@ class ACHContractStep extends React.Component { | |
* Clear the error associated to inputKey if found and store the inputKey new value in the state. | ||
* | ||
* @param {Integer} ownerIndex | ||
* @param {String} inputKey | ||
* @param {String} value | ||
* @param {Object} values | ||
*/ | ||
clearErrorAndSetBeneficialOwnerValue(ownerIndex, inputKey, value) { | ||
clearErrorAndSetBeneficialOwnerValues(ownerIndex, values) { | ||
this.setState((prevState) => { | ||
const renamedFields = { | ||
addressStreet: 'street', | ||
addressCity: 'city', | ||
addressState: 'state', | ||
addressZipCode: 'zipCode', | ||
}; | ||
const renamedInputKey = lodashGet(renamedFields, inputKey, inputKey); | ||
const beneficialOwners = [...prevState.beneficialOwners]; | ||
beneficialOwners[ownerIndex] = {...beneficialOwners[ownerIndex], [renamedInputKey]: value}; | ||
_.each(values, (value, inputKey) => { | ||
const renamedInputKey = lodashGet(renamedFields, inputKey, inputKey); | ||
beneficialOwners[ownerIndex] = {...beneficialOwners[ownerIndex], [renamedInputKey]: value}; | ||
}); | ||
BankAccounts.updateReimbursementAccountDraft({beneficialOwners}); | ||
return {beneficialOwners}; | ||
}); | ||
|
||
// Prepare inputKeys for clearing errors | ||
const inputKeys = _.keys(values); | ||
|
||
// dob field has multiple validations/errors, we are handling it temporarily like this. | ||
if (inputKey === 'dob') { | ||
this.clearError(`beneficialOwnersErrors.${ownerIndex}.dobAge`); | ||
if (_.contains(inputKeys, 'dob')) { | ||
inputKeys.push('dobAge'); | ||
} | ||
this.clearError(`beneficialOwnersErrors.${ownerIndex}.${inputKey}`); | ||
this.clearErrors(_.map(inputKeys, inputKey => `beneficialOwnersErrors.${ownerIndex}.${inputKey}`)); | ||
} | ||
|
||
/** | ||
* Clear the error associated to inputKey if found and store the inputKey new value in the state. | ||
* | ||
* @param {Integer} ownerIndex | ||
* @param {String} inputKey | ||
* @param {String} value | ||
*/ | ||
clearErrorAndSetBeneficialOwnerValue(ownerIndex, inputKey, value) { | ||
this.clearErrorAndSetBeneficialOwnerValues(ownerIndex, {[inputKey]: value}); | ||
} | ||
|
||
submit() { | ||
|
@@ -233,14 +252,20 @@ class ACHContractStep extends React.Component { | |
</Text> | ||
<IdentityForm | ||
style={[styles.mb2]} | ||
onFieldChange={(inputKey, value) => this.clearErrorAndSetBeneficialOwnerValue(index, inputKey, value)} | ||
onFieldChange={(inputKeyOrValues, value) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having What if we just return an object and have the validation and error clearing handled all at the same time for the various fields? Sorry to sound like a broken record, but the way we validate these will be changing soon in pretty drastic ways so maybe we should not spend much time perfecting this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed, didn't liked it, but it was what I came up with to solve the clearing multiple errors in a batch.
the idea is to ALWAYS pass an object to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: |
||
if (_.isString(inputKeyOrValues)) { | ||
this.clearErrorAndSetBeneficialOwnerValue(index, inputKeyOrValues, value); | ||
} else { | ||
this.clearErrorAndSetBeneficialOwnerValues(index, inputKeyOrValues); | ||
} | ||
}} | ||
values={{ | ||
firstName: owner.firstName || '', | ||
lastName: owner.lastName || '', | ||
street: owner.street || '', | ||
city: owner.city || '', | ||
state: owner.state || '', | ||
zipCode: owner.zipCode || '', | ||
addressStreet: owner.street || '', | ||
addressState: owner.state || '', | ||
addressCity: owner.city || '', | ||
addressZipCode: owner.zipCode || '', | ||
aldo-expensify marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dob: owner.dob || '', | ||
ssnLast4: owner.ssnLast4 || '', | ||
}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not saying this is likely but example of how this could go wrong in the future...
onChangeText
never firesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opened an issue here FaridSafi/react-native-google-places-autocomplete#786