@orderingstack/front-hooks 3.7.1 → 3.8.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.
package/dist/index.es.js CHANGED
@@ -1369,6 +1369,28 @@ function isEqual(value, other) {
1369
1369
  return baseIsEqual(value, other);
1370
1370
  }
1371
1371
  var isEqual_1 = isEqual;
1372
+ function addDiscounts(discounts) {
1373
+ let value = 0;
1374
+ discounts == null ? void 0 : discounts.forEach((discount) => value += Number(discount.discountPrice));
1375
+ return value;
1376
+ }
1377
+ function summarizeLineDiscounts(line) {
1378
+ return addDiscounts(line.discounts);
1379
+ }
1380
+ function formatPrice(value, currency, separator = ",", decimals = 2) {
1381
+ const price = Number(value);
1382
+ return `${price.toFixed(decimals).replace(".", separator)}${currency ? "\xA0" + currency : ""}`;
1383
+ }
1384
+ function isProductEnabled(item, enableKeys) {
1385
+ var _a;
1386
+ const enableKey = (_a = item._) == null ? void 0 : _a.enableKey;
1387
+ if (!enableKey)
1388
+ return true;
1389
+ if (!enableKeys || !Array.isArray(enableKeys) || enableKeys.length === 0)
1390
+ return false;
1391
+ const itemEnableKeys = enableKey.replace(/\s/g, "").split(",");
1392
+ return itemEnableKeys.some((key) => enableKeys.includes(key));
1393
+ }
1372
1394
  function useAvailability(originalMenu, markOnly = false, timeZone = void 0, interval = 60) {
1373
1395
  const [menu, setMenu] = useState(originalMenu ? filterTimeAvailabilityOfProducts(originalMenu, timeZone, void 0, markOnly) : originalMenu);
1374
1396
  useInterval(checkAvailability, interval * 1e3);
@@ -1382,6 +1404,32 @@ function useAvailability(originalMenu, markOnly = false, timeZone = void 0, inte
1382
1404
  useEffect(checkAvailability, [menu, originalMenu]);
1383
1405
  return menu;
1384
1406
  }
1407
+ function markHiddenByEnableKey(product, enableKeys) {
1408
+ if (!product.__) {
1409
+ product.__ = {};
1410
+ }
1411
+ product.__.isHiddenByEnableKey = !isProductEnabled(product, enableKeys);
1412
+ if (product.items && product.items.length > 0) {
1413
+ product.items = product.items.map((item) => markHiddenByEnableKey(item, enableKeys));
1414
+ }
1415
+ return product;
1416
+ }
1417
+ function markItemsHiddenByEnableKey(items, enableKeys) {
1418
+ if (!items) {
1419
+ return void 0;
1420
+ }
1421
+ return items.map((item) => markHiddenByEnableKey(item, enableKeys));
1422
+ }
1423
+ function useMenu({
1424
+ originalMenu,
1425
+ markOnly = false,
1426
+ timeZone,
1427
+ interval = 60,
1428
+ enableKeys = []
1429
+ }) {
1430
+ const menu = useAvailability(originalMenu, markOnly, timeZone, interval);
1431
+ return markItemsHiddenByEnableKey(menu, enableKeys);
1432
+ }
1385
1433
  var EPaymentStatus;
1386
1434
  (function(EPaymentStatus2) {
1387
1435
  EPaymentStatus2["UNINITIALIZED"] = "UNINITIALIZED";
@@ -1460,17 +1508,17 @@ var EOrderPaymentType;
1460
1508
  EOrderPaymentType2["RETURN"] = "RETURN";
1461
1509
  EOrderPaymentType2["EXTERNAL"] = "EXTERNAL";
1462
1510
  })(EOrderPaymentType || (EOrderPaymentType = {}));
1463
- var OrderSource;
1464
- (function(OrderSource2) {
1465
- OrderSource2["KIOSK"] = "KIOSK";
1466
- OrderSource2["WEB"] = "WEB";
1467
- OrderSource2["JUST_EAT_TAKE_AWAY"] = "JUSTEATTAKEAWAY";
1468
- OrderSource2["GLOVO"] = "GLOVO";
1469
- OrderSource2["PYSZNE"] = "PYSZNE";
1470
- OrderSource2["WOLT"] = "WOLT";
1471
- OrderSource2["UBER"] = "UBER";
1472
- OrderSource2["BOLT"] = "BOLT";
1473
- })(OrderSource || (OrderSource = {}));
1511
+ var EOrderSource;
1512
+ (function(EOrderSource2) {
1513
+ EOrderSource2["KIOSK"] = "KIOSK";
1514
+ EOrderSource2["WEB"] = "WEB";
1515
+ EOrderSource2["JUST_EAT_TAKE_AWAY"] = "JUSTEATTAKEAWAY";
1516
+ EOrderSource2["GLOVO"] = "GLOVO";
1517
+ EOrderSource2["PYSZNE"] = "PYSZNE";
1518
+ EOrderSource2["WOLT"] = "WOLT";
1519
+ EOrderSource2["UBER"] = "UBER";
1520
+ EOrderSource2["BOLT"] = "BOLT";
1521
+ })(EOrderSource || (EOrderSource = {}));
1474
1522
  var EOrderLineStatus;
1475
1523
  (function(EOrderLineStatus2) {
1476
1524
  EOrderLineStatus2["NEW"] = "NEW";
@@ -1491,12 +1539,19 @@ var EChannelName;
1491
1539
  EChannelName2["DINE_IN"] = "DINE_IN";
1492
1540
  EChannelName2["TAKE_AWAY"] = "TAKE_AWAY";
1493
1541
  EChannelName2["DELIVERY"] = "DELIVERY";
1494
- EChannelName2["GLOVO_DELIVERY"] = "GLOVO_DELIVERY";
1495
- EChannelName2["JUSTEAT_DELIVERY"] = "JUSTEAT_DELIVERY";
1496
- EChannelName2["UBER_DELIVERY"] = "UBER_DELIVERY";
1497
- EChannelName2["BOLT_DELIVERY"] = "BOLT_DELIVERY";
1498
- EChannelName2["WOLT_DELIVERY"] = "WOLT_DELIVERY";
1542
+ EChannelName2["GLOVO"] = "GLOVO";
1543
+ EChannelName2["JUSTEAT"] = "JUSTEAT";
1544
+ EChannelName2["UBER"] = "UBER";
1545
+ EChannelName2["BOLT"] = "BOLT";
1546
+ EChannelName2["WOLT"] = "WOLT";
1499
1547
  })(EChannelName || (EChannelName = {}));
1548
+ var ENotificationType;
1549
+ (function(ENotificationType2) {
1550
+ ENotificationType2["ORDER_EVENT_ERROR"] = "OrderEventError";
1551
+ ENotificationType2["ORDER_APPLIED_EVENTS"] = "OrderAppliedEvents";
1552
+ ENotificationType2["ORDER_EVENT_FISCAL"] = "OrderEventFiscal";
1553
+ ENotificationType2["ORDER_UPSELL"] = "OrderUpsell";
1554
+ })(ENotificationType || (ENotificationType = {}));
1500
1555
  function arrayEach$1(array, iteratee) {
1501
1556
  var index = -1, length = array == null ? 0 : array.length;
1502
1557
  while (++index < length) {
@@ -3689,17 +3744,5 @@ function getMediaUrl(url, size = 500) {
3689
3744
  function useMediaUrl(url, size = 500) {
3690
3745
  return getMediaUrl(url, size);
3691
3746
  }
3692
- function addDiscounts(discounts) {
3693
- let value = 0;
3694
- discounts == null ? void 0 : discounts.forEach((discount) => value += Number(discount.discountPrice));
3695
- return value;
3696
- }
3697
- function summarizeLineDiscounts(line) {
3698
- return addDiscounts(line.discounts);
3699
- }
3700
- function formatPrice(value, currency, separator = ",", decimals = 2) {
3701
- const price = Number(value);
3702
- return `${price.toFixed(decimals).replace(".", separator)}${currency ? "\xA0" + currency : ""}`;
3703
- }
3704
- export { addDiscounts, formatPrice, getGroupedBucketLines, getMediaUrl, groupOrderLines, isChannelOpen, summarizeLineDiscounts, useAvailability, useCms, useDisplayPrice, useGroupOrderLines, useInterval, useKioskChannelsAvailability, useKioskMediaCms, useKioskMediaCmsWithContext, useLocalizedVenueMedia, useMediaUrl, useOnClickOutside, useVenueCms };
3747
+ export { addDiscounts, formatPrice, getGroupedBucketLines, getMediaUrl, groupOrderLines, isChannelOpen, isProductEnabled, summarizeLineDiscounts, useAvailability, useCms, useDisplayPrice, useGroupOrderLines, useInterval, useKioskChannelsAvailability, useKioskMediaCms, useKioskMediaCmsWithContext, useLocalizedVenueMedia, useMediaUrl, useMenu, useOnClickOutside, useVenueCms };
3705
3748
  //# sourceMappingURL=index.es.js.map