tf-checkout-react 1.7.30 → 1.7.32-beta.0

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.
@@ -11,6 +11,7 @@ import _identity from 'lodash-es/identity';
11
11
  import _isEmpty from 'lodash-es/isEmpty';
12
12
  import _isEqual from 'lodash-es/isEqual';
13
13
  import _map from 'lodash-es/map';
14
+ import _omit from 'lodash-es/omit';
14
15
  import { nanoid } from 'nanoid';
15
16
  import React, { Component, useState, useEffect, memo, useRef, useCallback, useMemo, Fragment } from 'react';
16
17
  import { Tooltip } from 'react-tooltip';
@@ -924,6 +925,25 @@ var getFieldsKeys = function getFieldsKeys(customFields) {
924
925
  return field.name;
925
926
  });
926
927
  };
928
+ var getHolderTicketTypeIds = function getHolderTicketTypeIds(ticketsPriceBreakdown, holdersCount) {
929
+ if (!Array.isArray(ticketsPriceBreakdown)) return [];
930
+ var slots = [];
931
+ _forEach(ticketsPriceBreakdown, function (line) {
932
+ for (var i = 0; i < Number((line == null ? void 0 : line.quantity) || 0); i++) {
933
+ var _line$ticket_type_id;
934
+ slots.push(String((_line$ticket_type_id = line == null ? void 0 : line.ticket_type_id) != null ? _line$ticket_type_id : ''));
935
+ }
936
+ });
937
+ return slots.length === holdersCount ? slots : [];
938
+ };
939
+ /**
940
+ * Whether a ticket-holder custom field applies to a ticket of `ticketTypeId`.
941
+ * Unscoped fields apply to every ticket; an unknown ticket type fails open so a
942
+ * required field is never silently dropped.
943
+ */
944
+ var customFieldAppliesToTicketType = function customFieldAppliesToTicketType(field, ticketTypeId) {
945
+ return !ticketTypeId || _isEmpty(field.ticketTypeIds) || (field.ticketTypeIds || []).includes(String(ticketTypeId));
946
+ };
927
947
 
928
948
  var isJson = function isJson(value) {
929
949
  try {
@@ -999,6 +1019,11 @@ var optionsAdapter = function optionsAdapter(options) {
999
1019
  });
1000
1020
  return adaptedOptions;
1001
1021
  };
