@open-tender/store 0.3.69 → 0.3.71

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,6 +1,6 @@
1
1
  import { CartItem } from '../types';
2
- declare const useBuilder: (cartItem: CartItem) => {
3
- item: CartItem;
2
+ declare const useBuilder: (cartItem: CartItem | null) => {
3
+ item: CartItem | null;
4
4
  increment: () => void;
5
5
  decrement: () => void;
6
6
  setQuantity: (quantity: number) => void;
@@ -6,25 +6,37 @@ var utils_1 = require("../utils");
6
6
  var useBuilder = function (cartItem) {
7
7
  var _a = (0, react_1.useState)(cartItem), item = _a[0], setItem = _a[1];
8
8
  var increment = function () {
9
+ if (!item)
10
+ return setItem(null);
9
11
  var newQuantity = item.max
10
12
  ? Math.min(item.quantity + item.increment, item.max)
11
13
  : item.quantity + item.increment;
12
14
  setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { quantity: newQuantity })));
13
15
  };
14
16
  var decrement = function () {
17
+ if (!item)
18
+ return setItem(null);
15
19
  var newQuantity = Math.max(item.quantity - item.increment, item.min);
16
20
  setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { quantity: newQuantity })));
17
21
  };
18
22
  var setQuantity = function (quantity) {
23
+ if (!item)
24
+ return setItem(null);
19
25
  setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { quantity: quantity })));
20
26
  };
21
27
  var setMadeFor = function (madeFor) {
28
+ if (!item)
29
+ return setItem(null);
22
30
  setItem(tslib_1.__assign(tslib_1.__assign({}, item), { madeFor: madeFor }));
23
31
  };
24
32
  var setNotes = function (notes) {
33
+ if (!item)
34
+ return setItem(null);
25
35
  setItem(tslib_1.__assign(tslib_1.__assign({}, item), { notes: notes }));
26
36
  };
