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

CreditCardNumber field should report cardType #189

Merged
merged 2 commits into from
Apr 19, 2017

Conversation

TroyAlford
Copy link

No description provided.

@@ -71,7 +71,7 @@ export default class CreditCardNumber extends Component {

Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated toI'm thinking this parsing logic might be better outside of the React component - can we make separate JS file in react-gears for this? Would be easier to test and update too.

Copy link
Author

Choose a reason for hiding this comment

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

The parsing logic is already outside the component - it's handled by an external lib. I'm also reticent to refactor just for refactoring sake - is there a use-case that the current implementation doesn't support?

@@ -71,7 +71,7 @@ export default class CreditCardNumber extends Component {

// Only accept the change if we recognize the card type, and it is/may be valid
if (!this.props.restrictInput || cardType && (isValid || isPotentiallyValid)) {
this.props.onChange(value, isValid);
this.props.onChange(value, isValid, card.type);
Copy link
Contributor

Choose a reason for hiding this comment

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

If cardType and card.type are same can we combine or use one or the other here vs both?

Copy link
Author

Choose a reason for hiding this comment

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

They are not the same. cardType is the icon name and card.type is the name returned by the card parsing library. I'll rename cardType to be more clear.

@balloob
Copy link

balloob commented Apr 19, 2017

I think that this component is going the wrong direction. We should think in layers and very small ones.

Component A - the view: a component that allows users to type in a credit card and that shows an icon. This component will do it's own parsing of the card number to see which icon to show. Changes will be notified via an onChange handler that passes just the current value.

Component B - the validator: It renders component A and listens to onChange. If something is invalid, it will add has-danger to itself, Bootstrap styling will then color the form-control automatically red.

Component A is what can be in React-Gears. Component B is better fitted in people's own code base. For credit card validation there is a simple dependency that each can install and also each consumer of the component can decide which cards to accept.

@gthomas-appfolio
Copy link
Contributor

Agreed with @balloob 's comment above, let's work on this pattern for our form fields in next releases

@gthomas-appfolio gthomas-appfolio merged commit 5c40623 into master Apr 19, 2017
@gthomas-appfolio gthomas-appfolio deleted the feature/credit-card-number-reports-type branch April 19, 2017 21:26
@TroyAlford
Copy link
Author

That seems like a nice abstraction for the future, sure. There are 2 libs involved in parsing / validating the CC number.

Essentially, in the description above - Component A would only use credit-card-type - to find out the formatting rules and such.

Component B would then call card-validator to determine the validity and such.

I'd be happy to contribute to another PR to make this split.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants