Skip to content

Commit

Permalink
Merge pull request #9495 from thesahindia/thesahindia/fix-error-message
Browse files Browse the repository at this point in the history
Add specific error messages for additional details page
  • Loading branch information
AndrewGable authored Jul 8, 2022
2 parents 0fcc492 + 35454e1 commit 3ee772b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ export default {
legalMiddleNameLabel: 'Legal middle name',
legalLastNameLabel: 'Legal last name',
selectAnswer: 'You need to select a response to proceed.',
ssnFull9Error: 'Please enter a valid 9 digit SSN',
needSSNFull9: 'We\'re having trouble verifying your SSN. Please enter the full 9 digits of your SSN.',
weCouldNotVerify: 'We could not verify',
pleaseFixIt: 'Please fix this information before continuing.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ export default {
legalMiddleNameLabel: 'Segundo nombre legal',
legalLastNameLabel: 'Apellido legal',
selectAnswer: 'Selecciona una respuesta.',
ssnFull9Error: 'Por favor escribe los 9 dígitos de un SSN válido',
needSSNFull9: 'Estamos teniendo problemas para verificar su SSN. Ingresa los 9 dígitos del SSN.',
weCouldNotVerify: 'No pudimos verificar',
pleaseFixIt: 'Corrije esta información antes de continuar.',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function validateIdentity(identity) {
* @param {Boolean} [isCountryCodeOptional]
* @returns {Boolean}
*/
function isValidUSPhone(phoneNumber, isCountryCodeOptional) {
function isValidUSPhone(phoneNumber = '', isCountryCodeOptional) {
// Remove non alphanumeric characters from the phone number
const sanitizedPhone = phoneNumber.replace(CONST.REGEX.NON_ALPHA_NUMERIC, '');
const isUsPhone = isCountryCodeOptional
Expand Down
54 changes: 48 additions & 6 deletions src/pages/EnablePayments/AdditionalDetailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ class AdditionalDetailsStep extends React.Component {
'ssn',
];

this.errorTranslationKeys = {
legalFirstName: 'bankAccount.error.firstName',
legalLastName: 'bankAccount.error.lastName',
addressStreet: 'bankAccount.error.addressStreet',
addressCity: 'bankAccount.error.addressCity',
addressState: 'bankAccount.error.addressState',
addressZip: 'bankAccount.error.zipCode',
phoneNumber: 'bankAccount.error.phoneNumber',
dob: 'bankAccount.error.dob',
age: 'bankAccount.error.age',
ssn: 'bankAccount.error.ssnLast4',
ssnFull9: 'additionalDetailsStep.ssnFull9Error',
};

this.fieldNameTranslationKeys = {
legalFirstName: 'additionalDetailsStep.legalFirstNameLabel',
legalLastName: 'additionalDetailsStep.legalLastNameLabel',
Expand Down Expand Up @@ -141,7 +155,7 @@ class AdditionalDetailsStep extends React.Component {
return '';
}

return `${this.props.translate(this.fieldNameTranslationKeys[fieldName])} ${this.props.translate('common.isRequiredField')}.`;
return this.props.translate(this.errorTranslationKeys[fieldName]);
}

/**
Expand All @@ -164,6 +178,10 @@ class AdditionalDetailsStep extends React.Component {
errors.dob = true;
}

if (!ValidationUtils.meetsAgeRequirements(this.props.walletAdditionalDetailsDraft.dob)) {
errors.age = true;
}

if (!ValidationUtils.isValidAddress(this.props.walletAdditionalDetailsDraft.addressStreet)) {
errors.addressStreet = true;
}
Expand All @@ -172,7 +190,11 @@ class AdditionalDetailsStep extends React.Component {
errors.phoneNumber = true;
}

if (!ValidationUtils.isValidSSNLastFour(this.props.walletAdditionalDetailsDraft.ssn) && !ValidationUtils.isValidSSNFullNine(this.props.walletAdditionalDetailsDraft.ssn)) {
if (this.props.walletAdditionalDetails.shouldAskForFullSSN) {
if (!ValidationUtils.isValidSSNFullNine(this.props.walletAdditionalDetailsDraft.ssn)) {
errors.ssnFull9 = true;
}
} else if (!ValidationUtils.isValidSSNLastFour(this.props.walletAdditionalDetailsDraft.ssn)) {
errors.ssn = true;
}

Expand Down Expand Up @@ -201,6 +223,26 @@ class AdditionalDetailsStep extends React.Component {
});
}

/**
* Clear both errors associated with dob, and set the new value.
*
* @param {String} value
*/
clearDateErrorsAndSetValue(value) {
this.formHelper.clearErrors(this.props, ['dob', 'age']);
Wallet.updateAdditionalDetailsDraft({dob: value});
}

/**
* Clear ssn and ssnFull9 error and set the new value
*
* @param {String} value
*/
clearSSNErrorAndSetValue(value) {
this.formHelper.clearErrors(this.props, ['ssn', 'ssnFull9']);
Wallet.updateAdditionalDetailsDraft({ssn: value});
}

/**
* @param {String} fieldName
* @param {String} value
Expand Down Expand Up @@ -327,18 +369,18 @@ class AdditionalDetailsStep extends React.Component {
<DatePicker
containerStyles={[styles.mt4]}
label={this.props.translate(this.fieldNameTranslationKeys.dob)}
onInputChange={val => this.clearErrorAndSetValue('dob', val)}
onInputChange={val => this.clearDateErrorsAndSetValue(val)}
defaultValue={this.props.walletAdditionalDetailsDraft.dob || ''}
placeholder={this.props.translate('common.dob')}
errorText={this.getErrorText('dob')}
errorText={this.getErrorText('dob') || this.getErrorText('age')}
maximumDate={new Date()}
/>
<TextInput
containerStyles={[styles.mt4]}
label={this.props.translate(this.fieldNameTranslationKeys[shouldAskForFullSSN ? 'ssnFull9' : 'ssn'])}
onChangeText={val => this.clearErrorAndSetValue('ssn', val)}
onChangeText={val => this.clearSSNErrorAndSetValue(val)}
value={this.props.walletAdditionalDetailsDraft.ssn || ''}
errorText={this.getErrorText('ssn')}
errorText={this.getErrorText('ssnFull9') || this.getErrorText('ssn')}
maxLength={shouldAskForFullSSN ? 9 : 4}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
/>
Expand Down

0 comments on commit 3ee772b

Please sign in to comment.