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.
@@ -2683,6 +2683,14 @@ var CheckoutForm = function CheckoutForm(_ref) {
2683
2683
  stripeError = _useState2[0],
2684
2684
  setStripeError = _useState2[1];
2685
2685
 
2686
+ var _useState3 = useState([]),
2687
+ checkboxes = _useState3[0],
2688
+ setCheckboxes = _useState3[1];
2689
+
2690
+ var _useState4 = useState(false),
2691
+ allowSubmit = _useState4[0],
2692
+ setAllowSubmit = _useState4[1];
2693
+
2686
2694
  var handleSubmit = /*#__PURE__*/function () {
2687
2695
  var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
2688
2696
  var card, address, paymentMethodReq, _yield$stripe$confirm, _error;
@@ -2788,6 +2796,17 @@ var CheckoutForm = function CheckoutForm(_ref) {
2788
2796
  };
2789
2797
  }();
2790
2798
 
2799
+ var handleCheckboxes = function handleCheckboxes(e) {
2800
+ var checkbox = e.target;
2801
+ var updatedCheckedState = checkboxes.map(function (item) {
2802
+ var value = item.id === checkbox.name ? !item.checked : item.checked;
2803
+ return _extends({}, item, {
2804
+ checked: value
2805
+ });
2806
+ });
2807
+ setCheckboxes(updatedCheckedState);
2808
+ };
2809
+
2791
2810
  var onChangePostalCode = function onChangePostalCode(e) {
2792
2811
  setPostalCode(e.target.value);
2793
2812
  };
@@ -2801,6 +2820,19 @@ var CheckoutForm = function CheckoutForm(_ref) {
2801
2820
  zipCode && setPostalCode(zipCode);
2802
2821
  }
2803
2822
  }, []);
2823
+ useEffect(function () {
2824
+ if (conditions.length) {
2825
+ setCheckboxes(conditions);
2826
+ }
2827
+ }, [conditions]);
2828
+ useEffect(function () {
2829
+ if (checkboxes.length) {
2830
+ var allChecked = checkboxes.every(function (item) {
2831
+ return (item == null ? void 0 : item.checked) === true;
2832
+ });
2833
+ setAllowSubmit(allChecked);
2834
+ }
2835
+ }, [checkboxes]);
2804
2836
  var buttonIsDiabled = !stripe || !!error || isLoading;
2805
2837
  return React.createElement("div", {
2806
2838
  className: "stripe_payment_container"
@@ -2841,7 +2873,7 @@ var CheckoutForm = function CheckoutForm(_ref) {
2841
2873
  value: postalCode,
2842
2874
  onChange: onChangePostalCode,
2843
2875
  placeholder: "ZIP"
2844
- }))), conditions == null ? void 0 : conditions.map(function (checkbox) {
2876
+ }))), checkboxes == null ? void 0 : checkboxes.map(function (checkbox) {
2845
2877
  return React.createElement("div", {
2846
2878
  className: 'billing-info-container__singleField',
2847
2879
  key: checkbox.id
@@ -2850,10 +2882,12 @@ var CheckoutForm = function CheckoutForm(_ref) {
2850
2882
  }, React.createElement(CheckboxField, {
2851
2883
  name: checkbox.id,
2852
2884
  label: checkbox.text,
2853
- required: true
2885
+ required: true,
2886
+ onChange: handleCheckboxes,
2887
+ checked: checkbox.checked
2854
2888
  })));
2855
2889
  }), React.createElement("div", {
2856
- className: "payment_button " + (buttonIsDiabled ? 'disabled-payment-button' : '')
2890
+ className: "payment_button " + (buttonIsDiabled || !allowSubmit ? 'disabled-payment-button' : '')
2857
2891
  }, React.createElement("button", {
2858
2892
  disabled: buttonIsDiabled,
2859
2893
  type: "submit"
@@ -2995,7 +3029,8 @@ var PaymentContainer = function PaymentContainer(_ref) {
2995
3029
  setConditions(conditionsInfo ? conditionsInfo.map(function (item) {
2996
3030
  return {
2997
3031
  id: nanoid(),
2998
- text: item
3032
+ text: item,
3033
+ checked: false
2999
3034
  };
3000
3035
  }) : []);
3001
3036