tf-checkout-react 1.0.53 → 1.0.54

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.
@@ -2648,6 +2648,14 @@ var CheckoutForm = function CheckoutForm(_ref) {
2648
2648
  stripeError = _useState2[0],
2649
2649
  setStripeError = _useState2[1];
2650
2650
 
2651
+ var _useState3 = React.useState([]),
2652
+ checkboxes = _useState3[0],
2653
+ setCheckboxes = _useState3[1];
2654
+
2655
+ var _useState4 = React.useState(false),
2656
+ allowSubmit = _useState4[0],
2657
+ setAllowSubmit = _useState4[1];
2658
+
2651
2659
  var handleSubmit = /*#__PURE__*/function () {
2652
2660
  var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
2653
2661
  var card, address, paymentMethodReq, _yield$stripe$confirm, _error;
@@ -2753,6 +2761,17 @@ var CheckoutForm = function CheckoutForm(_ref) {
2753
2761
  };
2754
2762
  }();
2755
2763
 
2764
+ var handleCheckboxes = function handleCheckboxes(e) {
2765
+ var checkbox = e.target;
2766
+ var updatedCheckedState = checkboxes.map(function (item) {
2767
+ var value = item.id === checkbox.name ? !item.checked : item.checked;
2768
+ return _extends({}, item, {
2769
+ checked: value
2770
+ });
2771
+ });
2772
+ setCheckboxes(updatedCheckedState);
2773
+ };
2774
+
2756
2775
  var onChangePostalCode = function onChangePostalCode(e) {
2757
2776
  setPostalCode(e.target.value);
2758
2777
  };
@@ -2766,6 +2785,19 @@ var CheckoutForm = function CheckoutForm(_ref) {
2766
2785
  zipCode && setPostalCode(zipCode);
2767
2786
  }
2768
2787
  }, []);
2788
+ React.useEffect(function () {
2789
+ if (conditions.length) {
2790
+ setCheckboxes(conditions);
2791
+ }
2792
+ }, [conditions]);
2793
+ React.useEffect(function () {
2794
+ if (checkboxes.length) {
2795
+ var allChecked = checkboxes.every(function (item) {
2796
+ return (item == null ? void 0 : item.checked) === true;
2797
+ });
2798
+ setAllowSubmit(allChecked);
2799
+ }
2800
+ }, [checkboxes]);
2769
2801
  var buttonIsDiabled = !stripe || !!error || isLoading;
2770
2802
  return React__default.createElement("div", {
2771
2803
  className: "stripe_payment_container"
@@ -2806,7 +2838,7 @@ var CheckoutForm = function CheckoutForm(_ref) {
2806
2838
  value: postalCode,
2807
2839
  onChange: onChangePostalCode,
2808
2840
  placeholder: "ZIP"
2809
- }))), conditions == null ? void 0 : conditions.map(function (checkbox) {
2841
+ }))), checkboxes == null ? void 0 : checkboxes.map(function (checkbox) {
2810
2842
  return React__default.createElement("div", {
2811
2843
  className: 'billing-info-container__singleField',
2812
2844
  key: checkbox.id
@@ -2815,10 +2847,12 @@ var CheckoutForm = function CheckoutForm(_ref) {
2815
2847
  }, React__default.createElement(CheckboxField, {
2816
2848
  name: checkbox.id,
2817
2849
  label: checkbox.text,
2818
- required: true
2850
+ required: true,
2851
+ onChange: handleCheckboxes,
2852
+ checked: checkbox.checked
2819
2853
  })));
2820
2854
  }), React__default.createElement("div", {
2821
- className: "payment_button " + (buttonIsDiabled ? 'disabled-payment-button' : '')
2855
+ className: "payment_button " + (buttonIsDiabled || !allowSubmit ? 'disabled-payment-button' : '')
2822
2856
  }, React__default.createElement("button", {
2823
2857
  disabled: buttonIsDiabled,
2824
2858
  type: "submit"
@@ -2960,7 +2994,8 @@ var PaymentContainer = function PaymentContainer(_ref) {
2960
2994
  setConditions(conditionsInfo ? conditionsInfo.map(function (item) {
2961
2995
  return {
2962
2996
  id: nanoid.nanoid(),
2963
- text: item
2997
+ text: item,
2998
+ checked: false
2964
2999
  };
2965
3000
  }) : []);
2966
3001