tf-checkout-react 1.3.0 → 1.3.2

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.
@@ -3220,7 +3220,7 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref3) {
3220
3220
  while (1) {
3221
3221
  switch (_context5.prev = _context5.next) {
3222
3222
  case 0:
3223
- if (!(skipPage && !_isEmpty(ticketsQuantity) && !showDOB)) {
3223
+ if (!(skipPage && !_isEmpty(ticketsQuantity) && !showDOB && !loading)) {
3224
3224
  _context5.next = 18;
3225
3225
  break;
3226
3226
  }
@@ -4326,6 +4326,11 @@ var PaymentContainer = function PaymentContainer(_ref) {
4326
4326
  normalizer = _field$normalizer === void 0 ? _identity : _field$normalizer;
4327
4327
  var currency = orderData.currency;
4328
4328
  var value = orderData[id];
4329
+
4330
+ if (field.id === 'add_ons' && _isEmpty(value)) {
4331
+ return false;
4332
+ }
4333
+
4329
4334
  return React.createElement("div", {
4330
4335
  key: id,
4331
4336
  className: "order_info_block"
@@ -5620,9 +5625,10 @@ var TicketsContainer = function TicketsContainer(_ref) {
5620
5625
  hash = '';
5621
5626
  total = '';
5622
5627
  _isWindowDefined = typeof window !== 'undefined';
5628
+ _isWindowDefined && window.localStorage.removeItem('add_ons');
5623
5629
 
5624
5630
  if (!(skipBillingPage && !hasAddOn)) {
5625
- _context2.next = 37;
5631
+ _context2.next = 38;
5626
5632
  break;
5627
5633
  }
5628
5634
 
@@ -5632,31 +5638,27 @@ var TicketsContainer = function TicketsContainer(_ref) {
5632
5638
  checkoutBody = createCheckoutDataBodyWithDefaultHolder(ticketQuantity, userData);
5633
5639
 
5634
5640
  if (!enableBillingInfoAutoCreate) {
5635
- _context2.next = 33;
5641
+ _context2.next = 34;
5636
5642
  break;
5637
5643
  }
5638
5644
 
5639
- _context2.next = 30;
5645
+ _context2.next = 31;
5640
5646
  return postOnCheckout(checkoutBody, access_token);
5641
5647
 
5642
- case 30:
5648
+ case 31:
5643
5649
  _context2.t0 = _context2.sent;
5644
- _context2.next = 34;
5650
+ _context2.next = 35;
5645
5651
  break;
5646
5652
 
5647
- case 33:
5653
+ case 34:
5648
5654
  _context2.t0 = null;
5649
5655
 
5650
- case 34:
5656
+ case 35:
5651
5657
  checkoutResult = _context2.t0;
5652
5658
  hash = _get(checkoutResult, 'data.data.attributes.hash');
5653
5659
  total = _get(checkoutResult, 'data.data.attributes.total');
5654
5660
 
5655
- case 37:
5656
- if (hasAddOn && _isWindowDefined) {
5657
- window.localStorage.setItem('tickets_quantity', String(ticketQuantity));
5658
- }
5659
-
5661
+ case 38:
5660
5662
  onAddToCartSuccess({
5661
5663
  skip_billing_page: skipBillingPage,
5662
5664
  names_required: nameIsRequired,
@@ -7111,9 +7113,20 @@ var addonsWithGroupsAdapter = function addonsWithGroupsAdapter(data) {
7111
7113
  return adaptedAddons;
7112
7114
  };
7113
7115
  var cartAdapter = function cartAdapter(cart) {
7114
- var cartData = _get(cart, 'data.data.attributes.cart', []);
7116
+ var cartData = _get(cart, 'data.data.attributes', []);
7117
+
7118
+ var expiresAt = cartData.expiresAt,
7119
+ carts_arr = cartData.cart;
7120
+
7121
+ var _ref = carts_arr[0] || {},
7122
+ id = _ref.id,
7123
+ quantity = _ref.quantity;
7115
7124
 
7116
- return cartData[0] || {};
7125
+ return {
7126
+ id: id,
7127
+ quantity: quantity,
7128
+ expiresAt: expiresAt
7129
+ };
7117
7130
  };
7118
7131
 
7119
7132
  var AddonComponent = function AddonComponent(_ref) {
@@ -7213,10 +7226,11 @@ var filterStockBasedOnAvailability = function filterStockBasedOnAvailability(gen
7213
7226
  filteredStockCount = availableStock;
7214
7227
  }
7215
7228
  } else {
7216
- // Not setted any restriction
7217
- if (_isNull(availableStock)) {
7218
- filteredStockCount = 10;
7219
- } else {
7229
+ // Not set any restriction
7230
+ // Here 10 value is business logic
7231
+ filteredStockCount = 10;
7232
+
7233
+ if (!_isNull(availableStock) && availableStock < filteredStockCount) {
7220
7234
  filteredStockCount = availableStock;
7221
7235
  }
7222
7236
  }
@@ -7311,13 +7325,25 @@ var getTicketRelatedAddons = function getTicketRelatedAddons(addons, ticketId) {
7311
7325
  };
7312
7326
  var getSortedAddons = function getSortedAddons(addons, sortDirection) {
7313
7327
  if (sortDirection === void 0) {
7314
- sortDirection = "asc";
7328
+ sortDirection = 'asc';
7315
7329
  }
7316
7330
 
7317
7331
  var addonsCopy = [].concat(addons);
7318
7332
  addonsCopy.forEach(function (addon) {
7319
7333
  if (addon.variants) {
7334
+ var unsortedVariants = [];
7335
+ addon.variants.forEach(function (variant) {
7336
+ unsortedVariants.push(_extends({}, variant, {
7337
+ sortOrder: Number(variant.sortOrder)
7338
+ }));
7339
+ });
7320
7340
  addon.sortOrder = Number(addon.variants[0].sortOrder);
7341
+
7342
+ var sortedVariants = _sortBy(unsortedVariants, function (variant) {
7343
+ return variant.sortOrder;
7344
+ });
7345
+
7346
+ addon.variants = sortedVariants;
7321
7347
  } else {
7322
7348
  addon.sortOrder = Number(addon.sortOrder);
7323
7349
  }
@@ -7327,18 +7353,27 @@ var getSortedAddons = function getSortedAddons(addons, sortDirection) {
7327
7353
  return addon.sortOrder;
7328
7354
  });
7329
7355
 
7330
- if (sortDirection === "desc") {
7356
+ if (sortDirection === 'desc') {
7331
7357
  return _reverse(sortedAddons);
7332
7358
  }
7333
7359
 
7334
7360
  return sortedAddons;
7335
7361
  };
7362
+ var isAtLeastOneAddonSelected = function isAtLeastOneAddonSelected(value) {
7363
+ var selectedAddons = Object.fromEntries(Object.entries(value).filter(function (_ref) {
7364
+ var count = _ref[1];
7365
+ return Number(count) !== 0;
7366
+ }));
7367
+ return !_isEmpty(selectedAddons);
7368
+ };
7336
7369
 
7337
7370
  var AddonsContainter = function AddonsContainter(_ref) {
7338
7371
  var _ref$classNamePrefix = _ref.classNamePrefix,
7339
7372
  classNamePrefix = _ref$classNamePrefix === void 0 ? 'add_on' : _ref$classNamePrefix,
7340
7373
  _ref$enableBillingInf = _ref.enableBillingInfoAutoCreate,
7341
7374
  enableBillingInfoAutoCreate = _ref$enableBillingInf === void 0 ? true : _ref$enableBillingInf,
7375
+ _ref$enableTimer = _ref.enableTimer,
7376
+ enableTimer = _ref$enableTimer === void 0 ? false : _ref$enableTimer,
7342
7377
  _ref$onGetAddonsPageI = _ref.onGetAddonsPageInfoSuccess,
7343
7378
  onGetAddonsPageInfoSuccess = _ref$onGetAddonsPageI === void 0 ? _identity : _ref$onGetAddonsPageI,
7344
7379
  _ref$onGetAddonsPageI2 = _ref.onGetAddonsPageInfoError,
@@ -7350,7 +7385,10 @@ var AddonsContainter = function AddonsContainter(_ref) {
7350
7385
  _ref$onConfirmSelecti = _ref.onConfirmSelectionSuccess,
7351
7386
  onConfirmSelectionSuccess = _ref$onConfirmSelecti === void 0 ? _identity : _ref$onConfirmSelecti,
7352
7387
  _ref$onConfirmSelecti2 = _ref.onConfirmSelectionError,
7353
- onConfirmSelectionError = _ref$onConfirmSelecti2 === void 0 ? _identity : _ref$onConfirmSelecti2;
7388
+ onConfirmSelectionError = _ref$onConfirmSelecti2 === void 0 ? _identity : _ref$onConfirmSelecti2,
7389
+ _ref$onCountdownFinis = _ref.onCountdownFinish,
7390
+ _onCountdownFinish = _ref$onCountdownFinis === void 0 ? _identity : _ref$onCountdownFinis;
7391
+
7354
7392
  var eventId = getQueryVariable('event_id');
7355
7393
 
7356
7394
  var _useState = useState([]),
@@ -7373,10 +7411,14 @@ var AddonsContainter = function AddonsContainter(_ref) {
7373
7411
  loading = _useState5[0],
7374
7412
  setLoading = _useState5[1];
7375
7413
 
7414
+ var _useState6 = useState(0),
7415
+ cartExpirationTime = _useState6[0],
7416
+ setCartExpirationTime = _useState6[1];
7417
+
7376
7418
  useEffect(function () {
7377
7419
  var getAddonsPageInfo = /*#__PURE__*/function () {
7378
7420
  var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
7379
- var cart, cartAdaptedData, choosedTicketCount, choosedTicketID, addonsData, adaptedAddons, ticketRelatedAddons, sortedTicketAddons, _getAddonSelectOption, addonsWithOptions, groupsWithSelectedVariantsInfo, groupsWithVariants;
7421
+ var cart, _cartAdapter, choosedTicketID, quantity, expiresAt, choosedTicketCount, addonsData, adaptedAddons, ticketRelatedAddons, sortedTicketAddons, _getAddonSelectOption, addonsWithOptions, groupsWithSelectedVariantsInfo, groupsWithVariants;
7380
7422
 
7381
7423
  return runtime_1.wrap(function _callee$(_context) {
7382
7424
  while (1) {
@@ -7396,9 +7438,10 @@ var AddonsContainter = function AddonsContainter(_ref) {
7396
7438
 
7397
7439
  case 5:
7398
7440
  cart = _context.sent;
7399
- cartAdaptedData = cartAdapter(cart) || {};
7400
- choosedTicketCount = Number(cartAdaptedData.quantity);
7401
- choosedTicketID = cartAdaptedData.id;
7441
+ _cartAdapter = cartAdapter(cart), choosedTicketID = _cartAdapter.id, quantity = _cartAdapter.quantity, expiresAt = _cartAdapter.expiresAt;
7442
+ choosedTicketCount = Number(quantity);
7443
+ setCartExpirationTime(expiresAt); // Get and collect addons data
7444
+
7402
7445
  _context.next = 11;
7403
7446
  return getAddons(eventId);
7404
7447
 
@@ -7498,7 +7541,7 @@ var AddonsContainter = function AddonsContainter(_ref) {
7498
7541
  };
7499
7542
 
7500
7543
  var handleConfirm = /*#__PURE__*/function () {
7501
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(values) {
7544
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(values, skipAddonPage) {
7502
7545
  var _pageConfigsData$skip, _pageConfigsData$name, _pageConfigsData$age_, _pageConfigsData$phon, _pageConfigsData$has_, pageConfigsDataResponse, pageConfigsData, isWindowDefined, skipBillingPage, nameIsRequired, ageIsRequired, phoneIsRequired, hasAddOn, ticketsQuantity, userData, checkoutBody, checkoutResponse, hash, total;
7503
7546
 
7504
7547
  return runtime_1.wrap(function _callee2$(_context2) {
@@ -7520,7 +7563,7 @@ var AddonsContainter = function AddonsContainter(_ref) {
7520
7563
  hasAddOn = (_pageConfigsData$has_ = pageConfigsData.has_add_on) != null ? _pageConfigsData$has_ : false;
7521
7564
 
7522
7565
  if (!(skipBillingPage && enableBillingInfoAutoCreate)) {
7523
- _context2.next = 32;
7566
+ _context2.next = 33;
7524
7567
  break;
7525
7568
  }
7526
7569
 
@@ -7530,7 +7573,7 @@ var AddonsContainter = function AddonsContainter(_ref) {
7530
7573
  _context2.prev = 15;
7531
7574
  _context2.next = 18;
7532
7575
  return postOnCheckout(_extends({}, checkoutBody, {
7533
- attributes: _extends({}, checkoutBody.attributes, {
7576
+ attributes: _extends({}, checkoutBody.attributes, !skipAddonPage && {
7534
7577
  add_ons: values
7535
7578
  })
7536
7579
  }));
@@ -7540,6 +7583,7 @@ var AddonsContainter = function AddonsContainter(_ref) {
7540
7583
  hash = _get(checkoutResponse, 'data.data.attributes.hash');
7541
7584
  total = _get(checkoutResponse, 'data.data.attributes.total');
7542
7585
  isWindowDefined && window.localStorage.removeItem('quantity');
7586
+ isWindowDefined && window.localStorage.removeItem('add_ons');
7543
7587
  onPostCheckoutSuccess(checkoutResponse == null ? void 0 : checkoutResponse.data);
7544
7588
  onConfirmSelectionSuccess({
7545
7589
  skip_billing_page: skipBillingPage,
@@ -7551,22 +7595,25 @@ var AddonsContainter = function AddonsContainter(_ref) {
7551
7595
  total: total,
7552
7596
  hasAddOn: hasAddOn
7553
7597
  });
7554
- _context2.next = 30;
7598
+ _context2.next = 31;
7555
7599
  break;
7556
7600
 
7557
- case 26:
7558
- _context2.prev = 26;
7601
+ case 27:
7602
+ _context2.prev = 27;
7559
7603
  _context2.t0 = _context2["catch"](15);
7560
7604
  onPostCheckoutError(_context2.t0);
7561
7605
  onConfirmSelectionError(_context2.t0);
7562
7606
 
7563
- case 30:
7564
- _context2.next = 33;
7607
+ case 31:
7608
+ _context2.next = 34;
7565
7609
  break;
7566
7610
 
7567
- case 32:
7611
+ case 33:
7568
7612
  if (isWindowDefined) {
7569
- window.localStorage.setItem('add_ons', JSON.stringify(values));
7613
+ if (!skipAddonPage) {
7614
+ window.localStorage.setItem('add_ons', JSON.stringify(values));
7615
+ }
7616
+
7570
7617
  onConfirmSelectionSuccess({
7571
7618
  skip_billing_page: skipBillingPage && enableBillingInfoAutoCreate,
7572
7619
  names_required: nameIsRequired,
@@ -7582,28 +7629,32 @@ var AddonsContainter = function AddonsContainter(_ref) {
7582
7629
  });
7583
7630
  }
7584
7631
 
7585
- case 33:
7586
- _context2.next = 38;
7632
+ case 34:
7633
+ _context2.next = 39;
7587
7634
  break;
7588
7635
 
7589
- case 35:
7590
- _context2.prev = 35;
7636
+ case 36:
7637
+ _context2.prev = 36;
7591
7638
  _context2.t1 = _context2["catch"](0);
7592
7639
  onConfirmSelectionError(_context2.t1);
7593
7640
 
7594
- case 38:
7641
+ case 39:
7595
7642
  case "end":
7596
7643
  return _context2.stop();
7597
7644
  }
7598
7645
  }
7599
- }, _callee2, null, [[0, 35], [15, 26]]);
7646
+ }, _callee2, null, [[0, 36], [15, 27]]);
7600
7647
  }));
7601
7648
 
7602
- return function handleConfirm(_x) {
7649
+ return function handleConfirm(_x, _x2) {
7603
7650
  return _ref3.apply(this, arguments);
7604
7651
  };
7605
7652
  }();
7606
7653
 
7654
+ var handleClearAddons = function handleClearAddons() {
7655
+ window.localStorage.removeItem('add_ons');
7656
+ };
7657
+
7607
7658
  if (loading) {
7608
7659
  return React.createElement("div", {
7609
7660
  className: classNamePrefix + "_loader"
@@ -7612,28 +7663,40 @@ var AddonsContainter = function AddonsContainter(_ref) {
7612
7663
  }));
7613
7664
  }
7614
7665
 
7615
- return React.createElement("div", {
7666
+ return React.createElement(React.Fragment, null, !!cartExpirationTime && enableTimer && React.createElement(TimerWidget$1, {
7667
+ expires_at: cartExpirationTime,
7668
+ onCountdownFinish: function onCountdownFinish() {
7669
+ handleClearAddons();
7670
+
7671
+ _onCountdownFinish();
7672
+ }
7673
+ }), React.createElement("div", {
7616
7674
  className: classNamePrefix + "_container"
7617
7675
  }, React.createElement("div", {
7618
7676
  className: classNamePrefix + "_block"
7619
7677
  }, React.createElement("div", {
7620
7678
  className: classNamePrefix + "_line_block"
7621
- }, React.createElement("div", {
7622
- className: classNamePrefix + "_line"
7623
- }), React.createElement("p", {
7679
+ }, React.createElement("p", {
7624
7680
  className: classNamePrefix + "_info_title"
7625
- }, "Get Your Tickets")), React.createElement("div", {
7681
+ }, "Get Your Tickets"), React.createElement("button", {
7682
+ type: "button",
7683
+ className: classNamePrefix + "_skip",
7684
+ onClick: function onClick() {
7685
+ handleClearAddons();
7686
+ handleConfirm({}, true);
7687
+ }
7688
+ }, "Skip")), React.createElement("div", {
7626
7689
  className: classNamePrefix + "_title"
7627
7690
  }, "UPGRADES & ADD-ONS"), React.createElement("div", {
7628
7691
  className: classNamePrefix + "_subtitle"
7629
7692
  }, "PLEASE SELECT FROM THE OPTIONAL ADD-ONS BELOW"), React.createElement(Formik, {
7630
7693
  initialValues: {},
7631
- onSubmit: handleConfirm
7694
+ onSubmit: function onSubmit(values) {
7695
+ handleConfirm(values);
7696
+ }
7632
7697
  }, function (_ref4) {
7633
7698
  var values = _ref4.values;
7634
-
7635
- var isConfirmDisabled = _isEmpty(values);
7636
-
7699
+ var isConfirmDisabled = !isAtLeastOneAddonSelected(values);
7637
7700
  return React.createElement(Form, {
7638
7701
  autoComplete: "off",
7639
7702
  className: "form_holder"
@@ -7691,7 +7754,7 @@ var AddonsContainter = function AddonsContainter(_ref) {
7691
7754
  className: (isConfirmDisabled ? classNamePrefix + "_is_disabled" : '') + " " + classNamePrefix + "_submit_button",
7692
7755
  disabled: isConfirmDisabled
7693
7756
  }, "CONFIRM SELECTION")));
7694
- })));
7757
+ }))));
7695
7758
  };
7696
7759
 
7697
7760
  var style$5 = {