Skip to content

Commit

Permalink
use function to get first and last name
Browse files Browse the repository at this point in the history
  • Loading branch information
thesahindia committed Oct 6, 2022
1 parent 8285888 commit 5fac43c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/pages/EnablePayments/AdditionalDetailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ class AdditionalDetailsStep extends React.Component {
});
}

getFirstName() {
const {firstName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(this.props.currentUserPersonalDetails);
return this.props.walletAdditionalDetailsDraft.legalFirstName || firstName;
}

getLastName() {
const {lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(this.props.currentUserPersonalDetails);
return this.props.walletAdditionalDetailsDraft.legalLastName || lastName;
}

/**
* @returns {Object}
*/
Expand Down Expand Up @@ -165,6 +175,14 @@ class AdditionalDetailsStep extends React.Component {

const errors = {};

if (!this.getFirstName()) {
errors.legalFirstName = true;
}

if (!this.getLastName()) {
errors.legalLastName = true;
}

if (!ValidationUtils.isValidPastDate(this.props.walletAdditionalDetailsDraft.dob)) {
errors.dob = true;
}
Expand Down Expand Up @@ -212,6 +230,8 @@ class AdditionalDetailsStep extends React.Component {
const personalDetails = {
...this.props.walletAdditionalDetailsDraft,
phoneNumber: LoginUtils.getPhoneNumberWithoutUSCountryCodeAndSpecialChars(this.props.walletAdditionalDetailsDraft.phoneNumber),
legalFirstName: this.getFirstName(),
legalLastName: this.getLastName(),
};
Wallet.updatePersonalDetails(personalDetails);
}
Expand Down Expand Up @@ -266,7 +286,6 @@ class AdditionalDetailsStep extends React.Component {
const errorMessage = ErrorUtils.getLatestErrorMessage(this.props.walletAdditionalDetails) || '';
const isErrorVisible = _.size(this.getErrors()) > 0 || Boolean(errorMessage);
const shouldAskForFullSSN = this.props.walletAdditionalDetails.errorCode === CONST.WALLET.ERROR.SSN;
const {firstName, lastName} = PersonalDetails.extractFirstAndLastNameFromAvailableDetails(this.props.currentUserPersonalDetails);

return (
<>
Expand All @@ -291,14 +310,14 @@ class AdditionalDetailsStep extends React.Component {
containerStyles={[styles.mt4]}
label={this.props.translate(this.fieldNameTranslationKeys.legalFirstName)}
onChangeText={val => this.clearErrorAndSetValue('legalFirstName', val)}
value={this.props.walletAdditionalDetailsDraft.legalFirstName || firstName}
value={this.getFirstName()}
errorText={this.getErrorText('legalFirstName')}
/>
<TextInput
containerStyles={[styles.mt4]}
label={this.props.translate(this.fieldNameTranslationKeys.legalLastName)}
onChangeText={val => this.clearErrorAndSetValue('legalLastName', val)}
value={this.props.walletAdditionalDetailsDraft.legalLastName || lastName}
value={this.getLastName()}
errorText={this.getErrorText('legalLastName')}
/>
<AddressForm
Expand Down

0 comments on commit 5fac43c

Please sign in to comment.