1022
+ // `settings.ticketTypes` scopes a ticket field to those ticket types; absent or
1023
+ // empty means it applies to every ticket. Ids arrive as numbers, compare as strings.
1024
+ var ticketTypeIdsAdapter = function ticketTypeIdsAdapter(ticketTypes) {
1025
+ return Array.isArray(ticketTypes) && ticketTypes.length ? ticketTypes.map(String) : null;
1026
+ };
1002
1027
  var fieldDataAdapter = function fieldDataAdapter(field) {
1003
1028
  var name = field.name,
1004
1029
  label = field.label,
@@ -1016,6 +1041,10 @@ var fieldDataAdapter = function fieldDataAdapter(field) {
1016
1041
  className: _get(restValues, 'settings.className', ''),
1017
1042
  value: _get(restValues, 'defaultValue')
1018
1043
  };
1044
+ var ticketTypeIds = ticketTypeIdsAdapter(_get(restValues, 'settings.ticketTypes'));
1045
+ if (ticketTypeIds) {
1046
+ adaptedField.ticketTypeIds = ticketTypeIds;
1047
+ }
1019
1048
  switch (type) {
1020
1049
  case 'textarea':
1021
1050
  adaptedField.type = 'text';
@@ -2230,7 +2259,7 @@ var checkCustomerOrder = /*#__PURE__*/function () {
2230
2259
  };
2231
2260
  }();
2232
2261
 
2233
- var _excluded$1 = ["data", "ticketHoldersFields", "skipCustomFields", "onGetCustomFieldsError", "onGetCustomFieldsSuccess"];
2262
+ var _excluded$1 = ["data", "ticketHoldersFields", "skipCustomFields", "customFieldsEventId", "onGetCustomFieldsError", "onGetCustomFieldsSuccess"];
2234
2263
  var withCustomFields = function withCustomFields(Children) {
2235
2264
  return function (props) {
2236
2265
  var _props$data = props.data,
@@ -2242,6 +2271,7 @@ var withCustomFields = function withCustomFields(Children) {
2242
2271
  } : _props$ticketHoldersF,
2243
2272
  _props$skipCustomFiel = props.skipCustomFields,
2244
2273
  skipCustomFields = _props$skipCustomFiel === void 0 ? true : _props$skipCustomFiel,
2274
+ eventIdProp = props.customFieldsEventId,
2245
2275
  _props$onGetCustomFie = props.onGetCustomFieldsError,
2246
2276
  onGetCustomFieldsError = _props$onGetCustomFie === void 0 ? _identity : _props$onGetCustomFie,
2247
2277
  _props$onGetCustomFie2 = props.onGetCustomFieldsSuccess,
@@ -2262,18 +2292,59 @@ var withCustomFields = function withCustomFields(Children) {
2262
2292
  var _useState5 = useState([]),
2263
2293
  customFieldsAddOnKeys = _useState5[0],
2264
2294
  setCustomFieldsAddOnKeys = _useState5[1];
2265
- var getFields = /*#__PURE__*/function () {
2295
+ // The billing page URL often carries no event id (path routes, single-page
2296
+ // checkouts), so fall back to the event the cart session belongs to. Without
2297
+ // any id, the request would hit `/v1/event//custom_fields` and fail.
2298
+ var resolveEventId = /*#__PURE__*/function () {
2266
2299
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2267
- var eventId, customFields, orderFieldsKeys, ticketHoldersFieldsKeys, addOnFieldsKeys;
2300
+ var fromUrl, configs, fromCart;
2268
2301
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2269
2302
  while (1) switch (_context.prev = _context.next) {
2270
2303
  case 0:
2271
- _context.prev = 0;
2272
- eventId = getQueryVariable('event_id') || getQueryVariable("eventId") || '';
2273
- _context.next = 4;
2304
+ fromUrl = getQueryVariable('event_id') || getQueryVariable('eventId');
2305
+ if (!(eventIdProp || fromUrl)) {
2306
+ _context.next = 3;
2307
+ break;
2308
+ }
2309
+ return _context.abrupt("return", String(eventIdProp || fromUrl));
2310
+ case 3:
2311
+ _context.next = 5;
2312
+ return getCheckoutPageConfigs();
2313
+ case 5:
2314
+ configs = _context.sent;
2315
+ fromCart = _get(configs, 'data.attributes.event_id');
2316
+ return _context.abrupt("return", fromCart ? String(fromCart) : '');
2317
+ case 8:
2318
+ case "end":
2319
+ return _context.stop();
2320
+ }
2321
+ }, _callee);
2322
+ }));
2323
+ return function resolveEventId() {
2324
+ return _ref.apply(this, arguments);
2325
+ };
2326
+ }();
2327
+ var getFields = /*#__PURE__*/function () {
2328
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
2329
+ var eventId, customFields, orderFieldsKeys, ticketHoldersFieldsKeys, addOnFieldsKeys;
2330
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2331
+ while (1) switch (_context2.prev = _context2.next) {
2332
+ case 0:
2333
+ _context2.prev = 0;
2334
+ _context2.next = 3;
2335
+ return resolveEventId();
2336
+ case 3:
2337
+ eventId = _context2.sent;
2338
+ if (eventId) {
2339
+ _context2.next = 6;
2340
+ break;
2341
+ }
2342
+ return _context2.abrupt("return");
2343
+ case 6:
2344
+ _context2.next = 8;
2274
2345
  return getCustomFields(eventId);
2275
- case 4:
2276
- customFields = _context.sent;
2346
+ case 8:
2347
+ customFields = _context2.sent;
2277
2348
  orderFieldsKeys = getFieldsKeys(_get(customFields, 'orderFields', []));
2278
2349
  ticketHoldersFieldsKeys = getFieldsKeys(_get(customFields, 'ticketsFields', []));
2279
2350
  addOnFieldsKeys = getFieldsKeys(_get(customFields, 'addOnFields', []));
@@ -2282,24 +2353,24 @@ var withCustomFields = function withCustomFields(Children) {
2282
2353
  setCustomFieldsData(customFields);
2283
2354
  setCustomFieldsAddOnKeys(addOnFieldsKeys);
2284
2355
  onGetCustomFieldsSuccess(customFields);
2285
- _context.next = 18;
2356
+ _context2.next = 22;
2286
2357
  break;
2287
- case 15:
2288
- _context.prev = 15;
2289
- _context.t0 = _context["catch"](0);
2290
- onGetCustomFieldsError(_context.t0);
2291
- case 18:
2292
- _context.prev = 18;
2358
+ case 19:
2359
+ _context2.prev = 19;
2360
+ _context2.t0 = _context2["catch"](0);
2361
+ onGetCustomFieldsError(_context2.t0);
2362
+ case 22:
2363
+ _context2.prev = 22;
2293
2364
  setLoading(false);
2294
- return _context.finish(18);
2295
- case 21:
2365
+ return _context2.finish(22);
2366
+ case 25:
2296
2367
  case "end":
2297
- return _context.stop();
2368
+ return _context2.stop();
2298
2369
  }
2299
- }, _callee, null, [[0, 15, 18, 21]]);
2370
+ }, _callee2, null, [[0, 19, 22, 25]]);
2300
2371
  }));
