@thecb/components 4.2.0 → 4.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js
CHANGED
|
@@ -6104,6 +6104,35 @@ var checkCardBrand = function checkCardBrand(number) {
|
|
|
6104
6104
|
return "AMEX";
|
|
6105
6105
|
} else return "UNKNOWN";
|
|
6106
6106
|
};
|
|
6107
|
+
var displayCardBrand = function displayCardBrand(number) {
|
|
6108
|
+
if (/^6011/.test(number)) {
|
|
6109
|
+
return "Discover";
|
|
6110
|
+
} else if (/^5[1-5]/.test(number)) {
|
|
6111
|
+
return "Mastercard";
|
|
6112
|
+
} else if (/^4/.test(number)) {
|
|
6113
|
+
return "Visa";
|
|
6114
|
+
} else if (/^3[4,7]/.test(number)) {
|
|
6115
|
+
return "American Express";
|
|
6116
|
+
} else return "Unknown Card";
|
|
6117
|
+
};
|
|
6118
|
+
var checkRestrictedCards = function checkRestrictedCards(name) {
|
|
6119
|
+
switch (name) {
|
|
6120
|
+
case "DISCOVER":
|
|
6121
|
+
return /^(?!6011)/;
|
|
6122
|
+
|
|
6123
|
+
case "MASTERCARD":
|
|
6124
|
+
return /^(?!5[1-5])/;
|
|
6125
|
+
|
|
6126
|
+
case "VISA":
|
|
6127
|
+
return /^(?!4)/;
|
|
6128
|
+
|
|
6129
|
+
case "AMEX":
|
|
6130
|
+
return /^(?!3[4,7])/;
|
|
6131
|
+
|
|
6132
|
+
default:
|
|
6133
|
+
return "";
|
|
6134
|
+
}
|
|
6135
|
+
};
|
|
6107
6136
|
|
|
6108
6137
|
var general = /*#__PURE__*/Object.freeze({
|
|
6109
6138
|
__proto__: null,
|
|
@@ -6112,7 +6141,9 @@ var general = /*#__PURE__*/Object.freeze({
|
|
|
6112
6141
|
convertCentsToMoneyInt: convertCentsToMoneyInt,
|
|
6113
6142
|
safeChildren: safeChildren,
|
|
6114
6143
|
generateClickHandler: generateClickHandler,
|
|
6115
|
-
checkCardBrand: checkCardBrand
|
|
6144
|
+
checkCardBrand: checkCardBrand,
|
|
6145
|
+
displayCardBrand: displayCardBrand,
|
|
6146
|
+
checkRestrictedCards: checkRestrictedCards
|
|
6116
6147
|
});
|
|
6117
6148
|
|
|
6118
6149
|
var Text = function Text(_ref) {
|
|
@@ -14982,7 +15013,7 @@ var AlertErrorIcon = function AlertErrorIcon() {
|
|
|
14982
15013
|
xmlnsXlink: "http://www.w3.org/1999/xlink"
|
|
14983
15014
|
}, /*#__PURE__*/React__default.createElement("defs", null, /*#__PURE__*/React__default.createElement("path", {
|
|
14984
15015
|
d: "M12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 Z M15.5714286,7 L12,10.572 L8.42857143,7 L7,8.42857143 L10.571,12 L7,15.5714286 L8.42857143,17 L11.999,13.428 L15.5714286,17 L17,15.5714286 L13.428,12 L17,8.42857143 L15.5714286,7 Z",
|
|
14985
|
-
id: "path-1"
|
|
15016
|
+
id: "path-1-error-icon"
|
|
14986
15017
|
})), /*#__PURE__*/React__default.createElement("g", {
|
|
14987
15018
|
id: "Symbols",
|
|
14988
15019
|
stroke: "none",
|
|
@@ -14999,12 +15030,12 @@ var AlertErrorIcon = function AlertErrorIcon() {
|
|
|
14999
15030
|
id: "mask-2",
|
|
15000
15031
|
fill: "white"
|
|
15001
15032
|
}, /*#__PURE__*/React__default.createElement("use", {
|
|
15002
|
-
xlinkHref: "#path-1"
|
|
15033
|
+
xlinkHref: "#path-1-error-icon"
|
|
15003
15034
|
})), /*#__PURE__*/React__default.createElement("use", {
|
|
15004
15035
|
id: "icon---error",
|
|
15005
15036
|
fill: "#ED125F",
|
|
15006
15037
|
fillRule: "nonzero",
|
|
15007
|
-
xlinkHref: "#path-1"
|
|
15038
|
+
xlinkHref: "#path-1-error-icon"
|
|
15008
15039
|
})))));
|
|
15009
15040
|
};
|
|
15010
15041
|
|
|
@@ -34228,6 +34259,12 @@ const set$2 = fieldName => value => ({
|
|
|
34228
34259
|
const CLEAR = "form/CLEAR";
|
|
34229
34260
|
const clear = () => ({ type: CLEAR });
|
|
34230
34261
|
|
|
34262
|
+
const ADD_VALIDATOR = "field/ADD_VALIDATOR";
|
|
34263
|
+
const addValidator = fieldName => validator => ({
|
|
34264
|
+
type: ADD_VALIDATOR,
|
|
34265
|
+
payload: { fieldName, validator }
|
|
34266
|
+
});
|
|
34267
|
+
|
|
34231
34268
|
const createFormReducer = formConfig => (
|
|
34232
34269
|
state = createInitialState(formConfig),
|
|
34233
34270
|
action
|
|
@@ -34259,6 +34296,23 @@ const createFormReducer = formConfig => (
|
|
|
34259
34296
|
});
|
|
34260
34297
|
case CLEAR:
|
|
34261
34298
|
return createInitialState(formConfig);
|
|
34299
|
+
case ADD_VALIDATOR:
|
|
34300
|
+
const fieldWithOverride = action.payload.fieldName;
|
|
34301
|
+
const newValidator = action.payload.validator;
|
|
34302
|
+
|
|
34303
|
+
return produce(state, draftState => {
|
|
34304
|
+
draftState[fieldWithOverride].validators.push(newValidator);
|
|
34305
|
+
const fields = Object.entries(draftState);
|
|
34306
|
+
for (let entry of fields) {
|
|
34307
|
+
let fieldName = entry[0];
|
|
34308
|
+
let field = entry[1];
|
|
34309
|
+
let errors = computeErrors(fieldName, draftState);
|
|
34310
|
+
let dirty = field.dirty;
|
|
34311
|
+
draftState[fieldName].errors = errors;
|
|
34312
|
+
draftState[fieldName].dirty = dirty;
|
|
34313
|
+
draftState[fieldName].hasErrors = errors.length > 0;
|
|
34314
|
+
}
|
|
34315
|
+
});
|
|
34262
34316
|
default:
|
|
34263
34317
|
return state;
|
|
34264
34318
|
}
|
|
@@ -34277,7 +34331,8 @@ const createMapDispatchToProps = formConfig => {
|
|
|
34277
34331
|
const keys = Object.keys(formConfig);
|
|
34278
34332
|
for (let fieldName of keys) {
|
|
34279
34333
|
dispatchObj.fields[fieldName] = {
|
|
34280
|
-
set: value => dispatch(set$2(fieldName)(value))
|
|
34334
|
+
set: value => dispatch(set$2(fieldName)(value)),
|
|
34335
|
+
addValidator: validator => dispatch(addValidator(fieldName)(validator))
|
|
34281
34336
|
};
|
|
34282
34337
|
}
|
|
34283
34338
|
dispatchObj.form = { clear: () => dispatch(clear()) };
|
|
@@ -39347,18 +39402,9 @@ PaymentFormACH.reducer = reducer$6;
|
|
|
39347
39402
|
PaymentFormACH.mapStateToProps = mapStateToProps$7;
|
|
39348
39403
|
PaymentFormACH.mapDispatchToProps = mapDispatchToProps$6;
|
|
39349
39404
|
|
|
39350
|
-
var _creditCardNumberErro, _expirationDateErrors, _cvvErrors, _zipCodeErrors;
|
|
39351
|
-
|
|
39352
|
-
var nameOnCardErrors = _defineProperty({}, required.error, "Name is required");
|
|
39353
|
-
|
|
39354
|
-
var creditCardNumberErrors = (_creditCardNumberErro = {}, _defineProperty(_creditCardNumberErro, required.error, "Credit card number is required"), _defineProperty(_creditCardNumberErro, hasLength.error, "Credit card number is invalid"), _creditCardNumberErro);
|
|
39355
|
-
var expirationDateErrors = (_expirationDateErrors = {}, _defineProperty(_expirationDateErrors, required.error, "Expiration date is required"), _defineProperty(_expirationDateErrors, hasLength.error, "Expiration date is invalid"), _defineProperty(_expirationDateErrors, matchesRegex.error, "Expiration date is invalid"), _expirationDateErrors);
|
|
39356
|
-
var cvvErrors = (_cvvErrors = {}, _defineProperty(_cvvErrors, required.error, "CVV is required"), _defineProperty(_cvvErrors, hasLength.error, "CVV is invalid"), _cvvErrors);
|
|
39357
|
-
var zipCodeErrors = (_zipCodeErrors = {}, _defineProperty(_zipCodeErrors, required.error, "Zip code is required"), _defineProperty(_zipCodeErrors, hasLength.error, "Zip code is invalid"), _zipCodeErrors);
|
|
39358
|
-
|
|
39359
|
-
var countryErrorMessages = _defineProperty({}, required.error, "Country is required");
|
|
39360
|
-
|
|
39361
39405
|
var PaymentFormCard = function PaymentFormCard(_ref) {
|
|
39406
|
+
var _creditCardNumberErro, _expirationDateErrors, _cvvErrors, _zipCodeErrors;
|
|
39407
|
+
|
|
39362
39408
|
var _ref$variant = _ref.variant,
|
|
39363
39409
|
variant = _ref$variant === void 0 ? "default" : _ref$variant,
|
|
39364
39410
|
_ref$hideZipCode = _ref.hideZipCode,
|
|
@@ -39372,7 +39418,15 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
|
|
|
39372
39418
|
isMobile = _ref.isMobile,
|
|
39373
39419
|
showWalletCheckbox = _ref.showWalletCheckbox,
|
|
39374
39420
|
saveToWallet = _ref.saveToWallet,
|
|
39375
|
-
walletCheckboxMarked = _ref.walletCheckboxMarked
|
|
39421
|
+
walletCheckboxMarked = _ref.walletCheckboxMarked,
|
|
39422
|
+
restrictedCards = _ref.restrictedCards;
|
|
39423
|
+
React.useEffect(function () {
|
|
39424
|
+
if (restrictedCards) {
|
|
39425
|
+
restrictedCards.map(function (card) {
|
|
39426
|
+
return actions.fields.creditCardNumber.addValidator(matchesRegex(checkRestrictedCards(card)));
|
|
39427
|
+
});
|
|
39428
|
+
}
|
|
39429
|
+
}, []);
|
|
39376
39430
|
React.useEffect(function () {
|
|
39377
39431
|
if (clearOnDismount) {
|
|
39378
39432
|
return function () {
|
|
@@ -39380,6 +39434,16 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
|
|
|
39380
39434
|
};
|
|
39381
39435
|
}
|
|
39382
39436
|
}, []);
|
|
39437
|
+
|
|
39438
|
+
var nameOnCardErrors = _defineProperty({}, required.error, "Name is required");
|
|
39439
|
+
|
|
39440
|
+
var creditCardNumberErrors = (_creditCardNumberErro = {}, _defineProperty(_creditCardNumberErro, required.error, "Credit card number is required"), _defineProperty(_creditCardNumberErro, hasLength.error, "Credit card number is invalid"), _defineProperty(_creditCardNumberErro, matchesRegex.error, "".concat(displayCardBrand(fields.creditCardNumber.rawValue), " is not accepted")), _creditCardNumberErro);
|
|
39441
|
+
var expirationDateErrors = (_expirationDateErrors = {}, _defineProperty(_expirationDateErrors, required.error, "Expiration date is required"), _defineProperty(_expirationDateErrors, hasLength.error, "Expiration date is invalid"), _defineProperty(_expirationDateErrors, matchesRegex.error, "Expiration date is invalid"), _expirationDateErrors);
|
|
39442
|
+
var cvvErrors = (_cvvErrors = {}, _defineProperty(_cvvErrors, required.error, "CVV is required"), _defineProperty(_cvvErrors, hasLength.error, "CVV is invalid"), _cvvErrors);
|
|
39443
|
+
var zipCodeErrors = (_zipCodeErrors = {}, _defineProperty(_zipCodeErrors, required.error, "Zip code is required"), _defineProperty(_zipCodeErrors, hasLength.error, "Zip code is invalid"), _zipCodeErrors);
|
|
39444
|
+
|
|
39445
|
+
var countryErrorMessages = _defineProperty({}, required.error, "Country is required");
|
|
39446
|
+
|
|
39383
39447
|
var isUS = fields.country.rawValue === "US";
|
|
39384
39448
|
return /*#__PURE__*/React__default.createElement(FormContainer$1, {
|
|
39385
39449
|
variant: variant,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thecb/components",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"description": "Common lib for CityBase react components",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
"ramda": "^0.27.0",
|
|
81
81
|
"react-aria-modal": "^4.0.0",
|
|
82
82
|
"react-pose": "^4.0.10",
|
|
83
|
-
"redux-freeform": "^
|
|
83
|
+
"redux-freeform": "^5.0.0"
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -2,7 +2,12 @@ import React, { useEffect } from "react";
|
|
|
2
2
|
import { required, hasLength, matchesRegex } from "redux-freeform";
|
|
3
3
|
import Checkbox from "../../atoms/checkbox";
|
|
4
4
|
import CountryDropdown from "../../atoms/country-dropdown";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
checkCardBrand,
|
|
7
|
+
noop,
|
|
8
|
+
checkRestrictedCards,
|
|
9
|
+
displayCardBrand
|
|
10
|
+
} from "../../../util/general";
|
|
6
11
|
import {
|
|
7
12
|
expirationDateFormat,
|
|
8
13
|
creditCardFormat,
|
|
@@ -16,30 +21,6 @@ import {
|
|
|
16
21
|
} from "../../atoms/form-layouts";
|
|
17
22
|
import { Box } from "../../atoms/layouts";
|
|
18
23
|
|
|
19
|
-
const nameOnCardErrors = {
|
|
20
|
-
[required.error]: "Name is required"
|
|
21
|
-
};
|
|
22
|
-
const creditCardNumberErrors = {
|
|
23
|
-
[required.error]: "Credit card number is required",
|
|
24
|
-
[hasLength.error]: "Credit card number is invalid"
|
|
25
|
-
};
|
|
26
|
-
const expirationDateErrors = {
|
|
27
|
-
[required.error]: "Expiration date is required",
|
|
28
|
-
[hasLength.error]: "Expiration date is invalid",
|
|
29
|
-
[matchesRegex.error]: "Expiration date is invalid"
|
|
30
|
-
};
|
|
31
|
-
const cvvErrors = {
|
|
32
|
-
[required.error]: "CVV is required",
|
|
33
|
-
[hasLength.error]: "CVV is invalid"
|
|
34
|
-
};
|
|
35
|
-
const zipCodeErrors = {
|
|
36
|
-
[required.error]: "Zip code is required",
|
|
37
|
-
[hasLength.error]: "Zip code is invalid"
|
|
38
|
-
};
|
|
39
|
-
const countryErrorMessages = {
|
|
40
|
-
[required.error]: "Country is required"
|
|
41
|
-
};
|
|
42
|
-
|
|
43
24
|
const PaymentFormCard = ({
|
|
44
25
|
variant = "default",
|
|
45
26
|
hideZipCode = false,
|
|
@@ -51,13 +32,52 @@ const PaymentFormCard = ({
|
|
|
51
32
|
isMobile,
|
|
52
33
|
showWalletCheckbox,
|
|
53
34
|
saveToWallet,
|
|
54
|
-
walletCheckboxMarked
|
|
35
|
+
walletCheckboxMarked,
|
|
36
|
+
restrictedCards
|
|
55
37
|
}) => {
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (restrictedCards) {
|
|
40
|
+
restrictedCards.map(card =>
|
|
41
|
+
actions.fields.creditCardNumber.addValidator(
|
|
42
|
+
matchesRegex(checkRestrictedCards(card))
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
56
48
|
useEffect(() => {
|
|
57
49
|
if (clearOnDismount) {
|
|
58
50
|
return () => actions.form.clear();
|
|
59
51
|
}
|
|
60
52
|
}, []);
|
|
53
|
+
|
|
54
|
+
const nameOnCardErrors = {
|
|
55
|
+
[required.error]: "Name is required"
|
|
56
|
+
};
|
|
57
|
+
const creditCardNumberErrors = {
|
|
58
|
+
[required.error]: "Credit card number is required",
|
|
59
|
+
[hasLength.error]: "Credit card number is invalid",
|
|
60
|
+
[matchesRegex.error]: `${displayCardBrand(
|
|
61
|
+
fields.creditCardNumber.rawValue
|
|
62
|
+
)} is not accepted`
|
|
63
|
+
};
|
|
64
|
+
const expirationDateErrors = {
|
|
65
|
+
[required.error]: "Expiration date is required",
|
|
66
|
+
[hasLength.error]: "Expiration date is invalid",
|
|
67
|
+
[matchesRegex.error]: "Expiration date is invalid"
|
|
68
|
+
};
|
|
69
|
+
const cvvErrors = {
|
|
70
|
+
[required.error]: "CVV is required",
|
|
71
|
+
[hasLength.error]: "CVV is invalid"
|
|
72
|
+
};
|
|
73
|
+
const zipCodeErrors = {
|
|
74
|
+
[required.error]: "Zip code is required",
|
|
75
|
+
[hasLength.error]: "Zip code is invalid"
|
|
76
|
+
};
|
|
77
|
+
const countryErrorMessages = {
|
|
78
|
+
[required.error]: "Country is required"
|
|
79
|
+
};
|
|
80
|
+
|
|
61
81
|
const isUS = fields.country.rawValue === "US";
|
|
62
82
|
return (
|
|
63
83
|
<FormContainer variant={variant} role="form" aria-label="Card payment">
|
|
@@ -11,7 +11,7 @@ export const AlertErrorIcon = () => (
|
|
|
11
11
|
<defs>
|
|
12
12
|
<path
|
|
13
13
|
d="M12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 Z M15.5714286,7 L12,10.572 L8.42857143,7 L7,8.42857143 L10.571,12 L7,15.5714286 L8.42857143,17 L11.999,13.428 L15.5714286,17 L17,15.5714286 L13.428,12 L17,8.42857143 L15.5714286,7 Z"
|
|
14
|
-
id="path-1"
|
|
14
|
+
id="path-1-error-icon"
|
|
15
15
|
></path>
|
|
16
16
|
</defs>
|
|
17
17
|
<g
|
|
@@ -27,13 +27,13 @@ export const AlertErrorIcon = () => (
|
|
|
27
27
|
transform="translate(24.000000, 32.000000)"
|
|
28
28
|
>
|
|
29
29
|
<mask id="mask-2" fill="white">
|
|
30
|
-
<use xlinkHref="#path-1"></use>
|
|
30
|
+
<use xlinkHref="#path-1-error-icon"></use>
|
|
31
31
|
</mask>
|
|
32
32
|
<use
|
|
33
33
|
id="icon---error"
|
|
34
34
|
fill="#ED125F"
|
|
35
35
|
fillRule="nonzero"
|
|
36
|
-
xlinkHref="#path-1"
|
|
36
|
+
xlinkHref="#path-1-error-icon"
|
|
37
37
|
></use>
|
|
38
38
|
</g>
|
|
39
39
|
</g>
|
package/src/util/general.js
CHANGED
|
@@ -45,3 +45,30 @@ export const checkCardBrand = number => {
|
|
|
45
45
|
return "AMEX";
|
|
46
46
|
} else return "UNKNOWN";
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
export const displayCardBrand = number => {
|
|
50
|
+
if (/^6011/.test(number)) {
|
|
51
|
+
return "Discover";
|
|
52
|
+
} else if (/^5[1-5]/.test(number)) {
|
|
53
|
+
return "Mastercard";
|
|
54
|
+
} else if (/^4/.test(number)) {
|
|
55
|
+
return "Visa";
|
|
56
|
+
} else if (/^3[4,7]/.test(number)) {
|
|
57
|
+
return "American Express";
|
|
58
|
+
} else return "Unknown Card";
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const checkRestrictedCards = name => {
|
|
62
|
+
switch (name) {
|
|
63
|
+
case "DISCOVER":
|
|
64
|
+
return /^(?!6011)/;
|
|
65
|
+
case "MASTERCARD":
|
|
66
|
+
return /^(?!5[1-5])/;
|
|
67
|
+
case "VISA":
|
|
68
|
+
return /^(?!4)/;
|
|
69
|
+
case "AMEX":
|
|
70
|
+
return /^(?!3[4,7])/;
|
|
71
|
+
default:
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
};
|