@thecb/components 4.1.32 → 4.2.3

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 "Amex";
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
 
@@ -20956,7 +20987,7 @@ var FormattedCreditCard = function FormattedCreditCard(_ref) {
20956
20987
  }, "Autopay Enabled")));
20957
20988
  };
20958
20989
 
20959
- var FormattedCreditCard$1 = themeComponent(FormattedCreditCard, "FormattedCreditCard", fallbackValues$j, "default");
20990
+ var FormattedCreditCard$1 = themeComponent(FormattedCreditCard, "FormattedCreditCard", fallbackValues$j);
20960
20991
 
20961
20992
  function _templateObject3$8() {
20962
20993
  var data = _taggedTemplateLiteral(["\n display: block;\n top: auto;\n bottom: 6px;\n left: 2px;\n transition-duration: 0.13s;\n transition-delay: 0.13s;\n transition-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);\n margin-top: 12px;\n background-color: ", ";\n\n &, &::before, &::after {\n background-color: ", ";\n width: 30px;\n height: 3px;\n position: absolute;\n transition-property: transform;\n transition-duration: 0.15s;\n transition-timing-function: ease;\n }\n\n &::before, &::after {\n content: \"\";\n display: block;\n }\n\n &::before {\n top: -10px;\n transition: top 0.12s 0.2s cubic-bezier(0.33333, 0.66667, 0.66667, 1), \n transform 0.13s cubic-bezier(0.55, 0.055, 0.675, 0.19);\n }\n\n &::after {\n bottom: -10px;\n top: -20px;\n transition: top 0.2s 0.2s cubic-bezier(0.33333, 0.66667, 0.66667, 1), \n opacity 0.1s linear;\n }\n\n &.active, &.active::before, &.active::after {\n background-color: ", ";\n }\n\n &.active {\n transform: translate3d(0, -10px, 0) rotate(-45deg);\n transition-delay: 0.22s;\n transition-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n\n &.active::after {\n top: 0;\n opacity: 0;\n transition: top 0.2s cubic-bezier(0.33333, 0, 0.66667, 0.33333), \n opacity: 0.1s 0.22s linear;\n }\n\n &.active::before {\n top: 0;\n transform: rotate(-90deg);\n transition: top 0.1s 0.16s cubic-bezier(0.33333, 0, 0.66667, 0.33333), \n transform 0.13s 0.25s cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n"]);
@@ -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()) };
@@ -34778,7 +34833,7 @@ var EditableList = function EditableList(_ref) {
34778
34833
  useModal = _ref$useModal === void 0 ? false : _ref$useModal,
34779
34834
  Modal = _ref.modal,
34780
34835
  modalProps = _ref.modalProps,
34781
- autoPayMethod = _ref.autoPayMethod,
34836
+ autoPayMethods = _ref.autoPayMethods,
34782
34837
  qaPrefix = _ref.qaPrefix;
34783
34838
  return /*#__PURE__*/React__default.createElement(Box, {
34784
34839
  padding: "0rem 0rem 1.5rem 0rem"
@@ -34805,7 +34860,9 @@ var EditableList = function EditableList(_ref) {
34805
34860
 
34806
34861
  var expiredItem = (_item$expirationStatu = item === null || item === void 0 ? void 0 : item.expirationStatus) !== null && _item$expirationStatu !== void 0 ? _item$expirationStatu : ACTIVE$1;
34807
34862
  return /*#__PURE__*/React__default.createElement(EditableListItem, {
34808
- listItemSize: !!item.id && item.id === autoPayMethod ? "big" : listItemSize,
34863
+ listItemSize: !!item.id && (autoPayMethods === null || autoPayMethods === void 0 ? void 0 : autoPayMethods.some(function (methodID) {
34864
+ return methodID === item.id;
34865
+ })) ? "big" : listItemSize,
34809
34866
  key: item.id || item,
34810
34867
  disabled: expiredItem === EXPIRED$1
34811
34868
  }, /*#__PURE__*/React__default.createElement(Text$1, {
@@ -39345,18 +39402,9 @@ PaymentFormACH.reducer = reducer$6;
39345
39402
  PaymentFormACH.mapStateToProps = mapStateToProps$7;
39346
39403
  PaymentFormACH.mapDispatchToProps = mapDispatchToProps$6;
39347
39404
 
39348
- var _creditCardNumberErro, _expirationDateErrors, _cvvErrors, _zipCodeErrors;
39349
-
39350
- var nameOnCardErrors = _defineProperty({}, required.error, "Name is required");
39351
-
39352
- var creditCardNumberErrors = (_creditCardNumberErro = {}, _defineProperty(_creditCardNumberErro, required.error, "Credit card number is required"), _defineProperty(_creditCardNumberErro, hasLength.error, "Credit card number is invalid"), _creditCardNumberErro);
39353
- 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);
39354
- var cvvErrors = (_cvvErrors = {}, _defineProperty(_cvvErrors, required.error, "CVV is required"), _defineProperty(_cvvErrors, hasLength.error, "CVV is invalid"), _cvvErrors);
39355
- var zipCodeErrors = (_zipCodeErrors = {}, _defineProperty(_zipCodeErrors, required.error, "Zip code is required"), _defineProperty(_zipCodeErrors, hasLength.error, "Zip code is invalid"), _zipCodeErrors);
39356
-
39357
- var countryErrorMessages = _defineProperty({}, required.error, "Country is required");
39358
-
39359
39405
  var PaymentFormCard = function PaymentFormCard(_ref) {
39406
+ var _creditCardNumberErro, _expirationDateErrors, _cvvErrors, _zipCodeErrors;
39407
+
39360
39408
  var _ref$variant = _ref.variant,
39361
39409
  variant = _ref$variant === void 0 ? "default" : _ref$variant,
39362
39410
  _ref$hideZipCode = _ref.hideZipCode,
@@ -39370,7 +39418,15 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
39370
39418
  isMobile = _ref.isMobile,
39371
39419
  showWalletCheckbox = _ref.showWalletCheckbox,
39372
39420
  saveToWallet = _ref.saveToWallet,
39373
- 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
+ }, []);
39374
39430
  React.useEffect(function () {
39375
39431
  if (clearOnDismount) {
39376
39432
  return function () {
@@ -39378,6 +39434,16 @@ var PaymentFormCard = function PaymentFormCard(_ref) {
39378
39434
  };
39379
39435
  }
39380
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), " credit cards are restricted")), _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
+
39381
39447
  var isUS = fields.country.rawValue === "US";
39382
39448
  return /*#__PURE__*/React__default.createElement(FormContainer$1, {
39383
39449
  variant: variant,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "4.1.32",
3
+ "version": "4.2.3",
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": "^4.1.4"
83
+ "redux-freeform": "^5.0.0"
84
84
  }
85
85
  }
@@ -89,6 +89,5 @@ const FormattedCreditCard = ({
89
89
  export default themeComponent(
90
90
  FormattedCreditCard,
91
91
  "FormattedCreditCard",
92
- fallbackValues,
93
- "default"
92
+ fallbackValues
94
93
  );
@@ -34,7 +34,7 @@ const EditableList = ({
34
34
  useModal = false,
35
35
  modal: Modal,
36
36
  modalProps,
37
- autoPayMethod,
37
+ autoPayMethods,
38
38
  qaPrefix
39
39
  }) => (
40
40
  <Box padding="0rem 0rem 1.5rem 0rem">
@@ -63,7 +63,10 @@ const EditableList = ({
63
63
  return (
64
64
  <EditableListItem
65
65
  listItemSize={
66
- !!item.id && item.id === autoPayMethod ? "big" : listItemSize
66
+ !!item.id &&
67
+ autoPayMethods?.some(methodID => methodID === item.id)
68
+ ? "big"
69
+ : listItemSize
67
70
  }
68
71
  key={item.id || item}
69
72
  disabled={expiredItem === EXPIRED}
@@ -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 { checkCardBrand, noop } from "../../../util/general";
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
+ )} credit cards are restricted`
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>
@@ -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 "Amex";
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
+ };