2301
2372
  return function getFields() {
2302
- return _ref.apply(this, arguments);
2373
+ return _ref2.apply(this, arguments);
2303
2374
  };
2304
2375
  }();
2305
2376
  useEffect(function () {
@@ -7105,6 +7176,11 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7105
7176
  checkoutUpdateData = _useState24[0],
7106
7177
  setCheckoutUpdateData = _useState24[1];
7107
7178
  var prevData = useRef(data);
7179
+ // Ticket type of each holder slot — scopes ticket custom fields that list
7180
+ // `ticketTypes` in their settings to the holders of those ticket types.
7181
+ var holderTicketTypeIds = useMemo(function () {
7182
+ return getHolderTicketTypeIds(_get(checkoutUpdateData, 'cart_price_breakdown.tickets_price_breakdown'), ticketsQuantity.length);
7183
+ }, [checkoutUpdateData, ticketsQuantity.length]);
7108
7184
  var addAddOnsInAttributes = useCallback(function (checkoutBody) {
7109
7185
  var selectedAddOns = window.localStorage.getItem('add_ons') || '{}';
7110
7186
  var addOnDataCapture = window.localStorage.getItem('add_on_data_capture') || '{}';
@@ -7420,12 +7496,20 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7420
7496
  (_checkoutBody$attribu = checkoutBody.attributes) == null ? true : delete _checkoutBody$attribu[attributeKey];
7421
7497
  });
7422
7498
  // Collect data_capture for Ticket Holders Fields
7499
+ var ticketCustomGroup = _find(ticketHoldersFields.fields, 'customFields');
7500
+ var ticketCustomFields = (ticketCustomGroup == null ? void 0 : ticketCustomGroup.groupItems) || [];
7423
7501
  _forEach(checkoutBody.attributes.ticket_holders, function (holder, holderIndex) {
7424
7502
  var holderDataCapture = {};
7425
7503
  _forEach(customFieldsTicketHolderKeys, function (customFieldKey) {
7426
7504
  var customFieldHolderName = customFieldKey + "-" + holderIndex;
7427
- var customFieldHolderKey = values[customFieldHolderName] || '';
7428
- holderDataCapture[customFieldKey] = customFieldHolderKey;
7505
+ var field = _find(ticketCustomFields, function (_ref12) {
7506
+ var name = _ref12.name;
7507
+ return name === customFieldKey;
7508
+ });
7509
+ // Fields scoped to other ticket types were never shown to this holder.
7510
+ if (!field || customFieldAppliesToTicketType(field, holderTicketTypeIds[+holderIndex])) {
7511
+ holderDataCapture[customFieldKey] = values[customFieldHolderName] || '';
7512
+ }
7429
7513
  // Delete holder specific value from values list
7430
7514
  delete checkoutBody.attributes[customFieldHolderName];
7431
7515
  });
@@ -7475,7 +7559,7 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7475
7559
  return {
7476
7560
  attributes: mergedAttributes
7477
7561
  };
7478
- }, [showDOB, showTicketHolders, canSkipHolderNames, customFieldsOrderKeys, ticketsQuantity.length, emailLogged, firstNameLogged, lastNameLogged, phoneLogged, customFieldsTicketHolderKeys]);
7562
+ }, [showDOB, showTicketHolders, canSkipHolderNames, customFieldsOrderKeys, ticketsQuantity.length, emailLogged, firstNameLogged, lastNameLogged, phoneLogged, customFieldsTicketHolderKeys, ticketHoldersFields, holderTicketTypeIds]);
7479
7563
  var removeReferralKey = useCallback(function () {
7480
7564
  localStorage.removeItem('referral_key');
7481
7565
  }, []);
@@ -7505,7 +7589,7 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7505
7589
  }),
7506
7590
  processPayment = _useStripePayment.processPayment;
