Skip to content
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

Merged
merged 7 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ const CONST = {
CARD_NUMBER: /^[0-9]{15,16}$/,
CARD_SECURITY_CODE: /^[0-9]{3,4}$/,
CARD_EXPIRATION_DATE: /(0[1-9]|10|11|12)\/20[0-9]{2}$/,
PAYPAL_ME_USERNAME: /^[a-zA-Z0-9]*$/,

// Adapted from: https://gist.github.com/dperini/729294
// eslint-disable-next-line max-len
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export default {
addPayPalAccount: 'Add PayPal account',
editPayPalAccount: 'Update PayPal account',
growlMessageOnSave: 'Your PayPal username was successfully added',
formatError: 'Invalid PayPal.me username',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Sorry for being Nit-picky. but this does not sound friendly. You can ask this on Slack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked, lets see if we get any response. Any suggestions from your side?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really good with content but this is not really blocking this so if you don't get any feedback, then it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay got it. Thanks for the help.

},
addDebitCardPage: {
addADebitCard: 'Add a Debit Card',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 PayPal.me no válido',
},
addDebitCardPage: {
addADebitCard: 'Agregar una tarjeta de débito',
Expand Down
25 changes: 25 additions & 0 deletions src/pages/settings/Payments/AddPayPalMePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to ValidationUtils.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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={() => {
Expand Down Expand Up @@ -92,6 +114,9 @@ class AddPayPalMePage extends React.Component {
placeholder={this.props.translate('addPayPalMePage.yourPayPalUsername')}
onChangeText={text => this.setState({payPalMeUsername: text})}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clear the error on the onChangeText

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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') : ''}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/>
</View>
</View>
Expand Down