iticket-seatingplan-dev 1.8.0 → 1.8.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.
- package/dist/components/SeatingPlan.js +67 -45
- package/dist/utils/helpers.js +4 -8
- package/package.json +1 -1
|
@@ -24,7 +24,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
24
24
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
25
25
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
26
26
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
|
-
const
|
|
27
|
+
const SEATINGPLAN_MAX_RETRIES = 5;
|
|
28
|
+
const BOOKING_MAX_RETRIES = 2;
|
|
28
29
|
const SeatingPlan = _ref => {
|
|
29
30
|
var _document, _document2, _document3;
|
|
30
31
|
let {
|
|
@@ -83,8 +84,9 @@ const SeatingPlan = _ref => {
|
|
|
83
84
|
};
|
|
84
85
|
callbackFunction === null || callbackFunction === void 0 || callbackFunction(event);
|
|
85
86
|
};
|
|
86
|
-
const
|
|
87
|
+
const _addTicketToCart = async function addTicketToCart(s, priceage) {
|
|
87
88
|
var _mapRef$current;
|
|
89
|
+
let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
88
90
|
const updatedSeats = _objectSpread({}, seats);
|
|
89
91
|
const seatIndex = updatedSeats.seats.findIndex(seat => seat.ssId === s.ssId);
|
|
90
92
|
const setSeatLoading = loading => {
|
|
@@ -109,19 +111,20 @@ const SeatingPlan = _ref => {
|
|
|
109
111
|
return;
|
|
110
112
|
}
|
|
111
113
|
(_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 || (_mapRef$current = _mapRef$current.target) === null || _mapRef$current === void 0 || _mapRef$current.closePopup();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
try {
|
|
115
|
+
const response = await fetch(apiUrl, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
body: JSON.stringify({
|
|
118
|
+
priceAgeId: priceage.paId,
|
|
119
|
+
seatId: s.ssId,
|
|
120
|
+
price: priceage.p,
|
|
121
|
+
connectedShowings: connectedShowings
|
|
122
|
+
}),
|
|
123
|
+
headers: {
|
|
124
|
+
"content-type": "application/json",
|
|
125
|
+
"basket-key": sessionId
|
|
126
|
+
}
|
|
127
|
+
});
|
|
125
128
|
if ((response === null || response === void 0 ? void 0 : response.status) === 403 || (response === null || response === void 0 ? void 0 : response.status) === 400) {
|
|
126
129
|
if (seatIndex !== -1) {
|
|
127
130
|
updatedSeats.seats[seatIndex] = _objectSpread(_objectSpread({}, s), {}, {
|
|
@@ -135,11 +138,22 @@ const SeatingPlan = _ref => {
|
|
|
135
138
|
message: response.status === 400 ? _utils.ERROR_MESSAGES.INCOMPATIBLE_TICKETS : _utils.ERROR_MESSAGES.SEAT_UNAVAILABLE
|
|
136
139
|
});
|
|
137
140
|
} else if ((response === null || response === void 0 ? void 0 : response.status) === 429) {
|
|
141
|
+
if (retryCount < BOOKING_MAX_RETRIES) {
|
|
142
|
+
const delay = (0, _utils.getRetryDelay)(response, retryCount);
|
|
143
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
144
|
+
return _addTicketToCart(s, priceage, retryCount + 1);
|
|
145
|
+
}
|
|
138
146
|
setSeatLoading(false);
|
|
139
147
|
handleError({
|
|
140
148
|
code: 429,
|
|
141
149
|
message: _utils.ERROR_MESSAGES.SEAT_TAKEN
|
|
142
150
|
});
|
|
151
|
+
} else if (!response.ok) {
|
|
152
|
+
setSeatLoading(false);
|
|
153
|
+
handleError({
|
|
154
|
+
code: 500,
|
|
155
|
+
message: _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
156
|
+
});
|
|
143
157
|
} else {
|
|
144
158
|
if (seatIndex !== -1) {
|
|
145
159
|
updatedSeats.seats[seatIndex] = _objectSpread(_objectSpread({}, s), {}, {
|
|
@@ -172,15 +186,14 @@ const SeatingPlan = _ref => {
|
|
|
172
186
|
};
|
|
173
187
|
callbackFunction === null || callbackFunction === void 0 || callbackFunction(event);
|
|
174
188
|
}
|
|
175
|
-
}
|
|
189
|
+
} catch (_unused) {
|
|
176
190
|
setSeatLoading(false);
|
|
177
191
|
handleError({
|
|
178
192
|
code: 500,
|
|
179
193
|
message: _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
180
194
|
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
});
|
|
195
|
+
}
|
|
196
|
+
_initialFetch(true);
|
|
184
197
|
};
|
|
185
198
|
const removeTicketFromCart = (s, e) => {
|
|
186
199
|
const updatedSeats = _objectSpread({}, seats);
|
|
@@ -241,31 +254,40 @@ const SeatingPlan = _ref => {
|
|
|
241
254
|
};
|
|
242
255
|
setSeatsLoading(true);
|
|
243
256
|
const succeeded = [];
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
if (!res.ok) {
|
|
261
|
-
throw new Error("".concat(res.status));
|
|
257
|
+
const _tryBook = async function tryBook(seatToBook) {
|
|
258
|
+
let retryCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
259
|
+
try {
|
|
260
|
+
const res = await fetch(apiUrl, {
|
|
261
|
+
method: "POST",
|
|
262
|
+
body: JSON.stringify({
|
|
263
|
+
priceAgeId: seatToBook.priceage.paId,
|
|
264
|
+
seatId: seatToBook.seat.ssId,
|
|
265
|
+
price: seatToBook.priceage.p,
|
|
266
|
+
connectedShowings: connectedShowings
|
|
267
|
+
}),
|
|
268
|
+
headers: {
|
|
269
|
+
"content-type": "application/json",
|
|
270
|
+
"basket-key": sessionId
|
|
262
271
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
272
|
+
});
|
|
273
|
+
if (res.status === 429) {
|
|
274
|
+
if (retryCount < BOOKING_MAX_RETRIES) {
|
|
275
|
+
const delay = (0, _utils.getRetryDelay)(res, retryCount);
|
|
276
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
277
|
+
return _tryBook(seatToBook, retryCount + 1);
|
|
278
|
+
}
|
|
279
|
+
throw new Error("429");
|
|
267
280
|
}
|
|
281
|
+
if (!res.ok) {
|
|
282
|
+
throw new Error("".concat(res.status));
|
|
283
|
+
}
|
|
284
|
+
succeeded.push(seatToBook);
|
|
285
|
+
} catch (_unused2) {
|
|
286
|
+
throw new Error("Booking failed for seat ".concat(seatToBook.seat.r, " ").concat(seatToBook.seat.c));
|
|
268
287
|
}
|
|
288
|
+
};
|
|
289
|
+
try {
|
|
290
|
+
await Promise.all(seatsToBook.map(seatToBook => _tryBook(seatToBook)));
|
|
269
291
|
setBookedSeats(prev => [...prev, ...seatsToBook.map(_ref2 => {
|
|
270
292
|
let {
|
|
271
293
|
seat,
|
|
@@ -357,7 +379,7 @@ const SeatingPlan = _ref => {
|
|
|
357
379
|
console.error("Failed to remove seat ".concat(seat, ":"), error);
|
|
358
380
|
}
|
|
359
381
|
}
|
|
360
|
-
} catch (
|
|
382
|
+
} catch (_unused3) {
|
|
361
383
|
handleError({
|
|
362
384
|
code: 500,
|
|
363
385
|
message: _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
@@ -402,7 +424,7 @@ const SeatingPlan = _ref => {
|
|
|
402
424
|
const availablePrices = ((_seats$pricing = seats.pricing) === null || _seats$pricing === void 0 ? void 0 : _seats$pricing.filter(price => (!priceSectionIds || priceSectionIds.includes(price.psId)) && s.psId === price.psId)) || [];
|
|
403
425
|
const isSingleFlexi = availablePrices.length === 1 && !!availablePrices[0].pMax && !!availablePrices[0].pMin && availablePrices[0].pMax > availablePrices[0].pMin;
|
|
404
426
|
if (availablePrices.length === 1 && !isSingleFlexi) {
|
|
405
|
-
|
|
427
|
+
_addTicketToCart(s, availablePrices[0]);
|
|
406
428
|
}
|
|
407
429
|
} else {
|
|
408
430
|
removeTicketFromCart(s, e);
|
|
@@ -426,7 +448,7 @@ const SeatingPlan = _ref => {
|
|
|
426
448
|
}
|
|
427
449
|
});
|
|
428
450
|
if (response.status === 429) {
|
|
429
|
-
if (retryCount >=
|
|
451
|
+
if (retryCount >= SEATINGPLAN_MAX_RETRIES) {
|
|
430
452
|
throw new Error("We're experiencing high demand. Please try again later.");
|
|
431
453
|
}
|
|
432
454
|
const delay = (0, _utils.getRetryDelay)(response, retryCount);
|
|
@@ -553,7 +575,7 @@ const SeatingPlan = _ref => {
|
|
|
553
575
|
setTicketPopupOpen: setTicketPopupOpen,
|
|
554
576
|
chosenSeat: chosenSeat,
|
|
555
577
|
bookedSeats: bookedSeats,
|
|
556
|
-
addTicketToCart:
|
|
578
|
+
addTicketToCart: _addTicketToCart,
|
|
557
579
|
batchRemoveTicketsFromCart: batchRemoveTicketsFromCart,
|
|
558
580
|
isReloading: isReloading,
|
|
559
581
|
initialFetch: _initialFetch,
|
package/dist/utils/helpers.js
CHANGED
|
@@ -8,14 +8,10 @@ var _enums = require("./enums");
|
|
|
8
8
|
const getIsTouchScreen = () => {
|
|
9
9
|
let hasTouchScreen = false;
|
|
10
10
|
if (typeof window !== "undefined") {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const mQ = (_matchMedia = matchMedia) === null || _matchMedia === void 0 ? void 0 : _matchMedia("(pointer: coarse)");
|
|
16
|
-
if ((mQ === null || mQ === void 0 ? void 0 : mQ.media) === "(pointer: coarse)") {
|
|
17
|
-
hasTouchScreen = !!mQ.matches;
|
|
18
|
-
}
|
|
11
|
+
var _matchMedia;
|
|
12
|
+
const mQ = (_matchMedia = matchMedia) === null || _matchMedia === void 0 ? void 0 : _matchMedia("(hover: none)");
|
|
13
|
+
if ((mQ === null || mQ === void 0 ? void 0 : mQ.media) === "(hover: none)") {
|
|
14
|
+
hasTouchScreen = !!mQ.matches;
|
|
19
15
|
}
|
|
20
16
|
}
|
|
21
17
|
return hasTouchScreen;
|