7507
7591
  var updateCheckoutWithAddOns = useCallback( /*#__PURE__*/function () {
7508
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(addOns) {
7592
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(addOns) {
7509
7593
  var mergedAddOns, _checkoutUpdateData, checkoutResponse, checkoutDataObj, updatedAttributes, errorMessage;
7510
7594
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7511
7595
  while (1) switch (_context8.prev = _context8.next) {
@@ -7520,9 +7604,9 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7520
7604
  return _context8.abrupt("return");
7521
7605
  case 3:
7522
7606
  mergedAddOns = _extends({}, singleCheckoutAddons); // Update existing entries and add new ones
7523
- Object.entries(addOns).forEach(function (_ref13) {
7524
- var key = _ref13[0],
7525
- value = _ref13[1];
7607
+ Object.entries(addOns).forEach(function (_ref14) {
7608
+ var key = _ref14[0],
7609
+ value = _ref14[1];
7526
7610
  var amount = Number(value);
7527
7611
  if (amount) {
7528
7612
  mergedAddOns[key] = amount;
@@ -7566,11 +7650,11 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7566
7650
  }, _callee8, null, [[5, 13]]);
7567
7651
  }));
7568
7652
  return function (_x) {
7569
- return _ref12.apply(this, arguments);
7653
+ return _ref13.apply(this, arguments);
7570
7654
  };
7571
7655
  }(), [eventId, isSinglePageCheckout, onCheckoutUpdateError, onCheckoutUpdateSuccess]);
7572
7656
  var handleAddOnSelect = useCallback( /*#__PURE__*/function () {
7573
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(selectedAddOns) {
7657
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(selectedAddOns) {
7574
7658
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7575
7659
  while (1) switch (_context9.prev = _context9.next) {
7576
7660
  case 0:
@@ -7583,7 +7667,7 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
7583
7667
  }, _callee9);
7584
7668
  }));
7585
7669
  return function (_x2) {
7586
- return _ref14.apply(this, arguments);
7670
+ return _ref15.apply(this, arguments);
7587
7671
  };
7588
7672
  }(), [updateCheckoutWithAddOns]);
7589
7673
  var onAddOnSelect = useCallback(function (id, value, _addon, fieldUpdates) {
@@ -8038,13 +8122,18 @@ var BillingInfoContainer = /*#__PURE__*/React.memo(function (_ref6) {
8038
8122
  key: _item
8039
8123
  }, React.createElement("h5", null, "Ticket ", index + 1), _map(ticketHoldersFields.fields, function (group) {
8040
8124
  var id = group.id,
8041
- groupClassname = group.groupClassname,
8042
- groupItems = group.groupItems;
8125
+ groupClassname = group.groupClassname;
8126
+ var groupItems = group.customFields ? group.groupItems.filter(function (item) {
8127
+ return customFieldAppliesToTicketType(item, holderTicketTypeIds[index]);
8128
+ }) : group.groupItems;
8129
+ if (_isEmpty(groupItems)) return null;
8043
8130
  return React.createElement("div", {
8044
8131
  key: id
8045
8132
  }, React.createElement("div", {
8046
8133
  className: groupClassname
8047
- }, _map(groupItems, function (element) {
8134
+ }, _map(groupItems, function (item) {
8135
+ // Scoping metadata, not a Field prop.
8136
+ var element = _omit(item, 'ticketTypeIds');
8048
8137
  return React.createElement("div", {
8049
8138
  className: element.className,
8050
8139
  key: element.name
@@ -10374,9 +10463,9 @@ var TicketsSection = function TicketsSection(_ref) {
10374
10463
  var ticketOldPriceWithFees = priceSymbol + " " + (+ticket.oldBasePrice).toFixed(2);
10375
10464
  var ticketOldPriceWithoutFees = priceSymbol + " " + (+ticket.oldCost).toFixed(2);
10376
10465
  var ticketFinalPrice = ticket.feeIncluded && !ticket.isForward ? +(ticket.x_face_value || ticket.basePrice) : ticket.feeIncluded ? +ticket.basePrice : +ticket.cost;
10377
- var ticketFinalPriceFormatted = priceSymbol + " " + Math.round(ticketFinalPrice);
10466
+ var ticketFinalPriceFormatted = priceSymbol + " " + parseFloat(ticketFinalPrice.toFixed(2));
10378
10467
  var ticketOldFinalPrice = ticket.feeIncluded && !ticket.isForward ? +(ticket.x_face_value || ticket.basePrice) : ticket.feeIncluded ? +ticket.oldBasePrice : +ticket.oldCost;
10379
- var ticketOldFinalPriceFormatted = priceSymbol + " " + Math.round(ticketOldFinalPrice);
10468
+ var ticketOldFinalPriceFormatted = priceSymbol + " " + parseFloat(ticketOldFinalPrice.toFixed(2));
10380
10469
  var ticketFeeAmount = (+ticket.basePrice - +ticket.cost).toFixed(2);
10381
10470
  var ticketBreakdown = !ticket.feeIncluded ? '(+ fees at checkout)' : !ticket.isForward ? null : parseFloat(ticketFeeAmount) > 0 ? "(" + priceSymbol + " " + (+ticket.cost).toFixed(2) + " + " + priceSymbol + " " + ticketFeeAmount + " fee)" : null;
10382
10471
  var isSoldOut = ticket.sold_out || !(ticket.displayTicket || ticket.slotGroupId) || ticket.soldOut;
@@ -10458,9 +10547,9 @@ var TicketsSection = function TicketsSection(_ref) {
10458
10547
  var ticketOldPriceWithFees = priceSymbol + " " + (+ticket.oldBasePrice).toFixed(2);
10459
10548
  var ticketOldPriceWithoutFees = priceSymbol + " " + (+ticket.oldCost).toFixed(2);
10460
10549
  var ticketFinalPrice = ticket.feeIncluded && !ticket.isForward ? +(ticket.x_face_value || ticket.basePrice) : ticket.feeIncluded ? +ticket.basePrice : +ticket.cost;
10461
- var ticketFinalPriceFormatted = priceSymbol + " " + Math.round(ticketFinalPrice);
10550
+ var ticketFinalPriceFormatted = priceSymbol + " " + parseFloat(ticketFinalPrice.toFixed(2));
10462
10551
  var ticketOldFinalPrice = ticket.feeIncluded && !ticket.isForward ? +(ticket.x_face_value || ticket.basePrice) : ticket.feeIncluded ? +ticket.oldBasePrice : +ticket.oldCost;
10463
- var ticketOldFinalPriceFormatted = priceSymbol + " " + Math.round(ticketOldFinalPrice);
10552
+ var ticketOldFinalPriceFormatted = priceSymbol + " " + parseFloat(ticketOldFinalPrice.toFixed(2));
10464
10553
  var ticketFeeAmount = (+ticket.basePrice - +ticket.cost).toFixed(2);
10465
10554
  var ticketBreakdown = !ticket.feeIncluded ? '(+ fees at checkout)' : !ticket.isForward ? null : parseFloat(ticketFeeAmount) > 0 ? "(" + priceSymbol + " " + (+ticket.cost).toFixed(2) + " + " + priceSymbol + " " + ticketFeeAmount + " fee)" : null;
10466
10555
  var isSoldOut = ticket.sold_out || !(ticket.displayTicket || ticket.slotGroupId) || ticket.soldOut;
@@ -10576,9 +10665,9 @@ var TimeSlotTicketRow = function TimeSlotTicketRow(_ref) {
10576
10665
  var ticketOldPriceWithFees = priceSymbol + " " + (+ticket.oldBasePrice).toFixed(2);
10577
10666
  var ticketOldPriceWithoutFees = priceSymbol + " " + (+ticket.oldCost).toFixed(2);
10578
10667
  var ticketFinalPrice = ticket.feeIncluded && !ticket.isForward ? +(ticket.x_face_value || ticket.basePrice) : ticket.feeIncluded ? +ticket.basePrice : +ticket.cost;
10579
- var ticketFinalPriceFormatted = priceSymbol + " " + Math.round(ticketFinalPrice);
10668
+ var ticketFinalPriceFormatted = priceSymbol + " " + parseFloat(ticketFinalPrice.toFixed(2));
10580
10669
  var ticketOldFinalPrice = ticket.feeIncluded && !ticket.isForward ? +(ticket.x_face_value || ticket.basePrice) : ticket.feeIncluded ? +ticket.oldBasePrice : +ticket.oldCost;
10581
- var ticketOldFinalPriceFormatted = priceSymbol + " " + Math.round(ticketOldFinalPrice);
10670
+ var ticketOldFinalPriceFormatted = priceSymbol + " " + parseFloat(ticketOldFinalPrice.toFixed(2));
10582
10671
  var ticketFeeAmount = (+ticket.basePrice - +ticket.cost).toFixed(2);
10583
10672
  var ticketBreakdown = !ticket.feeIncluded ? '(+ fees at checkout)' : !ticket.isForward ? null : parseFloat(ticketFeeAmount) > 0 ? "(" + priceSymbol + " " + (+ticket.cost).toFixed(2) + " + " + priceSymbol + " " + ticketFeeAmount + " fee)" : null;
10584
10673
  var ticketIsDiscounted = false;