iticket-seatingplan-dev 1.8.3 → 1.8.4
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 +51 -74
- package/dist/utils/helpers.js +3 -5
- package/package.json +1 -1
|
@@ -94,6 +94,20 @@ const SeatingPlan = _ref => {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
+
const setSeatsLoading = (seatsToUpdate, loading) => {
|
|
98
|
+
setSeats(prev => {
|
|
99
|
+
const updatedSeats = _objectSpread({}, prev);
|
|
100
|
+
seatsToUpdate.forEach(seat => {
|
|
101
|
+
const seatIndex = updatedSeats.seats.findIndex(s => s.ssId === seat.ssId);
|
|
102
|
+
if (seatIndex !== -1) {
|
|
103
|
+
updatedSeats.seats[seatIndex] = _objectSpread(_objectSpread({}, updatedSeats.seats[seatIndex]), {}, {
|
|
104
|
+
loading: loading
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return updatedSeats;
|
|
109
|
+
});
|
|
110
|
+
};
|
|
97
111
|
const _addTicketToCart = async function addTicketToCart(s, priceage) {
|
|
98
112
|
var _mapRef$current;
|
|
99
113
|
let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
@@ -135,7 +149,7 @@ const SeatingPlan = _ref => {
|
|
|
135
149
|
if ((response === null || response === void 0 ? void 0 : response.status) === 429) {
|
|
136
150
|
if (retryCount < BOOKING_MAX_RETRIES) {
|
|
137
151
|
setRetrying(prev => [...prev, s.ssId]);
|
|
138
|
-
const delay = (0, _utils.getRetryDelay)(response
|
|
152
|
+
const delay = (0, _utils.getRetryDelay)(response);
|
|
139
153
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
140
154
|
return _addTicketToCart(s, priceage, retryCount + 1);
|
|
141
155
|
}
|
|
@@ -161,41 +175,34 @@ const SeatingPlan = _ref => {
|
|
|
161
175
|
});
|
|
162
176
|
return;
|
|
163
177
|
}
|
|
164
|
-
updateSeat(seatIndex, _objectSpread(_objectSpread({}, s), {}, {
|
|
165
|
-
loading: false
|
|
166
|
-
}));
|
|
167
178
|
if (!(response !== null && response !== void 0 && response.ok)) {
|
|
179
|
+
updateSeat(seatIndex, _objectSpread(_objectSpread({}, s), {}, {
|
|
180
|
+
loading: false
|
|
181
|
+
}));
|
|
168
182
|
handleError({
|
|
169
183
|
code: (response === null || response === void 0 ? void 0 : response.status) === 400 ? 400 : 500,
|
|
170
184
|
message: (response === null || response === void 0 ? void 0 : response.status) === 400 ? _utils.ERROR_MESSAGES.INCOMPATIBLE_TICKETS : _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
171
185
|
});
|
|
172
186
|
} else {
|
|
173
|
-
setRetrying(prev => prev.filter(id => id !== s.ssId));
|
|
174
187
|
updateSeat(seatIndex, _objectSpread(_objectSpread({}, s), {}, {
|
|
175
188
|
loading: false,
|
|
176
189
|
s: _utils.statuses.USER_PENDING,
|
|
177
190
|
bookedPrice: price
|
|
178
191
|
}));
|
|
179
|
-
setBookedSeats(prev => [...prev, {
|
|
180
|
-
ssId: s.ssId,
|
|
181
|
-
r: s.r,
|
|
182
|
-
c: s.c,
|
|
192
|
+
setBookedSeats(prev => [...prev, _objectSpread(_objectSpread({}, s), {}, {
|
|
183
193
|
showingId: showingId,
|
|
184
194
|
pId: priceage.paId,
|
|
185
195
|
p: priceage.p,
|
|
186
196
|
paName: priceage.paName
|
|
187
|
-
}]);
|
|
197
|
+
})]);
|
|
188
198
|
const event = {
|
|
189
199
|
type: "cart-change-add",
|
|
190
|
-
details: [
|
|
191
|
-
ssId: s.ssId,
|
|
192
|
-
r: s.r,
|
|
193
|
-
c: s.c,
|
|
200
|
+
details: [_objectSpread(_objectSpread({}, s), {}, {
|
|
194
201
|
showingId: showingId,
|
|
195
202
|
pId: priceage.paId,
|
|
196
203
|
p: priceage.p,
|
|
197
204
|
paName: priceage.paName
|
|
198
|
-
}]
|
|
205
|
+
})]
|
|
199
206
|
};
|
|
200
207
|
callbackFunction === null || callbackFunction === void 0 || callbackFunction(event);
|
|
201
208
|
}
|
|
@@ -210,17 +217,21 @@ const SeatingPlan = _ref => {
|
|
|
210
217
|
});
|
|
211
218
|
}
|
|
212
219
|
};
|
|
213
|
-
const removeTicketFromCart = (s, e) => {
|
|
220
|
+
const removeTicketFromCart = async (s, e) => {
|
|
214
221
|
const seatIndex = seats.seats.findIndex(seat => seat.ssId === s.ssId);
|
|
215
222
|
updateSeat(seatIndex, _objectSpread(_objectSpread({}, s), {}, {
|
|
216
223
|
loading: true
|
|
217
224
|
}));
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
225
|
+
try {
|
|
226
|
+
const response = await fetch("".concat(apiUrl, "/seat/").concat(s.ssId), {
|
|
227
|
+
method: "DELETE",
|
|
228
|
+
headers: {
|
|
229
|
+
"basket-key": sessionId
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
throw new Error("".concat(response.status));
|
|
222
234
|
}
|
|
223
|
-
}).then(() => {
|
|
224
235
|
updateSeat(seatIndex, _objectSpread(_objectSpread({}, s), {}, {
|
|
225
236
|
loading: false,
|
|
226
237
|
s: _utils.statuses.UNSOLD,
|
|
@@ -232,7 +243,7 @@ const SeatingPlan = _ref => {
|
|
|
232
243
|
details: bookedSeats.filter(bs => bs.ssId === s.ssId)
|
|
233
244
|
};
|
|
234
245
|
callbackFunction === null || callbackFunction === void 0 || callbackFunction(event);
|
|
235
|
-
}
|
|
246
|
+
} catch (_unused2) {
|
|
236
247
|
updateSeat(seatIndex, _objectSpread(_objectSpread({}, s), {}, {
|
|
237
248
|
loading: false
|
|
238
249
|
}));
|
|
@@ -240,30 +251,13 @@ const SeatingPlan = _ref => {
|
|
|
240
251
|
code: 500,
|
|
241
252
|
message: _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
242
253
|
});
|
|
243
|
-
}
|
|
254
|
+
}
|
|
244
255
|
};
|
|
245
256
|
const batchAddTicketsToCart = async seatsToBook => {
|
|
246
257
|
if (!canMultiSelect && !seats.preventOrphanedSeats || seatsToBook.length === 0) {
|
|
247
258
|
return;
|
|
248
259
|
}
|
|
249
|
-
|
|
250
|
-
setSeats(prev => {
|
|
251
|
-
const updatedSeats = _objectSpread({}, prev);
|
|
252
|
-
seatsToBook.forEach(_ref2 => {
|
|
253
|
-
let {
|
|
254
|
-
seat
|
|
255
|
-
} = _ref2;
|
|
256
|
-
const seatIndex = updatedSeats.seats.findIndex(s => s.ssId === seat.ssId);
|
|
257
|
-
if (seatIndex !== -1) {
|
|
258
|
-
updatedSeats.seats[seatIndex] = _objectSpread(_objectSpread({}, updatedSeats.seats[seatIndex]), {}, {
|
|
259
|
-
loading: loading
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
return updatedSeats;
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
setSeatsLoading(true);
|
|
260
|
+
setSeatsLoading(seatsToBook.map(seat => seat.seat), true);
|
|
267
261
|
const succeeded = [];
|
|
268
262
|
const _tryBook = async function tryBook(seatToBook) {
|
|
269
263
|
let retryCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -284,7 +278,7 @@ const SeatingPlan = _ref => {
|
|
|
284
278
|
if (res.status === 429) {
|
|
285
279
|
if (retryCount < BOOKING_MAX_RETRIES) {
|
|
286
280
|
setRetrying(prev => [...prev, seatToBook.seat.ssId]);
|
|
287
|
-
const delay = (0, _utils.getRetryDelay)(res
|
|
281
|
+
const delay = (0, _utils.getRetryDelay)(res);
|
|
288
282
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
289
283
|
return _tryBook(seatToBook, retryCount + 1);
|
|
290
284
|
} else {
|
|
@@ -294,7 +288,7 @@ const SeatingPlan = _ref => {
|
|
|
294
288
|
throw new Error("".concat(res.status));
|
|
295
289
|
}
|
|
296
290
|
succeeded.push(seatToBook.seat);
|
|
297
|
-
} catch (
|
|
291
|
+
} catch (_unused3) {
|
|
298
292
|
throw new Error("Booking failed for seat ".concat(seatToBook.seat.r, " ").concat(seatToBook.seat.c));
|
|
299
293
|
}
|
|
300
294
|
};
|
|
@@ -303,27 +297,24 @@ const SeatingPlan = _ref => {
|
|
|
303
297
|
await _tryBook(seatToBook);
|
|
304
298
|
}
|
|
305
299
|
setRetrying(prev => prev.filter(id => !seatsToBook.some(s => s.seat.ssId === id)));
|
|
306
|
-
setBookedSeats(prev => [...prev, ...seatsToBook.map(
|
|
300
|
+
setBookedSeats(prev => [...prev, ...seatsToBook.map(_ref2 => {
|
|
307
301
|
let {
|
|
308
302
|
seat,
|
|
309
303
|
priceage
|
|
310
|
-
} =
|
|
311
|
-
return {
|
|
312
|
-
ssId: seat.ssId,
|
|
313
|
-
r: seat.r,
|
|
314
|
-
c: seat.c,
|
|
304
|
+
} = _ref2;
|
|
305
|
+
return _objectSpread(_objectSpread({}, seat), {}, {
|
|
315
306
|
showingId: showingId,
|
|
316
307
|
pId: priceage.paId,
|
|
317
308
|
p: priceage.p,
|
|
318
309
|
paName: priceage.paName
|
|
319
|
-
};
|
|
310
|
+
});
|
|
320
311
|
})]);
|
|
321
312
|
setSeats(prev => {
|
|
322
313
|
const updatedSeats = _objectSpread({}, prev);
|
|
323
|
-
seatsToBook.forEach(
|
|
314
|
+
seatsToBook.forEach(_ref3 => {
|
|
324
315
|
let {
|
|
325
316
|
seat
|
|
326
|
-
} =
|
|
317
|
+
} = _ref3;
|
|
327
318
|
const seatIndex = updatedSeats.seats.findIndex(s => s.ssId === seat.ssId);
|
|
328
319
|
if (seatIndex !== -1) {
|
|
329
320
|
updatedSeats.seats[seatIndex] = _objectSpread(_objectSpread({}, updatedSeats.seats[seatIndex]), {}, {
|
|
@@ -337,20 +328,17 @@ const SeatingPlan = _ref => {
|
|
|
337
328
|
});
|
|
338
329
|
const event = {
|
|
339
330
|
type: "cart-change-add",
|
|
340
|
-
details: [...
|
|
331
|
+
details: [...seatsToBook.map(_ref4 => {
|
|
341
332
|
let {
|
|
342
333
|
seat,
|
|
343
334
|
priceage
|
|
344
|
-
} =
|
|
345
|
-
return {
|
|
346
|
-
ssId: seat.ssId,
|
|
347
|
-
r: seat.r,
|
|
348
|
-
c: seat.c,
|
|
335
|
+
} = _ref4;
|
|
336
|
+
return _objectSpread(_objectSpread({}, seat), {}, {
|
|
349
337
|
showingId: showingId,
|
|
350
338
|
pId: priceage.paId,
|
|
351
339
|
p: priceage.p,
|
|
352
340
|
paName: priceage.paName
|
|
353
|
-
};
|
|
341
|
+
});
|
|
354
342
|
})]
|
|
355
343
|
};
|
|
356
344
|
callbackFunction === null || callbackFunction === void 0 || callbackFunction(event);
|
|
@@ -365,7 +353,7 @@ const SeatingPlan = _ref => {
|
|
|
365
353
|
}
|
|
366
354
|
});
|
|
367
355
|
}
|
|
368
|
-
setSeatsLoading(false);
|
|
356
|
+
setSeatsLoading(seatsToBook.map(seat => seat.seat), false);
|
|
369
357
|
handleError({
|
|
370
358
|
code: error === "429" ? 429 : 500,
|
|
371
359
|
message: _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
@@ -376,18 +364,7 @@ const SeatingPlan = _ref => {
|
|
|
376
364
|
if (!canMultiSelect && !seats.preventOrphanedSeats || seatsToRemove.length === 0) {
|
|
377
365
|
return;
|
|
378
366
|
}
|
|
379
|
-
|
|
380
|
-
const updatedSeats = _objectSpread({}, prev);
|
|
381
|
-
seatsToRemove.forEach(s => {
|
|
382
|
-
const seatIndex = updatedSeats.seats.findIndex(seat => seat.ssId === s.ssId);
|
|
383
|
-
if (seatIndex !== -1) {
|
|
384
|
-
updatedSeats.seats[seatIndex] = _objectSpread(_objectSpread({}, updatedSeats.seats[seatIndex]), {}, {
|
|
385
|
-
loading: true
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
return updatedSeats;
|
|
390
|
-
});
|
|
367
|
+
setSeatsLoading(seatsToRemove, true);
|
|
391
368
|
const succeededIds = [];
|
|
392
369
|
try {
|
|
393
370
|
for (const seat of seatsToRemove) {
|
|
@@ -406,7 +383,7 @@ const SeatingPlan = _ref => {
|
|
|
406
383
|
console.error("Failed to remove seat ".concat(seat, ":"), error);
|
|
407
384
|
}
|
|
408
385
|
}
|
|
409
|
-
} catch (
|
|
386
|
+
} catch (_unused4) {
|
|
410
387
|
handleError({
|
|
411
388
|
code: 500,
|
|
412
389
|
message: _utils.ERROR_MESSAGES.GENERIC_ERROR
|
|
@@ -481,7 +458,7 @@ const SeatingPlan = _ref => {
|
|
|
481
458
|
if (retryCount >= SEATINGPLAN_MAX_RETRIES) {
|
|
482
459
|
throw new Error("We're experiencing high demand. Please try again later.");
|
|
483
460
|
}
|
|
484
|
-
const delay = (0, _utils.getRetryDelay)(response
|
|
461
|
+
const delay = (0, _utils.getRetryDelay)(response);
|
|
485
462
|
setInitialiseMessage("We're experiencing high demand. Please wait while we try again...");
|
|
486
463
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
487
464
|
return _initialFetch(isReload, retryCount + 1);
|
package/dist/utils/helpers.js
CHANGED
|
@@ -228,15 +228,13 @@ const getAdjacentBookedSeats = (seat, seatsMap) => {
|
|
|
228
228
|
return adjacentBookedSeats;
|
|
229
229
|
};
|
|
230
230
|
exports.getAdjacentBookedSeats = getAdjacentBookedSeats;
|
|
231
|
-
const getRetryDelay =
|
|
231
|
+
const getRetryDelay = response => {
|
|
232
232
|
var _ref, _ref2, _response$headers$get;
|
|
233
233
|
const retryAfter = (_ref = (_ref2 = (_response$headers$get = response.headers.get("Retry-After")) !== null && _response$headers$get !== void 0 ? _response$headers$get : response.headers.get("retry-after")) !== null && _ref2 !== void 0 ? _ref2 : response.headers.get("rl-twm")) !== null && _ref !== void 0 ? _ref : "5";
|
|
234
|
-
|
|
235
|
-
return response.headers.get("rl-twm") ? Math.round(parseInt(retryAfter) * 60 * 1000) : parseInt(retryAfter) * 1000;
|
|
236
|
-
}
|
|
234
|
+
const delay = response.headers.get("rl-twm") ? Math.round(parseInt(retryAfter) * 60 * 1000) : parseInt(retryAfter) * 1000;
|
|
237
235
|
|
|
238
236
|
// adds jitter
|
|
239
|
-
return
|
|
237
|
+
return delay + Math.random() * 1000;
|
|
240
238
|
};
|
|
241
239
|
exports.getRetryDelay = getRetryDelay;
|
|
242
240
|
const groupSeatsByPriceSection = (seats, pricing, priceSectionIds) => {
|