@open-tender/store 1.1.151 → 1.1.152

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.
@@ -1,16 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var utils_1 = require("@open-tender/utils");
4
+ var react_1 = require("react");
4
5
  var hooks_1 = require("../app/hooks");
5
6
  var slices_1 = require("../slices");
6
7
  var CartUpsellItem = function (_a) {
7
8
  var item = _a.item, callback = _a.callback, isLast = _a.isLast, children = _a.children;
8
9
  var dispatch = (0, hooks_1.useAppDispatch)();
10
+ var _b = (0, react_1.useState)(false), hasSize = _b[0], setHasSize = _b[1];
9
11
  var apiUrl = (0, hooks_1.useAppSelector)(slices_1.selectKioskApi);
10
12
  var config = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig).cartUpsellItem;
11
13
  var display_cals = (0, hooks_1.useAppSelector)(slices_1.selectStoreSettings).display_cals;
12
- var builtItem = (0, utils_1.useBuilder)(item).item;
14
+ var _c = (0, utils_1.useBuilder)(item), builtItem = _c.item, toggleOption = _c.toggleOption;
13
15
  var quantity = builtItem.quantity, groups = builtItem.groups;
16
+ var sizeGroup = groups === null || groups === void 0 ? void 0 : groups.find(function (i) { return i.isSize; });
14
17
  var groupsBelowMin = (0, utils_1.hasGroupsBelowMin)(null, groups);
15
18
  var isIncomplete = "".concat(quantity) === '' || quantity === 0 || groupsBelowMin;
16
19
  var add = function () {
@@ -20,14 +23,31 @@ var CartUpsellItem = function (_a) {
20
23
  callback();
21
24
  }
22
25
  };
23
- var handlers = { add: add };
26
+ var addSize = function (optionId) {
27
+ if (sizeGroup) {
28
+ toggleOption([[sizeGroup.id, optionId]]);
29
+ setHasSize(true);
30
+ }
31
+ };
32
+ (0, react_1.useEffect)(function () {
33
+ if (hasSize && !isIncomplete) {
34
+ dispatch((0, slices_1.addItemToCart)(builtItem));
35
+ dispatch((0, slices_1.showNotification)("".concat(builtItem.name, " added to cart!")));
36
+ if (callback)
37
+ callback();
38
+ }
39
+ }, [hasSize, isIncomplete, builtItem, callback, dispatch]);
40
+ var handlers = { add: add, addSize: addSize };
41
+ if (isIncomplete && !sizeGroup)
42
+ return null;
24
43
  return children({
25
44
  config: config,
26
45
  handlers: handlers,
27
46
  item: item,
28
47
  isLast: isLast,
29
48
  apiUrl: apiUrl,
30
- displayCals: display_cals
49
+ displayCals: display_cals,
50
+ sizeGroup: sizeGroup
31
51
  });
32
52
  };
33
53
  exports.default = CartUpsellItem;
@@ -1,14 +1,17 @@
1
1
  import { hasGroupsBelowMin, useBuilder } from '@open-tender/utils';
2
+ import { useEffect, useState } from 'react';
2
3
  import { useAppDispatch, useAppSelector } from '../app/hooks';
3
- import { addItemToCart, selectKioskApi, selectKioskConfig, selectStoreSettings } from '../slices';
4
+ import { addItemToCart, selectKioskApi, selectKioskConfig, selectStoreSettings, showNotification } from '../slices';
4
5
  var CartUpsellItem = function (_a) {
5
6
  var item = _a.item, callback = _a.callback, isLast = _a.isLast, children = _a.children;
6
7
  var dispatch = useAppDispatch();
8
+ var _b = useState(false), hasSize = _b[0], setHasSize = _b[1];
7
9
  var apiUrl = useAppSelector(selectKioskApi);
8
10
  var config = useAppSelector(selectKioskConfig).cartUpsellItem;
9
11
  var display_cals = useAppSelector(selectStoreSettings).display_cals;
10
- var builtItem = useBuilder(item).item;
12
+ var _c = useBuilder(item), builtItem = _c.item, toggleOption = _c.toggleOption;
11
13
  var quantity = builtItem.quantity, groups = builtItem.groups;
14
+ var sizeGroup = groups === null || groups === void 0 ? void 0 : groups.find(function (i) { return i.isSize; });
12
15
  var groupsBelowMin = hasGroupsBelowMin(null, groups);
13
16
  var isIncomplete = "".concat(quantity) === '' || quantity === 0 || groupsBelowMin;
14
17
  var add = function () {
@@ -18,14 +21,31 @@ var CartUpsellItem = function (_a) {
18
21
  callback();
19
22
  }
20
23
  };
21
- var handlers = { add: add };
24
+ var addSize = function (optionId) {
25
+ if (sizeGroup) {
26
+ toggleOption([[sizeGroup.id, optionId]]);
27
+ setHasSize(true);
28
+ }
29
+ };
30
+ useEffect(function () {
31
+ if (hasSize && !isIncomplete) {
32
+ dispatch(addItemToCart(builtItem));
33
+ dispatch(showNotification("".concat(builtItem.name, " added to cart!")));
34
+ if (callback)
35
+ callback();
36
+ }
37
+ }, [hasSize, isIncomplete, builtItem, callback, dispatch]);
38
+ var handlers = { add: add, addSize: addSize };
39
+ if (isIncomplete && !sizeGroup)
40
+ return null;
22
41
  return children({
23
42
  config: config,
24
43
  handlers: handlers,
25
44
  item: item,
26
45
  isLast: isLast,
27
46
  apiUrl: apiUrl,
28
- displayCals: display_cals
47
+ displayCals: display_cals,
48
+ sizeGroup: sizeGroup
29
49
  });
30
50
  };
31
51
  export default CartUpsellItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/store",
3
- "version": "1.1.151",
3
+ "version": "1.1.152",
4
4
  "description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -62,8 +62,8 @@
62
62
  "peerDependencies": {
63
63
  "@emotion/react": "^11.11.1",
64
64
  "@open-tender/types": "^0.4.67",
65
- "@open-tender/ui": "^0.3.102",
66
- "@open-tender/utils": "^0.4.39",
65
+ "@open-tender/ui": "^0.3.103",
66
+ "@open-tender/utils": "^0.4.40",
67
67
  "@reduxjs/toolkit": "^2.0.1",
68
68
  "date-fns": "2.30.0",
69
69
  "date-fns-tz": "^2.0.0",