-
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
Paypal username field validation #5842
Changes from 2 commits
5c9f6e9
cbdad42
c4a4a0f
a1e8ce1
9a0b0b3
592ea97
85444ab
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 |
---|---|---|
|
@@ -282,6 +282,7 @@ export default { | |
addPayPalAccount: 'Agregar cuenta de PayPal', | ||
growlMessageOnSave: 'Su nombre de usuario de PayPal se agregó correctamente', | ||
editPayPalAccount: 'Actualizar cuenta de PayPal', | ||
formatError: 'Usuario PayPa.me no válido', | ||
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. Also missing the |
||
}, | ||
addDebitCardPage: { | ||
addADebitCard: 'Agregar una tarjeta de débito', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,10 @@ class AddPayPalMePage extends React.Component { | |
|
||
this.state = { | ||
payPalMeUsername: props.payPalMeUsername, | ||
payPalMeUsernameError: false, | ||
}; | ||
this.setPayPalMeUsername = this.setPayPalMeUsername.bind(this); | ||
this.validatePaypalMeUsername = this.validatePaypalMeUsername.bind(this); | ||
this.paypalUsernameInputRef = null; | ||
} | ||
|
||
|
@@ -58,11 +60,31 @@ class AddPayPalMePage extends React.Component { | |
* Sets the payPalMeUsername for the current user | ||
*/ | ||
setPayPalMeUsername() { | ||
const isValid = this.validatePaypalMeUsername(); | ||
if (!isValid) { | ||
return; | ||
} | ||
NameValuePair.set(CONST.NVP.PAYPAL_ME_ADDRESS, this.state.payPalMeUsername, ONYXKEYS.NVP_PAYPAL_ME_ADDRESS); | ||
Growl.show(this.props.translate('addPayPalMePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000); | ||
Navigation.navigate(ROUTES.SETTINGS_PAYMENTS); | ||
} | ||
|
||
/** | ||
* Validate the paypal username with regex | ||
* | ||
* @returns {Boolean} | ||
*/ | ||
validatePaypalMeUsername() { | ||
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. Let's move this to ValidationUtils.js 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. Done |
||
const regex = CONST.REGEX.PAYPAL_ME_USERNAME; | ||
if (this.state.payPalMeUsername && !regex.test(this.state.payPalMeUsername)) { | ||
this.setState({payPalMeUsernameError: true}); | ||
return false; | ||
} | ||
this.setState({payPalMeUsernameError: false}); | ||
return true; | ||
} | ||
|
||
|
||
render() { | ||
return ( | ||
<ScreenWrapper onTransitionEnd={() => { | ||
|
@@ -92,6 +114,9 @@ class AddPayPalMePage extends React.Component { | |
placeholder={this.props.translate('addPayPalMePage.yourPayPalUsername')} | ||
onChangeText={text => this.setState({payPalMeUsername: text})} | ||
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. Please clear the error on 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. done |
||
returnKeyType="done" | ||
hasError={this.state.payPalMeUsernameError} | ||
errorText={this.state.payPalMeUsernameError ? this.props.translate('addPayPalMePage.formatError') : ''} | ||
|
||
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. We can remove this empty line. 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. Done |
||
/> | ||
</View> | ||
</View> | ||
|
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.
Missing an
l
— should bePayPal.me