tf-checkout-react 1.7.20 → 1.7.23

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.
@@ -3605,21 +3605,35 @@ var AddonStepper = function AddonStepper(_ref) {
3605
3605
  handleAddonChange = _ref.handleAddonChange,
3606
3606
  classNamePrefix = _ref.classNamePrefix,
3607
3607
  _ref$siblingIds = _ref.siblingIds,
3608
- siblingIds = _ref$siblingIds === void 0 ? [] : _ref$siblingIds;
3608
+ siblingIds = _ref$siblingIds === void 0 ? [] : _ref$siblingIds,
3609
+ _ref$allAddonIds = _ref.allAddonIds,
3610
+ allAddonIds = _ref$allAddonIds === void 0 ? [] : _ref$allAddonIds,
3611
+ maxTotalQuantity = _ref.maxTotalQuantity;
3609
3612
  var _useFormikContext = useFormikContext(),
3610
3613
  values = _useFormikContext.values,
3611
3614
  setFieldValue = _useFormikContext.setFieldValue;
3612
3615
  var qty = Number((_values$id = values[id]) != null ? _values$id : 0);
3613
3616
  var max = (selectOptions == null ? void 0 : selectOptions.length) > 0 ? selectOptions[selectOptions.length - 1].value : 0;
3617
+ var totalSelected = allAddonIds.length > 0 ? allAddonIds.reduce(function (sum, aid) {
3618
+ var _values$aid;
3619
+ return sum + Number((_values$aid = values[aid]) != null ? _values$aid : 0);
3620
+ }, 0) : 0;
3614
3621
  var change = function change(next) {
3615
- if (next > 0) {
3616
- siblingIds.forEach(function (siblingId) {
3617
- return setFieldValue(siblingId, 0);
3618
- });
3622
+ if (next > qty) {
3623
+ if (maxTotalQuantity != null) {
3624
+ allAddonIds.forEach(function (aid) {
3625
+ if (aid !== id) setFieldValue(aid, 0);
3626
+ });
3627
+ } else {
3628
+ siblingIds.forEach(function (siblingId) {
3629
+ return setFieldValue(siblingId, 0);
3630
+ });
3631
+ }
3619
3632
  }
3620
3633
  setFieldValue(id, next);
3621
3634
  handleAddonChange(id, next);
3622
3635
  };
3636
+ var incrementDisabled = qty >= max || maxTotalQuantity != null && totalSelected >= maxTotalQuantity && qty === 0;
3623
3637
  return React.createElement("div", {
3624
3638
  className: classNamePrefix + "_stepper"
3625
3639
  }, React.createElement("button", {
@@ -3638,7 +3652,7 @@ var AddonStepper = function AddonStepper(_ref) {
3638
3652
  onClick: function onClick() {
3639
3653
  return change(qty + 1);
3640
3654
  },
3641
- disabled: qty >= max,
3655
+ disabled: incrementDisabled,
3642
3656
  "aria-label": "Increase quantity"
3643
3657
  }, "+"));
3644
3658
  };
@@ -3657,6 +3671,9 @@ var AddonComponent = function AddonComponent(_ref2) {
3657
3671
  useStepperQty = _ref2$useStepperQty === void 0 ? false : _ref2$useStepperQty,
3658
3672
  _ref2$siblingIds = _ref2.siblingIds,
3659
3673
  siblingIds = _ref2$siblingIds === void 0 ? [] : _ref2$siblingIds,
3674
+ _ref2$allAddonIds = _ref2.allAddonIds,
3675
+ allAddonIds = _ref2$allAddonIds === void 0 ? [] : _ref2$allAddonIds,
3676
+ maxTotalQuantity = _ref2.maxTotalQuantity,
3660
3677
  _ref2$onCustomFieldCh = _ref2.onCustomFieldChange,
3661
3678
  onCustomFieldChange = _ref2$onCustomFieldCh === void 0 ? _identity : _ref2$onCustomFieldCh;
3662
3679
  var id = data.id,
@@ -3690,7 +3707,9 @@ var AddonComponent = function AddonComponent(_ref2) {
3690
3707
  selectOptions: selectOptions,
3691
3708
  handleAddonChange: handleAddonChange,
3692
3709
  classNamePrefix: classNamePrefix,
3693
- siblingIds: siblingIds
3710
+ siblingIds: siblingIds,
3711
+ allAddonIds: allAddonIds,
3712
+ maxTotalQuantity: maxTotalQuantity
3694
3713
  })) : React.createElement(Field, {
3695
3714
  name: id,
3696
3715
  selectOptions: selectOptions,
@@ -4478,6 +4497,7 @@ var SimpleAddonsContainer = function SimpleAddonsContainer(_ref) {
4478
4497
  eventId = _ref.eventId,
4479
4498
  _ref$useStepperQty = _ref.useStepperQty,
4480
4499
  useStepperQty = _ref$useStepperQty === void 0 ? false : _ref$useStepperQty,
4500
+ addonMaxQuantityGroups = _ref.addonMaxQuantityGroups,
4481
4501
  _ref$onAddOnSelect = _ref.onAddOnSelect,
4482
4502
  onAddOnSelect = _ref$onAddOnSelect === void 0 ? _identity : _ref$onAddOnSelect,
4483
4503
  _ref$handleConfirm = _ref.handleConfirm,
@@ -4494,12 +4514,15 @@ var SimpleAddonsContainer = function SimpleAddonsContainer(_ref) {
4494
4514
  var _useState4 = useState({}),
4495
4515
  groupsWithInitialVariantsValues = _useState4[0],
4496
4516
  setGroupsWithInitialVariantsValues = _useState4[1];
4497
- var _useState5 = useState(true),
4498
- loading = _useState5[0],
4499
- setLoading = _useState5[1];
4500
- var _useState6 = useState(null),
4501
- visibleDescription = _useState6[0],
4502
- setVisibleDescription = _useState6[1];
4517
+ var _useState5 = useState({}),
4518
+ crossGroupSelections = _useState5[0],
4519
+ setCrossGroupSelections = _useState5[1];
4520
+ var _useState6 = useState(true),
4521
+ loading = _useState6[0],
4522
+ setLoading = _useState6[1];
4523
+ var _useState7 = useState(null),
4524
+ visibleDescription = _useState7[0],
4525
+ setVisibleDescription = _useState7[1];
4503
4526
  var handleDescriptionToggle = function handleDescriptionToggle(ticketId) {
4504
4527
  setVisibleDescription(function (current) {
4505
4528
  return current === ticketId ? null : ticketId;
@@ -4628,6 +4651,37 @@ var SimpleAddonsContainer = function SimpleAddonsContainer(_ref) {
4628
4651
  recreateGroupVariantsSelectOptions(currGroupId, updatedGroupsWithSelectedVariants[currGroupId]);
4629
4652
  }
4630
4653
  };
4654
+ // Cross-group cap: when addonMaxQuantityGroups is set, limits total selections
4655
+ // across ALL addon groups to that number by capping each stepper's max.
4656
+ var effectiveAddonsOptions = useMemo(function () {
4657
+ if (!addonMaxQuantityGroups) return addonsOptions;
4658
+ var totalSelected = Object.values(crossGroupSelections).reduce(function (sum, v) {
4659
+ return sum + Number(v);
4660
+ }, 0);
4661
+ var globalRemaining = addonMaxQuantityGroups - totalSelected;
4662
+ var result = {};
4663
+ var _loop = function _loop() {
4664
+ var opts = addonsOptions[id] || [];
4665
+ var sdkMax = opts.length ? opts[opts.length - 1].value : 0;
4666
+ var currSelected = Number(crossGroupSelections[id] || 0);
4667
+ var allowedMax = Math.max(0, Math.min(sdkMax, globalRemaining + currSelected));
4668
+ result[id] = opts.filter(function (opt) {
4669
+ return opt.value <= allowedMax;
4670
+ });
4671
+ };
4672
+ for (var id in addonsOptions) {
4673
+ _loop();
4674
+ }
4675
+ return result;
4676
+ }, [addonsOptions, crossGroupSelections, addonMaxQuantityGroups]);
4677
+ var handleCrossGroupChange = function handleCrossGroupChange(id, value) {
4678
+ if (addonMaxQuantityGroups) {
4679
+ setCrossGroupSelections(function (prev) {
4680
+ var _extends6;
4681
+ return _extends({}, prev, (_extends6 = {}, _extends6[id] = Number(value), _extends6));
4682
+ });
4683
+ }
4684
+ };
4631
4685
  var initialValues = useMemo(function () {
4632
4686
  var _addOnDataWithCustomF2;
4633
4687
  var addOnsData = {};
@@ -4737,7 +4791,7 @@ var SimpleAddonsContainer = function SimpleAddonsContainer(_ref) {
4737
4791
  React.createElement(AddonComponent, {
4738
4792
  key: variant.id,
4739
4793
  data: variant,
4740
- selectOptions: addonsOptions[variant.id],
4794
+ selectOptions: effectiveAddonsOptions[variant.id],
4741
4795
  classNamePrefix: classNamePrefix,
4742
4796
  siblingIds: addon.variants.filter(function (v) {
4743
4797
  return v.id !== variant.id;
@@ -4745,7 +4799,7 @@ var SimpleAddonsContainer = function SimpleAddonsContainer(_ref) {
4745
4799
  return v.id;
4746
4800
  }),
4747
4801
  handleAddonChange: function handleAddonChange(id, value) {
4748
- console.log('handleAddonChange', id, value);
4802
+ handleCrossGroupChange(id, value);
4749
4803
  onFieldChange(id, value, addon);
4750
4804
  var fieldUpdates = collectAddonFieldUpdates(addon, values);
4751
4805
  onAddOnSelect(id, value, addon, fieldUpdates);
@@ -4763,9 +4817,10 @@ var SimpleAddonsContainer = function SimpleAddonsContainer(_ref) {
4763
4817
  React.createElement(AddonComponent, {
4764
4818
  key: addon.id,
4765
4819
  data: addon,
4766
- selectOptions: addonsOptions[addon.id],
4820
+ selectOptions: effectiveAddonsOptions[addon.id],
4767
4821
  classNamePrefix: classNamePrefix,
4768
4822
  handleAddonChange: function handleAddonChange(id, value) {
4823
+ handleCrossGroupChange(id, value);
4769
4824
  onFieldChange(id, value, addon);
4770
4825
  var fieldUpdates = collectAddonFieldUpdates(addon, values);
4771
4826
  onAddOnSelect(id, value, addon, fieldUpdates);