@open-tender/store 0.3.68 → 0.3.70
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/cjs/hooks/index.d.ts +2 -0
- package/dist/cjs/hooks/index.js +6 -0
- package/dist/cjs/hooks/useBuilder.d.ts +14 -0
- package/dist/cjs/hooks/useBuilder.js +146 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/types/api/cart.d.ts +1 -0
- package/dist/esm/hooks/index.d.ts +2 -0
- package/dist/esm/hooks/index.js +2 -0
- package/dist/esm/hooks/useBuilder.d.ts +14 -0
- package/dist/esm/hooks/useBuilder.js +144 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/types/api/cart.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CartItem } from '../types';
|
|
2
|
+
declare const useBuilder: (cartItem: CartItem | null) => {
|
|
3
|
+
item: CartItem | null;
|
|
4
|
+
increment: () => void;
|
|
5
|
+
decrement: () => void;
|
|
6
|
+
setQuantity: (quantity: number) => void;
|
|
7
|
+
setMadeFor: (madeFor: string) => void;
|
|
8
|
+
setNotes: (notes: string) => void;
|
|
9
|
+
toggleOption: (groupId: number, optionId: number) => void;
|
|
10
|
+
incrementOption: (groupId: number, optionId: number) => void;
|
|
11
|
+
decrementOption: (groupId: number, optionId: number) => void;
|
|
12
|
+
setOptionQuantity: (groupId: number, optionId: number, quantity: number) => void;
|
|
13
|
+
};
|
|
14
|
+
export default useBuilder;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
var useBuilder = function (cartItem) {
|
|
7
|
+
var _a = (0, react_1.useState)(cartItem), item = _a[0], setItem = _a[1];
|
|
8
|
+
var increment = function () {
|
|
9
|
+
if (!item)
|
|
10
|
+
return setItem(null);
|
|
11
|
+
var newQuantity = item.max
|
|
12
|
+
? Math.min(item.quantity + item.increment, item.max)
|
|
13
|
+
: item.quantity + item.increment;
|
|
14
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { quantity: newQuantity })));
|
|
15
|
+
};
|
|
16
|
+
var decrement = function () {
|
|
17
|
+
if (!item)
|
|
18
|
+
return setItem(null);
|
|
19
|
+
var newQuantity = Math.max(item.quantity - item.increment, item.min);
|
|
20
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { quantity: newQuantity })));
|
|
21
|
+
};
|
|
22
|
+
var setQuantity = function (quantity) {
|
|
23
|
+
if (!item)
|
|
24
|
+
return setItem(null);
|
|
25
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { quantity: quantity })));
|
|
26
|
+
};
|
|
27
|
+
var setMadeFor = function (madeFor) {
|
|
28
|
+
if (!item)
|
|
29
|
+
return setItem(null);
|
|
30
|
+
setItem(tslib_1.__assign(tslib_1.__assign({}, item), { madeFor: madeFor }));
|
|
31
|
+
};
|
|
32
|
+
var setNotes = function (notes) {
|
|
33
|
+
if (!item)
|
|
34
|
+
return setItem(null);
|
|
35
|
+
setItem(tslib_1.__assign(tslib_1.__assign({}, item), { notes: notes }));
|
|
36
|
+
};
|
|
37
|
+
var toggleOption = function (groupId, optionId) {
|
|
38
|
+
if (!item)
|
|
39
|
+
return setItem(null);
|
|
40
|
+
var groups = item.groups.map(function (group) {
|
|
41
|
+
if (group.id === groupId) {
|
|
42
|
+
var options = group.options.map(function (option) {
|
|
43
|
+
var newQuantity = option.id === optionId ? 1 : 0;
|
|
44
|
+
return tslib_1.__assign(tslib_1.__assign({}, option), { quantity: newQuantity });
|
|
45
|
+
});
|
|
46
|
+
return tslib_1.__assign(tslib_1.__assign({}, group), { options: options });
|
|
47
|
+
}
|
|
48
|
+
return group;
|
|
49
|
+
});
|
|
50
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
|
|
51
|
+
};
|
|
52
|
+
var incrementOption = function (groupId, optionId) {
|
|
53
|
+
if (!item)
|
|
54
|
+
return setItem(null);
|
|
55
|
+
var groups = item.groups.map(function (group) {
|
|
56
|
+
if (group.id === groupId) {
|
|
57
|
+
var count_1 = group.options
|
|
58
|
+
.filter(function (o) { return o.id !== optionId; })
|
|
59
|
+
.reduce(function (t, o) { return t + o.quantity; }, 0);
|
|
60
|
+
if (group.max !== 0 && count_1 >= group.max)
|
|
61
|
+
return group;
|
|
62
|
+
var options = group.options.map(function (option) {
|
|
63
|
+
if (option.id === optionId) {
|
|
64
|
+
var quantity = option.quantity + option.increment;
|
|
65
|
+
var quantities = [quantity];
|
|
66
|
+
if (option.max !== 0)
|
|
67
|
+
quantities.push(option.max);
|
|
68
|
+
if (group.max !== 0)
|
|
69
|
+
quantities.push(group.max - count_1);
|
|
70
|
+
quantity = Math.min.apply(Math, quantities);
|
|
71
|
+
return tslib_1.__assign(tslib_1.__assign({}, option), { quantity: quantity });
|
|
72
|
+
}
|
|
73
|
+
return option;
|
|
74
|
+
});
|
|
75
|
+
return tslib_1.__assign(tslib_1.__assign({}, group), { options: options });
|
|
76
|
+
}
|
|
77
|
+
return group;
|
|
78
|
+
});
|
|
79
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
|
|
80
|
+
};
|
|
81
|
+
var decrementOption = function (groupId, optionId) {
|
|
82
|
+
if (!item)
|
|
83
|
+
return setItem(null);
|
|
84
|
+
var groups = item.groups.map(function (group) {
|
|
85
|
+
if (group.id === groupId) {
|
|
86
|
+
var options = group.options.map(function (option) {
|
|
87
|
+
if (option.id === optionId) {
|
|
88
|
+
var quantity = Math.max(option.quantity - option.increment, 0);
|
|
89
|
+
return tslib_1.__assign(tslib_1.__assign({}, option), { quantity: quantity });
|
|
90
|
+
}
|
|
91
|
+
return option;
|
|
92
|
+
});
|
|
93
|
+
return tslib_1.__assign(tslib_1.__assign({}, group), { options: options });
|
|
94
|
+
}
|
|
95
|
+
return group;
|
|
96
|
+
});
|
|
97
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
|
|
98
|
+
};
|
|
99
|
+
var setOptionQuantity = function (groupId, optionId, quantity) {
|
|
100
|
+
if (!item)
|
|
101
|
+
return setItem(null);
|
|
102
|
+
var groups = item.groups.map(function (group) {
|
|
103
|
+
if (group.id === groupId) {
|
|
104
|
+
var count_2 = group.options
|
|
105
|
+
.filter(function (o) { return o.id !== optionId; })
|
|
106
|
+
.reduce(function (t, o) { return t + o.quantity; }, 0);
|
|
107
|
+
if (group.max !== 0 && count_2 >= group.max)
|
|
108
|
+
return group;
|
|
109
|
+
var options = group.options.map(function (option) {
|
|
110
|
+
if (option.id === optionId) {
|
|
111
|
+
if (!quantity) {
|
|
112
|
+
return tslib_1.__assign(tslib_1.__assign({}, option), { quantity: quantity });
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
var quantities = [quantity];
|
|
116
|
+
if (option.max !== 0)
|
|
117
|
+
quantities.push(option.max);
|
|
118
|
+
if (group.max !== 0)
|
|
119
|
+
quantities.push(group.max - count_2);
|
|
120
|
+
quantity = Math.min.apply(Math, quantities);
|
|
121
|
+
quantity = Math.max(quantity, option.min);
|
|
122
|
+
return tslib_1.__assign(tslib_1.__assign({}, option), { quantity: quantity });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return option;
|
|
126
|
+
});
|
|
127
|
+
return tslib_1.__assign(tslib_1.__assign({}, group), { options: options });
|
|
128
|
+
}
|
|
129
|
+
return group;
|
|
130
|
+
});
|
|
131
|
+
setItem((0, utils_1.calcPrices)(tslib_1.__assign(tslib_1.__assign({}, item), { groups: groups })));
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
item: item,
|
|
135
|
+
increment: increment,
|
|
136
|
+
decrement: decrement,
|
|
137
|
+
setQuantity: setQuantity,
|
|
138
|
+
setMadeFor: setMadeFor,
|
|
139
|
+
setNotes: setNotes,
|
|
140
|
+
toggleOption: toggleOption,
|
|
141
|
+
incrementOption: incrementOption,
|
|
142
|
+
decrementOption: decrementOption,
|
|
143
|
+
setOptionQuantity: setOptionQuantity
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
exports.default = useBuilder;
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.appReducer = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var store_1 = require("./app/store");
|
|
6
6
|
Object.defineProperty(exports, "appReducer", { enumerable: true, get: function () { return store_1.appReducer; } });
|
|
7
|
+
tslib_1.__exportStar(require("./hooks"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./slices"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./types"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CartItem } from '../types';
|
|
2
|
+
declare const useBuilder: (cartItem: CartItem | null) => {
|
|
3
|
+
item: CartItem | null;
|
|
4
|
+
increment: () => void;
|
|
5
|
+
decrement: () => void;
|
|
6
|
+
setQuantity: (quantity: number) => void;
|
|
7
|
+
setMadeFor: (madeFor: string) => void;
|
|
8
|
+
setNotes: (notes: string) => void;
|
|
9
|
+
toggleOption: (groupId: number, optionId: number) => void;
|
|
10
|
+
incrementOption: (groupId: number, optionId: number) => void;
|
|
11
|
+
decrementOption: (groupId: number, optionId: number) => void;
|
|
12
|
+
setOptionQuantity: (groupId: number, optionId: number, quantity: number) => void;
|
|
13
|
+
};
|
|
14
|
+
export default useBuilder;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { calcPrices } from '../utils';
|
|
4
|
+
var useBuilder = function (cartItem) {
|
|
5
|
+
var _a = useState(cartItem), item = _a[0], setItem = _a[1];
|
|
6
|
+
var increment = function () {
|
|
7
|
+
if (!item)
|
|
8
|
+
return setItem(null);
|
|
9
|
+
var newQuantity = item.max
|
|
10
|
+
? Math.min(item.quantity + item.increment, item.max)
|
|
11
|
+
: item.quantity + item.increment;
|
|
12
|
+
setItem(calcPrices(__assign(__assign({}, item), { quantity: newQuantity })));
|
|
13
|
+
};
|
|
14
|
+
var decrement = function () {
|
|
15
|
+
if (!item)
|
|
16
|
+
return setItem(null);
|
|
17
|
+
var newQuantity = Math.max(item.quantity - item.increment, item.min);
|
|
18
|
+
setItem(calcPrices(__assign(__assign({}, item), { quantity: newQuantity })));
|
|
19
|
+
};
|
|
20
|
+
var setQuantity = function (quantity) {
|
|
21
|
+
if (!item)
|
|
22
|
+
return setItem(null);
|
|
23
|
+
setItem(calcPrices(__assign(__assign({}, item), { quantity: quantity })));
|
|
24
|
+
};
|
|
25
|
+
var setMadeFor = function (madeFor) {
|
|
26
|
+
if (!item)
|
|
27
|
+
return setItem(null);
|
|
28
|
+
setItem(__assign(__assign({}, item), { madeFor: madeFor }));
|
|
29
|
+
};
|
|
30
|
+
var setNotes = function (notes) {
|
|
31
|
+
if (!item)
|
|
32
|
+
return setItem(null);
|
|
33
|
+
setItem(__assign(__assign({}, item), { notes: notes }));
|
|
34
|
+
};
|
|
35
|
+
var toggleOption = function (groupId, optionId) {
|
|
36
|
+
if (!item)
|
|
37
|
+
return setItem(null);
|
|
38
|
+
var groups = item.groups.map(function (group) {
|
|
39
|
+
if (group.id === groupId) {
|
|
40
|
+
var options = group.options.map(function (option) {
|
|
41
|
+
var newQuantity = option.id === optionId ? 1 : 0;
|
|
42
|
+
return __assign(__assign({}, option), { quantity: newQuantity });
|
|
43
|
+
});
|
|
44
|
+
return __assign(__assign({}, group), { options: options });
|
|
45
|
+
}
|
|
46
|
+
return group;
|
|
47
|
+
});
|
|
48
|
+
setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
|
|
49
|
+
};
|
|
50
|
+
var incrementOption = function (groupId, optionId) {
|
|
51
|
+
if (!item)
|
|
52
|
+
return setItem(null);
|
|
53
|
+
var groups = item.groups.map(function (group) {
|
|
54
|
+
if (group.id === groupId) {
|
|
55
|
+
var count_1 = group.options
|
|
56
|
+
.filter(function (o) { return o.id !== optionId; })
|
|
57
|
+
.reduce(function (t, o) { return t + o.quantity; }, 0);
|
|
58
|
+
if (group.max !== 0 && count_1 >= group.max)
|
|
59
|
+
return group;
|
|
60
|
+
var options = group.options.map(function (option) {
|
|
61
|
+
if (option.id === optionId) {
|
|
62
|
+
var quantity = option.quantity + option.increment;
|
|
63
|
+
var quantities = [quantity];
|
|
64
|
+
if (option.max !== 0)
|
|
65
|
+
quantities.push(option.max);
|
|
66
|
+
if (group.max !== 0)
|
|
67
|
+
quantities.push(group.max - count_1);
|
|
68
|
+
quantity = Math.min.apply(Math, quantities);
|
|
69
|
+
return __assign(__assign({}, option), { quantity: quantity });
|
|
70
|
+
}
|
|
71
|
+
return option;
|
|
72
|
+
});
|
|
73
|
+
return __assign(__assign({}, group), { options: options });
|
|
74
|
+
}
|
|
75
|
+
return group;
|
|
76
|
+
});
|
|
77
|
+
setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
|
|
78
|
+
};
|
|
79
|
+
var decrementOption = function (groupId, optionId) {
|
|
80
|
+
if (!item)
|
|
81
|
+
return setItem(null);
|
|
82
|
+
var groups = item.groups.map(function (group) {
|
|
83
|
+
if (group.id === groupId) {
|
|
84
|
+
var options = group.options.map(function (option) {
|
|
85
|
+
if (option.id === optionId) {
|
|
86
|
+
var quantity = Math.max(option.quantity - option.increment, 0);
|
|
87
|
+
return __assign(__assign({}, option), { quantity: quantity });
|
|
88
|
+
}
|
|
89
|
+
return option;
|
|
90
|
+
});
|
|
91
|
+
return __assign(__assign({}, group), { options: options });
|
|
92
|
+
}
|
|
93
|
+
return group;
|
|
94
|
+
});
|
|
95
|
+
setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
|
|
96
|
+
};
|
|
97
|
+
var setOptionQuantity = function (groupId, optionId, quantity) {
|
|
98
|
+
if (!item)
|
|
99
|
+
return setItem(null);
|
|
100
|
+
var groups = item.groups.map(function (group) {
|
|
101
|
+
if (group.id === groupId) {
|
|
102
|
+
var count_2 = group.options
|
|
103
|
+
.filter(function (o) { return o.id !== optionId; })
|
|
104
|
+
.reduce(function (t, o) { return t + o.quantity; }, 0);
|
|
105
|
+
if (group.max !== 0 && count_2 >= group.max)
|
|
106
|
+
return group;
|
|
107
|
+
var options = group.options.map(function (option) {
|
|
108
|
+
if (option.id === optionId) {
|
|
109
|
+
if (!quantity) {
|
|
110
|
+
return __assign(__assign({}, option), { quantity: quantity });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
var quantities = [quantity];
|
|
114
|
+
if (option.max !== 0)
|
|
115
|
+
quantities.push(option.max);
|
|
116
|
+
if (group.max !== 0)
|
|
117
|
+
quantities.push(group.max - count_2);
|
|
118
|
+
quantity = Math.min.apply(Math, quantities);
|
|
119
|
+
quantity = Math.max(quantity, option.min);
|
|
120
|
+
return __assign(__assign({}, option), { quantity: quantity });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return option;
|
|
124
|
+
});
|
|
125
|
+
return __assign(__assign({}, group), { options: options });
|
|
126
|
+
}
|
|
127
|
+
return group;
|
|
128
|
+
});
|
|
129
|
+
setItem(calcPrices(__assign(__assign({}, item), { groups: groups })));
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
item: item,
|
|
133
|
+
increment: increment,
|
|
134
|
+
decrement: decrement,
|
|
135
|
+
setQuantity: setQuantity,
|
|
136
|
+
setMadeFor: setMadeFor,
|
|
137
|
+
setNotes: setNotes,
|
|
138
|
+
toggleOption: toggleOption,
|
|
139
|
+
incrementOption: incrementOption,
|
|
140
|
+
decrementOption: decrementOption,
|
|
141
|
+
setOptionQuantity: setOptionQuantity
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
export default useBuilder;
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/store",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.70",
|
|
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",
|