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