27
37
  var toggleOption = function (groupId, optionId) {
38
+ if (!item)
39
+ return setItem(null);
28
40
  var groups = item.groups.map(function (group) {
29
41
  if (group.id === groupId) {
30
42
  var options = group.options.map(function (option) {
@@ -38,6 +50,8 @@ var useBuilder = function (cartItem) {
38
50
  setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
39
51
  };
40
52
  var incrementOption = function (groupId, optionId) {
53
+ if (!item)
54
+ return setItem(null);
41
55
  var groups = item.groups.map(function (group) {
42
56
  if (group.id === groupId) {
43
57
  var count_1 = group.options
@@ -65,6 +79,8 @@ var useBuilder = function (cartItem) {
65
79
  setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
66
80
  };
67
81
  var decrementOption = function (groupId, optionId) {
82
+ if (!item)
83
+ return setItem(null);
68
84
  var groups = item.groups.map(function (group) {
69
85
  if (group.id === groupId) {
70
86
  var options = group.options.map(function (option) {
@@ -81,6 +97,8 @@ var useBuilder = function (cartItem) {
81
97
  setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
82
98
  };
83
99
  var setOptionQuantity = function (groupId, optionId, quantity) {
100
+ if (!item)
101
+ return setItem(null);
84
102
  var groups = item.groups.map(function (group) {
85
103
  if (group.id === groupId) {
86
104
  var count_2 = group.options
@@ -39,6 +39,7 @@ export interface CartItemGroup {
39
39
  min: number;
40
40
  isSize: boolean;
41
41
  options: CartItemOptions;
42
+ quantity: number;
42
43
  }
43
44
  export declare type CartItemGroups = Array<CartItemGroup>;
44
45
  export interface CartItem {
@@ -117,7 +117,8 @@ var makeCartItemGroups = function (optionGroups, isEdit, soldOut) {
117
117
  max: g.max_options,
118
118
  min: g.min_options,
119
119
  isSize: !!g.is_size,
120
- options: options
120
+ options: options,
121
+ quantity: options.reduce(function (t, o) { return (t += o.quantity); }, 0)
121
122
  };
122
123
  return group;
123
124
  });
@@ -1,6 +1,6 @@
1
1
  import { CartItem } from '../types';
2
- declare const useBuilder: (cartItem: CartItem) => {
3
- item: CartItem;
2
+ declare const useBuilder: (cartItem: CartItem | null) => {
3
+ item: CartItem | null;
4
4
  increment: () => void;
5
5
  decrement: () => void;
6
6
  setQuantity: (quantity: number) => void;
@@ -4,25 +4,37 @@ import { calcPrices } from '../utils';
4
4
  var useBuilder = function (cartItem) {
5
5
  var _a = useState(cartItem), item = _a[0], setItem = _a[1];
6
6
  var increment = function () {
7
+ if (!item)
8
+ return setItem(null);
7
9
  var newQuantity = item.max
8
10
  ? Math.min(item.quantity + item.increment, item.max)
9
11
  : item.quantity + item.increment;
10
12
  setItem(calcPrices(__assign(__assign({}, item), { quantity: newQuantity })));
11
13
  };
12
14
  var decrement = function () {
15
+ if (!item)
16
+ return setItem(null);
13
17
  var newQuantity = Math.max(item.quantity - item.increment, item.min);
14
18
  setItem(calcPrices(__assign(__assign({}, item), { quantity: newQuantity })));
15
19
  };
16
20
  var setQuantity = function (quantity) {
21
+ if (!item)
22
+ return setItem(null);
17
23
  setItem(calcPrices(__assign(__assign({}, item), { quantity: quantity })));
18
24
  };
19
25
  var setMadeFor = function (madeFor) {
26
+ if (!item)
27
+ return setItem(null);
20
28
  setItem(__assign(__assign({}, item), { madeFor: madeFor }));
21
29
  };
22
30
  var setNotes = function (notes) {
31
+ if (!item)
32
+ return setItem(null);
23
33
  setItem(__assign(__assign({}, item), { notes: notes }));
24
34
  };
25
35
  var toggleOption = function (groupId, optionId) {
36
+ if (!item)
37
+ return setItem(null);
26
38
  var groups = item.groups.map(function (group) {
27
39
  if (group.id === groupId) {
28
40
  var options = group.options.map(function (option) {
@@ -36,6 +48,8 @@ var useBuilder = function (cartItem) {
36
48
  setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
37
49
  };
38
50
  var incrementOption = function (groupId, optionId) {
51
+ if (!item)
52
+ return setItem(null);
39
53
  var groups = item.groups.map(function (group) {
40
54
  if (group.id === groupId) {
41
55
  var count_1 = group.options
@@ -63,6 +77,8 @@ var useBuilder = function (cartItem) {
63
77
  setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
64
78
  };
65
79
  var decrementOption = function (groupId, optionId) {
80
+ if (!item)
81
+ return setItem(null);
66
82
  var groups = item.groups.map(function (group) {
67
83
  if (group.id === groupId) {
68
84
  var options = group.options.map(function (option) {
@@ -79,6 +95,8 @@ var useBuilder = function (cartItem) {
79
95
  setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
80
96
  };
81
97
  var setOptionQuantity = function (groupId, optionId, quantity) {
98
+ if (!item)
99
+ return setItem(null);
82
100
  var groups = item.groups.map(function (group) {
83
101
  if (group.id === groupId) {
84
102
  var count_2 = group.options
@@ -39,6 +39,7 @@ export interface CartItemGroup {
39
39
  min: number;
40
40
  isSize: boolean;
41
41
  options: CartItemOptions;
42
+ quantity: number;
42
43
  }
43
44
  export declare type CartItemGroups = Array<CartItemGroup>;
44
45
  export interface CartItem {
@@ -109,7 +109,8 @@ var makeCartItemGroups = function (optionGroups, isEdit, soldOut) {
109
109
  max: g.max_options,
110
110
  min: g.min_options,
111
111
  isSize: !!g.is_size,
112
- options: options
112
+ options: options,
113
+ quantity: options.reduce(function (t, o) { return (t += o.quantity); }, 0)
113
114
  };
114
115
  return group;
115
116
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/store",
3
- "version": "0.3.69",
3
+ "version": "0.3.71",
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",