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

Add slash in Debit card expiration #7362

Merged
merged 27 commits into from
Apr 13, 2022
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
91b17fa
fix: Added instance var and insertStringAt utils
mananjadhav Jan 21, 2022
42b9524
fix: Added onKeyPress and onChangeText for slash handling
mananjadhav Jan 21, 2022
e584b66
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Feb 21, 2022
5d29dd7
fix: Changed the auto slash logic for length
mananjadhav Feb 21, 2022
f334014
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Mar 7, 2022
61b79ee
feat: moved the auto slash code to separate functions
mananjadhav Mar 7, 2022
c547151
fix: added funcs to this
mananjadhav Mar 7, 2022
a84ede9
fix: handle delete slash when its the last char
mananjadhav Mar 7, 2022
77fd124
fix: Code cleanup
mananjadhav Mar 7, 2022
b1177c1
fix: added comment to functions
mananjadhav Mar 7, 2022
e0c7020
fix: change event to e.nativeEvent
mananjadhav Mar 7, 2022
d8b345f
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Mar 10, 2022
578ec9e
fix: changed setstate to clearErrorAndSetValue, temp console added
mananjadhav Mar 10, 2022
eee0bed
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Mar 14, 2022
88d83b4
fix: length check to > 2 for expirationdate
mananjadhav Mar 14, 2022
b51bb24
fix: removed keyup handling and update addslash function
mananjadhav Mar 21, 2022
0c45288
fix: update binding and remove console log
mananjadhav Mar 21, 2022
3ca97a1
fix: updated comment
mananjadhav Mar 21, 2022
b00729a
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Mar 23, 2022
eba7a98
fix: updated auto-slash logic to onChangeText
mananjadhav Mar 23, 2022
a5b8a5b
fix: removed unwanted var
mananjadhav Mar 24, 2022
80bdec7
fix: comment alignment fixed
mananjadhav Mar 24, 2022
b9069d5
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Mar 24, 2022
bfb9491
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Apr 11, 2022
6beb3d8
fix: remove unwanted variable
mananjadhav Apr 12, 2022
0b3ed72
Merge branch 'main' of https://github.com/mananjadhav/App into fix/au…
mananjadhav Apr 12, 2022
49956d7
refactor: changed comment language
mananjadhav Apr 13, 2022
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
33 changes: 32 additions & 1 deletion src/pages/settings/Payments/AddDebitCardPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {Component} from 'react';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
import lodashEndsWith from 'lodash/endsWith';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -91,6 +92,7 @@ class DebitCardPage extends Component {
this.submit = this.submit.bind(this);
this.clearErrorAndSetValue = this.clearErrorAndSetValue.bind(this);
this.getErrorText = this.getErrorText.bind(this);
this.addOrRemoveSlashToExpiryDate = this.addOrRemoveSlashToExpiryDate.bind(this);
}

/**
Expand Down Expand Up @@ -184,6 +186,35 @@ class DebitCardPage extends Component {
}));
}

/**
* @param {String} inputExpiryDate
*/
addOrRemoveSlashToExpiryDate(inputExpiryDate) {
this.setState((prevState) => {
let expiryDate = inputExpiryDate;

// Remove the digit and '/' when backspace is pressed with expiry date ending with '/'
if (inputExpiryDate.length < prevState.expirationDate.length
&& (((inputExpiryDate.length === 3 && lodashEndsWith(inputExpiryDate, '/'))
|| (inputExpiryDate.length === 2 && lodashEndsWith(prevState.expirationDate, '/'))))) {
expiryDate = inputExpiryDate.substring(0, inputExpiryDate.length - 1);
} else if (inputExpiryDate.length === 2 && _.indexOf(inputExpiryDate, '/') === -1) {
// An Expiry Date was added, so we should append a slash '/'
expiryDate = `${inputExpiryDate}/`;
} else if (inputExpiryDate.length > 2 && _.indexOf(inputExpiryDate, '/') === -1) {
// Expiry Date with MM and YY without slash, hence adding slash(/)
expiryDate = `${inputExpiryDate.slice(0, 2)}/${inputExpiryDate.slice(2)}`;
}
return {
expirationDate: expiryDate,
errors: {
...prevState.errors,
expirationDate: false,
},
};
});
}

render() {
return (
<ScreenWrapper>
Expand Down Expand Up @@ -217,11 +248,11 @@ class DebitCardPage extends Component {
<TextInput
label={this.props.translate('addDebitCardPage.expiration')}
placeholder={this.props.translate('addDebitCardPage.expirationDate')}
onChangeText={expirationDate => this.clearErrorAndSetValue('expirationDate', expirationDate)}
value={this.state.expirationDate}
maxLength={7}
errorText={this.getErrorText('expirationDate')}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
onChangeText={this.addOrRemoveSlashToExpiryDate}
/>
</View>
<View style={[styles.flex1]}>
Expand Down