@open-tender/utils 0.0.68 → 0.1.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/cjs/hooks/menu/useBuilder.d.ts +8 -7
- package/dist/cjs/hooks/menu/useBuilder.js +92 -86
- package/dist/cjs/hooks/menu/useOrderItem.d.ts +33 -43
- package/dist/cjs/hooks/menu/useOrderItem.js +21 -22
- package/dist/cjs/hooks/useAddressForm.js +1 -1
- package/dist/cjs/hooks/useAllergenForm.js +1 -1
- package/dist/cjs/hooks/useCartGuestForm.js +2 -2
- package/dist/cjs/hooks/useCheckoutLoginForm.js +1 -1
- package/dist/cjs/hooks/useCreditCard.d.ts +1 -2
- package/dist/cjs/hooks/useCreditCard.js +4 -3
- package/dist/cjs/hooks/useCreditCardForm.js +3 -3
- package/dist/cjs/hooks/useCurbside.js +1 -1
- package/dist/cjs/hooks/useDineInForm.js +1 -1
- package/dist/cjs/hooks/useDonationForm.js +5 -5
- package/dist/cjs/hooks/useGiftCardAssignForm.js +1 -1
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +1 -1
- package/dist/cjs/hooks/useGiftCardForm.js +6 -4
- package/dist/cjs/hooks/useGiftCardsForm.js +22 -9
- package/dist/cjs/hooks/useGuestForm.js +1 -1
- package/dist/cjs/hooks/useImage.d.ts +1 -2
- package/dist/cjs/hooks/useImage.js +2 -1
- package/dist/cjs/hooks/useLevelUpForm.d.ts +1 -2
- package/dist/cjs/hooks/useLevelUpForm.js +3 -2
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +3 -3
- package/dist/cjs/hooks/useOrderRating.js +1 -1
- package/dist/cjs/hooks/useOrderRatingForm.js +1 -1
- package/dist/cjs/hooks/useProfileForm.js +3 -3
- package/dist/cjs/hooks/useResetPasswordForm.js +2 -2
- package/dist/cjs/hooks/useSendResetForm.js +4 -2
- package/dist/cjs/hooks/useSignUpForm.js +14 -10
- package/dist/cjs/hooks/useSignUpGuestForm.js +3 -3
- package/dist/cjs/hooks/useSigninForm.js +1 -1
- package/dist/cjs/utils/cart.d.ts +97 -453
- package/dist/cjs/utils/cart.js +288 -361
- package/dist/cjs/utils/customer.js +1 -1
- package/dist/cjs/utils/errors.js +4 -2
- package/dist/cjs/utils/favorites.d.ts +3 -3
- package/dist/cjs/utils/favorites.js +11 -4
- package/dist/cjs/utils/helpers.d.ts +8 -3
- package/dist/cjs/utils/helpers.js +31 -3
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/maps.js +1 -1
- package/dist/cjs/utils/orders.d.ts +3 -3
- package/dist/cjs/utils/refunds.d.ts +4 -4
- package/dist/cjs/utils/revenueCenters.d.ts +11 -0
- package/dist/cjs/utils/revenueCenters.js +125 -0
- package/dist/cjs/utils/rewards.js +5 -5
- package/dist/cjs/utils/theme.js +7 -7
- package/dist/esm/hooks/menu/useBuilder.d.ts +8 -7
- package/dist/esm/hooks/menu/useBuilder.js +92 -86
- package/dist/esm/hooks/menu/useOrderItem.d.ts +33 -43
- package/dist/esm/hooks/menu/useOrderItem.js +22 -23
- package/dist/esm/hooks/useAddressForm.js +1 -1
- package/dist/esm/hooks/useAllergenForm.js +1 -1
- package/dist/esm/hooks/useCartGuestForm.js +2 -2
- package/dist/esm/hooks/useCheckoutLoginForm.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +1 -2
- package/dist/esm/hooks/useCreditCard.js +4 -5
- package/dist/esm/hooks/useCreditCardForm.js +3 -3
- package/dist/esm/hooks/useCurbside.js +1 -1
- package/dist/esm/hooks/useDineInForm.js +1 -1
- package/dist/esm/hooks/useDonationForm.js +5 -5
- package/dist/esm/hooks/useGiftCardAssignForm.js +1 -1
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +1 -1
- package/dist/esm/hooks/useGiftCardForm.js +6 -4
- package/dist/esm/hooks/useGiftCardsForm.js +22 -9
- package/dist/esm/hooks/useGuestForm.js +1 -1
- package/dist/esm/hooks/useImage.d.ts +1 -2
- package/dist/esm/hooks/useImage.js +1 -2
- package/dist/esm/hooks/useLevelUpForm.d.ts +1 -2
- package/dist/esm/hooks/useLevelUpForm.js +2 -3
- package/dist/esm/hooks/useOrderFulfillmentForm.js +3 -3
- package/dist/esm/hooks/useOrderRating.js +1 -1
- package/dist/esm/hooks/useOrderRatingForm.js +1 -1
- package/dist/esm/hooks/useProfileForm.js +3 -3
- package/dist/esm/hooks/useResetPasswordForm.js +2 -2
- package/dist/esm/hooks/useSendResetForm.js +4 -2
- package/dist/esm/hooks/useSignUpForm.js +14 -10
- package/dist/esm/hooks/useSignUpGuestForm.js +3 -3
- package/dist/esm/hooks/useSigninForm.js +1 -1
- package/dist/esm/utils/cart.d.ts +97 -453
- package/dist/esm/utils/cart.js +276 -339
- package/dist/esm/utils/customer.js +1 -1
- package/dist/esm/utils/errors.js +4 -2
- package/dist/esm/utils/favorites.d.ts +3 -3
- package/dist/esm/utils/favorites.js +11 -4
- package/dist/esm/utils/helpers.d.ts +8 -3
- package/dist/esm/utils/helpers.js +25 -2
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/maps.js +1 -1
- package/dist/esm/utils/orders.d.ts +3 -3
- package/dist/esm/utils/refunds.d.ts +4 -4
- package/dist/esm/utils/revenueCenters.d.ts +11 -0
- package/dist/esm/utils/revenueCenters.js +115 -0
- package/dist/esm/utils/rewards.js +1 -1
- package/dist/esm/utils/theme.js +7 -7
- package/package.json +2 -4
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CartItem,
|
|
2
|
-
export declare const useBuilder: (orderItem:
|
|
3
|
-
item:
|
|
1
|
+
import { CartItem, CartLevels } from '@open-tender/types';
|
|
2
|
+
export declare const useBuilder: (orderItem: CartItem) => {
|
|
3
|
+
item: CartItem;
|
|
4
4
|
increment: () => void;
|
|
5
5
|
decrement: () => void;
|
|
6
6
|
setQuantity: (quantity: number) => void;
|
|
7
7
|
setMadeFor: (madeFor: string) => void;
|
|
8
8
|
setNotes: (notes: string) => void;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
setMadeForNotes: (madeFor: string, notes: string) => void;
|
|
10
|
+
toggleOption: (levels: CartLevels) => void;
|
|
11
|
+
incrementOption: (levels: CartLevels) => void;
|
|
12
|
+
decrementOption: (levels: CartLevels) => void;
|
|
13
|
+
setOptionQuantity: (levels: CartLevels, quantity: number) => void;
|
|
13
14
|
};
|
|
@@ -6,19 +6,20 @@ const utils_1 = require("../../utils");
|
|
|
6
6
|
const useBuilder = (orderItem) => {
|
|
7
7
|
const [item, setItem] = (0, react_1.useState)(orderItem);
|
|
8
8
|
const increment = () => {
|
|
9
|
-
var _a, _b, _c, _d;
|
|
10
9
|
const newQuantity = item.max
|
|
11
|
-
? Math.min(
|
|
12
|
-
:
|
|
13
|
-
|
|
10
|
+
? Math.min(item.quantity + item.increment, item.max)
|
|
11
|
+
: item.quantity + item.increment;
|
|
12
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
|
|
13
|
+
setItem(pricedItem);
|
|
14
14
|
};
|
|
15
15
|
const decrement = () => {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
setItem(
|
|
16
|
+
const newQuantity = Math.max(item.quantity - item.increment, item.min);
|
|
17
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
|
|
18
|
+
setItem(pricedItem);
|
|
19
19
|
};
|
|
20
20
|
const setQuantity = (quantity) => {
|
|
21
|
-
|
|
21
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity }));
|
|
22
|
+
setItem(pricedItem);
|
|
22
23
|
};
|
|
23
24
|
const setMadeFor = (madeFor) => {
|
|
24
25
|
setItem(Object.assign(Object.assign({}, item), { madeFor }));
|
|
@@ -26,93 +27,78 @@ const useBuilder = (orderItem) => {
|
|
|
26
27
|
const setNotes = (notes) => {
|
|
27
28
|
setItem(Object.assign(Object.assign({}, item), { notes }));
|
|
28
29
|
};
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const newQuantity = option.id === optionId ? 1 : 0;
|
|
36
|
-
return Object.assign(Object.assign({}, option), { quantity: newQuantity });
|
|
37
|
-
});
|
|
38
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
39
|
-
}
|
|
40
|
-
return group;
|
|
30
|
+
const setMadeForNotes = (madeFor, notes) => {
|
|
31
|
+
setItem(Object.assign(Object.assign({}, item), { madeFor, notes }));
|
|
32
|
+
};
|
|
33
|
+
const toggleGroupOption = (group, optionId) => {
|
|
34
|
+
const options = group.options.map(option => {
|
|
35
|
+
return Object.assign(Object.assign({}, option), { quantity: option.id === optionId ? 1 : 0 });
|
|
41
36
|
});
|
|
42
|
-
|
|
37
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
43
38
|
};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const count = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
50
|
-
if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
|
|
51
|
-
return group;
|
|
52
|
-
const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
|
|
53
|
-
var _a, _b, _c, _d;
|
|
54
|
-
if (option.id === optionId) {
|
|
55
|
-
let quantity = ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = option.increment) !== null && _b !== void 0 ? _b : 0);
|
|
56
|
-
const quantities = [quantity];
|
|
57
|
-
if (option.max !== 0)
|
|
58
|
-
quantities.push(((_c = option.max) !== null && _c !== void 0 ? _c : 0));
|
|
59
|
-
if (group.max !== 0)
|
|
60
|
-
quantities.push(((_d = group.max) !== null && _d !== void 0 ? _d : 0) - (count !== null && count !== void 0 ? count : 0));
|
|
61
|
-
quantity = Math.min(...quantities);
|
|
62
|
-
return Object.assign(Object.assign({}, option), { quantity });
|
|
63
|
-
}
|
|
64
|
-
return option;
|
|
65
|
-
});
|
|
66
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
67
|
-
}
|
|
39
|
+
const incrementGroupOption = (group, optionId) => {
|
|
40
|
+
const count = group.options
|
|
41
|
+
.filter(o => o.id !== optionId)
|
|
42
|
+
.reduce((t, o) => t + o.quantity, 0);
|
|
43
|
+
if (group.max !== 0 && count >= group.max)
|
|
68
44
|
return group;
|
|
45
|
+
const options = group.options.map(option => {
|
|
46
|
+
if (option.id === optionId) {
|
|
47
|
+
let quantity = option.quantity + option.increment;
|
|
48
|
+
const quantities = [quantity];
|
|
49
|
+
if (option.max !== 0)
|
|
50
|
+
quantities.push(option.max);
|
|
51
|
+
if (group.max !== 0)
|
|
52
|
+
quantities.push(group.max - count);
|
|
53
|
+
quantity = Math.min(...quantities);
|
|
54
|
+
return Object.assign(Object.assign({}, option), { quantity });
|
|
55
|
+
}
|
|
56
|
+
return option;
|
|
69
57
|
});
|
|
70
|
-
|
|
58
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
71
59
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const options = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
|
|
78
|
-
var _a, _b;
|
|
79
|
-
if (option.id === optionId) {
|
|
80
|
-
const quantity = Math.max(((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = option.increment) !== null && _b !== void 0 ? _b : 0), 0);
|
|
81
|
-
return Object.assign(Object.assign({}, option), { quantity });
|
|
82
|
-
}
|
|
83
|
-
return option;
|
|
84
|
-
});
|
|
85
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
60
|
+
const decrementGroupOption = (group, optionId) => {
|
|
61
|
+
const options = group.options.map(option => {
|
|
62
|
+
if (option.id === optionId) {
|
|
63
|
+
const quantity = Math.max(option.quantity - option.increment, 0);
|
|
64
|
+
return Object.assign(Object.assign({}, option), { quantity });
|
|
86
65
|
}
|
|
66
|
+
return option;
|
|
67
|
+
});
|
|
68
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
69
|
+
};
|
|
70
|
+
const setGroupOptionQuantity = (group, optionId, quantity) => {
|
|
71
|
+
if (quantity === undefined)
|
|
72
|
+
return group;
|
|
73
|
+
const count = group.options
|
|
74
|
+
.filter(o => o.id !== optionId)
|
|
75
|
+
.reduce((t, o) => t + o.quantity, 0);
|
|
76
|
+
if (group.max !== 0 && count >= group.max)
|
|
87
77
|
return group;
|
|
78
|
+
const options = group.options.map(option => {
|
|
79
|
+
if (option.id === optionId) {
|
|
80
|
+
const quantities = quantity ? [quantity] : [0];
|
|
81
|
+
if (option.max !== 0)
|
|
82
|
+
quantities.push(option.max);
|
|
83
|
+
if (group.max !== 0)
|
|
84
|
+
quantities.push(group.max - count);
|
|
85
|
+
quantity = Math.min(...quantities);
|
|
86
|
+
quantity = Math.max(quantity, option.min);
|
|
87
|
+
return Object.assign(Object.assign({}, option), { quantity });
|
|
88
|
+
}
|
|
89
|
+
return option;
|
|
88
90
|
});
|
|
89
|
-
|
|
91
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
90
92
|
};
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var _a, _b, _c;
|
|
93
|
+
const updateGroups = (groups, levels, fn, quantity) => {
|
|
94
|
+
const [[groupId, optionId], ...rest] = levels;
|
|
95
|
+
return groups.map(group => {
|
|
95
96
|
if (group.id === groupId) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
|
|
100
|
-
var _a, _b, _c;
|
|
101
|
-
const optionGroups = nested || option.groups || [];
|
|
97
|
+
if (!rest.length)
|
|
98
|
+
return fn(group, optionId, quantity);
|
|
99
|
+
const options = group.options.map(option => {
|
|
102
100
|
if (option.id === optionId) {
|
|
103
|
-
|
|
104
|
-
return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
const quantities = [quantity];
|
|
108
|
-
if (option.max !== 0)
|
|
109
|
-
quantities.push(((_a = option.max) !== null && _a !== void 0 ? _a : 0));
|
|
110
|
-
if (group.max !== 0)
|
|
111
|
-
quantities.push(((_b = group.max) !== null && _b !== void 0 ? _b : 0) - (count !== null && count !== void 0 ? count : 0));
|
|
112
|
-
quantity = Math.min(...quantities);
|
|
113
|
-
quantity = Math.max(quantity, ((_c = option.min) !== null && _c !== void 0 ? _c : 0));
|
|
114
|
-
return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
|
|
115
|
-
}
|
|
101
|
+
return Object.assign(Object.assign({}, option), { groups: updateGroups(option.groups, rest, fn) });
|
|
116
102
|
}
|
|
117
103
|
return option;
|
|
118
104
|
});
|
|
@@ -120,7 +106,26 @@ const useBuilder = (orderItem) => {
|
|
|
120
106
|
}
|
|
121
107
|
return group;
|
|
122
108
|
});
|
|
123
|
-
|
|
109
|
+
};
|
|
110
|
+
const toggleOption = (levels) => {
|
|
111
|
+
const groups = updateGroups(item.groups, levels, toggleGroupOption);
|
|
112
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
113
|
+
setItem(pricedItem);
|
|
114
|
+
};
|
|
115
|
+
const incrementOption = (levels) => {
|
|
116
|
+
const groups = updateGroups(item.groups, levels, incrementGroupOption);
|
|
117
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
118
|
+
setItem(pricedItem);
|
|
119
|
+
};
|
|
120
|
+
const decrementOption = (levels) => {
|
|
121
|
+
const groups = updateGroups(item.groups, levels, decrementGroupOption);
|
|
122
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
123
|
+
setItem(pricedItem);
|
|
124
|
+
};
|
|
125
|
+
const setOptionQuantity = (levels, quantity) => {
|
|
126
|
+
const groups = updateGroups(item.groups, levels, setGroupOptionQuantity, quantity);
|
|
127
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
128
|
+
setItem(pricedItem);
|
|
124
129
|
};
|
|
125
130
|
return {
|
|
126
131
|
item,
|
|
@@ -129,10 +134,11 @@ const useBuilder = (orderItem) => {
|
|
|
129
134
|
setQuantity,
|
|
130
135
|
setMadeFor,
|
|
131
136
|
setNotes,
|
|
137
|
+
setMadeForNotes,
|
|
132
138
|
toggleOption,
|
|
133
139
|
incrementOption,
|
|
134
140
|
decrementOption,
|
|
135
|
-
setOptionQuantity
|
|
141
|
+
setOptionQuantity
|
|
136
142
|
};
|
|
137
143
|
};
|
|
138
144
|
exports.useBuilder = useBuilder;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CartCounts, Favorite, CartItem,
|
|
2
|
-
export declare const useOrderItem: (orderItem:
|
|
3
|
-
showImage: boolean
|
|
4
|
-
displayDesc:
|
|
1
|
+
import { CartCounts, Favorite, CartItem, ConfigDisplaySetting } from '@open-tender/types';
|
|
2
|
+
export declare const useOrderItem: (orderItem: CartItem, favorite: Favorite | null | undefined, allergenAlerts: string[] | undefined, displaySettings: ConfigDisplaySetting, cartCounts?: CartCounts, isMobile?: boolean) => {
|
|
3
|
+
showImage: boolean;
|
|
4
|
+
displayDesc: string | null;
|
|
5
5
|
displayTags: string[];
|
|
6
6
|
displayAllergens: string[];
|
|
7
7
|
displayPrice: string;
|
|
@@ -10,47 +10,37 @@ export declare const useOrderItem: (orderItem: Partial<CartItem>, favorite?: Par
|
|
|
10
10
|
isSoldOut: boolean;
|
|
11
11
|
allergenAlert: string | null;
|
|
12
12
|
hasSelections: boolean;
|
|
13
|
-
showQuickAdd: boolean
|
|
13
|
+
showQuickAdd: boolean;
|
|
14
14
|
sizeOnly: boolean | undefined;
|
|
15
15
|
cartCount: number;
|
|
16
|
+
cartGuestId: number | null;
|
|
17
|
+
customerId: number | null;
|
|
16
18
|
index?: number | undefined;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
shortName?: string | undefined;
|
|
20
|
-
cart_guest_id?: number | null | undefined;
|
|
21
|
-
category?: string | null | undefined;
|
|
22
|
-
customer_id?: number | null | undefined;
|
|
23
|
-
description?: string | null | undefined;
|
|
24
|
-
imageUrl?: string | null | undefined;
|
|
25
|
-
slug?: string | undefined;
|
|
26
|
-
allergens?: string[] | undefined;
|
|
27
|
-
tags?: string[] | undefined;
|
|
28
|
-
ingredients?: string | null | undefined;
|
|
29
|
-
madeFor?: string | null | undefined;
|
|
30
|
-
notes?: string | null | undefined;
|
|
31
|
-
nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
|
|
32
|
-
cals?: number | null | undefined;
|
|
33
|
-
groups?: import("@open-tender/types").CartItemGroups | undefined;
|
|
34
|
-
quantity?: number | undefined;
|
|
35
|
-
price?: number | undefined;
|
|
36
|
-
increment?: number | undefined;
|
|
37
|
-
max?: number | undefined;
|
|
38
|
-
min?: number | undefined;
|
|
39
|
-
points?: any;
|
|
40
|
-
upsellItems?: number[] | undefined;
|
|
41
|
-
similarItems?: number[] | undefined;
|
|
42
|
-
totalPrice?: number | undefined;
|
|
43
|
-
totalPoints?: number | null | undefined;
|
|
44
|
-
totalCals?: number | null | undefined;
|
|
45
|
-
item_no?: number | undefined;
|
|
46
|
-
nutritional_info?: import("@open-tender/types").NutritionalInfo | null | undefined;
|
|
47
|
-
price_total?: number | undefined;
|
|
48
|
-
favorite_id?: number | undefined;
|
|
49
|
-
images?: import("@open-tender/types").OrderItemImages | undefined;
|
|
50
|
-
short_description?: string | undefined;
|
|
51
|
-
shortDescription?: string | undefined;
|
|
52
|
-
made_for?: string | undefined;
|
|
19
|
+
madeFor: string | null;
|
|
20
|
+
notes: string | null;
|
|
53
21
|
signature?: string | undefined;
|
|
54
|
-
|
|
55
|
-
|
|
22
|
+
similarItems: number[];
|
|
23
|
+
upsellItems: number[];
|
|
24
|
+
allergens: string[];
|
|
25
|
+
cals: number | null;
|
|
26
|
+
description: string | null;
|
|
27
|
+
groups: import("@open-tender/types").CartItemGroups;
|
|
28
|
+
id: number;
|
|
29
|
+
imageUrl: string | null;
|
|
30
|
+
increment: number;
|
|
31
|
+
ingredients: string | null;
|
|
32
|
+
max: number;
|
|
33
|
+
min: number;
|
|
34
|
+
name: string;
|
|
35
|
+
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
36
|
+
points: number | null;
|
|
37
|
+
price: number;
|
|
38
|
+
quantity: number;
|
|
39
|
+
shortDescription: string | null;
|
|
40
|
+
shortName: string;
|
|
41
|
+
slug: string;
|
|
42
|
+
tags: string[];
|
|
43
|
+
totalCals: number | null;
|
|
44
|
+
totalPoints: number | null;
|
|
45
|
+
totalPrice: number | null;
|
|
56
46
|
};
|
|
@@ -2,35 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOrderItem = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
|
-
const useOrderItem = (orderItem, favorite = null,
|
|
6
|
-
|
|
7
|
-
const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile, } = displaySettings;
|
|
5
|
+
const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySettings, cartCounts = {}, isMobile = true) => {
|
|
6
|
+
const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile } = displaySettings;
|
|
8
7
|
const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
|
|
9
|
-
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, } = orderItem;
|
|
10
|
-
const cartCount =
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const sizeOnly = sizeGroup && (groups === null || groups === void 0 ? void 0 : groups.length) === 1;
|
|
8
|
+
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, isSoldOut } = orderItem;
|
|
9
|
+
const cartCount = cartCounts[orderItem.id] || 0;
|
|
10
|
+
const displayTags = showTags && tags.length ? tags : [];
|
|
11
|
+
const displayAllergens = showAllergens && allergens.length ? allergens : [];
|
|
12
|
+
const contains = allergens.filter(allergen => allergenAlerts.includes(allergen));
|
|
13
|
+
const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
|
|
14
|
+
const sizeGroup = groups.find(i => i.isSize);
|
|
15
|
+
const sizeOnly = sizeGroup && groups.length === 1;
|
|
18
16
|
const defaultOption = !sizeGroup
|
|
19
17
|
? null
|
|
20
|
-
:
|
|
18
|
+
: sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
|
|
21
19
|
const currentPrice = totalPrice
|
|
22
20
|
? totalPrice
|
|
23
21
|
: defaultOption
|
|
24
22
|
? defaultOption.price
|
|
25
23
|
: price;
|
|
26
|
-
const displayPrice = (0, utils_1.formatDollars)(
|
|
24
|
+
const displayPrice = (0, utils_1.formatDollars)(currentPrice.toString());
|
|
27
25
|
const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
|
|
28
26
|
const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
|
|
29
|
-
const groupsBelowMin = (
|
|
30
|
-
const isIncomplete = totalPrice === 0 ||
|
|
31
|
-
const nonSizeGroups = groups
|
|
27
|
+
const groupsBelowMin = (0, utils_1.hasGroupsBelowMin)(null, groups);
|
|
28
|
+
const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
|
|
29
|
+
const nonSizeGroups = groups.filter(i => !i.isSize);
|
|
32
30
|
const currentOptions = (0, utils_1.getItemOptions)({ groups: nonSizeGroups });
|
|
33
|
-
const hasSelections =
|
|
31
|
+
const hasSelections = currentOptions.length > 0;
|
|
34
32
|
const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
|
|
35
33
|
const desc = showDesc === 'HIDE'
|
|
36
34
|
? ''
|
|
@@ -38,11 +36,12 @@ const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts =
|
|
|
38
36
|
? shortDescription
|
|
39
37
|
: description;
|
|
40
38
|
const optionNames = favorite
|
|
41
|
-
?
|
|
42
|
-
|
|
43
|
-
const names =
|
|
39
|
+
? favorite.item.groups
|
|
40
|
+
.reduce((arr, group) => {
|
|
41
|
+
const names = group.options.map(o => o.name);
|
|
44
42
|
return [...arr, ...names];
|
|
45
|
-
}, [])
|
|
43
|
+
}, [])
|
|
44
|
+
.join(', ')
|
|
46
45
|
: null;
|
|
47
46
|
const displayDesc = optionNames || desc;
|
|
48
47
|
return Object.assign(Object.assign({}, orderItem), { showImage,
|
|
@@ -15,7 +15,7 @@ const useAddressForm = (address, loading, error, update, callback) => {
|
|
|
15
15
|
{ label: 'Contact Phone', name: 'phone', type: 'phone-pad' },
|
|
16
16
|
{ label: 'Description', name: 'description', type: 'default' },
|
|
17
17
|
{ label: 'Notes', name: 'notes', type: 'default' },
|
|
18
|
-
{ label: 'Is Default', name: 'is_default', type: 'checkbox' }
|
|
18
|
+
{ label: 'Is Default', name: 'is_default', type: 'checkbox' }
|
|
19
19
|
];
|
|
20
20
|
(0, react_1.useEffect)(() => {
|
|
21
21
|
var _a, _b;
|
|
@@ -9,7 +9,7 @@ const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
|
9
9
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
10
10
|
const fields = [
|
|
11
11
|
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
12
|
-
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
12
|
+
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
13
13
|
];
|
|
14
14
|
(0, react_1.useEffect)(() => {
|
|
15
15
|
return () => {
|
|
@@ -42,7 +42,7 @@ const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
|
42
42
|
data,
|
|
43
43
|
submitting,
|
|
44
44
|
handleChange,
|
|
45
|
-
handleSubmit
|
|
45
|
+
handleSubmit
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
exports.useCartGuestForm = useCartGuestForm;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CreditCardData } from '@open-tender/types';
|
|
3
|
-
declare const useCreditCard: (initState: any, cardErrors?: {}, disabled?: boolean) => {
|
|
3
|
+
export declare const useCreditCard: (initState: any, cardErrors?: {}, disabled?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<null>;
|
|
5
5
|
data: CreditCardData;
|
|
6
6
|
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
@@ -11,4 +11,3 @@ declare const useCreditCard: (initState: any, cardErrors?: {}, disabled?: boolea
|
|
|
11
11
|
handleBlur: (evt?: any) => void;
|
|
12
12
|
isComplete: boolean;
|
|
13
13
|
};
|
|
14
|
-
export default useCreditCard;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCreditCard = void 0;
|
|
3
4
|
const react_1 = require("react");
|
|
4
5
|
const __1 = require("../");
|
|
5
6
|
const defaultState = {
|
|
@@ -7,7 +8,7 @@ const defaultState = {
|
|
|
7
8
|
exp: '',
|
|
8
9
|
cvv: '',
|
|
9
10
|
zip: '',
|
|
10
|
-
is_default: false
|
|
11
|
+
is_default: false
|
|
11
12
|
};
|
|
12
13
|
const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
13
14
|
const [initCard, initCardType] = (0, __1.formatCard)(initState);
|
|
@@ -51,7 +52,7 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
|
51
52
|
setErrors,
|
|
52
53
|
handleChange,
|
|
53
54
|
handleBlur,
|
|
54
|
-
isComplete
|
|
55
|
+
isComplete
|
|
55
56
|
};
|
|
56
57
|
};
|
|
57
|
-
exports.
|
|
58
|
+
exports.useCreditCard = useCreditCard;
|
|
@@ -38,7 +38,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
38
38
|
if (!token) {
|
|
39
39
|
setSubmitting(false);
|
|
40
40
|
setErrors({
|
|
41
|
-
form: 'Please complete the recaptcha before submitting'
|
|
41
|
+
form: 'Please complete the recaptcha before submitting'
|
|
42
42
|
});
|
|
43
43
|
if (windowRef)
|
|
44
44
|
windowRef.scrollTo({ top: 0 });
|
|
@@ -51,7 +51,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
51
51
|
catch (err) {
|
|
52
52
|
setSubmitting(false);
|
|
53
53
|
setErrors({
|
|
54
|
-
form: 'Please complete the recaptcha before submitting'
|
|
54
|
+
form: 'Please complete the recaptcha before submitting'
|
|
55
55
|
});
|
|
56
56
|
if (windowRef)
|
|
57
57
|
windowRef.scrollTo({ top: 0 });
|
|
@@ -69,7 +69,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
69
69
|
recaptchaRef,
|
|
70
70
|
data,
|
|
71
71
|
submitting,
|
|
72
|
-
handleSubmit
|
|
72
|
+
handleSubmit
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
exports.useCreditCardForm = useCreditCardForm;
|
|
@@ -43,7 +43,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
43
43
|
if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
|
|
44
44
|
const options = creditCards.map(i => ({
|
|
45
45
|
label: `${i.card_type_name} ending in ${i.last4}`,
|
|
46
|
-
value: i.customer_card_id
|
|
46
|
+
value: i.customer_card_id
|
|
47
47
|
}));
|
|
48
48
|
setCreditCardOptions(options);
|
|
49
49
|
const defaultCard = creditCards.length
|
|
@@ -70,7 +70,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
70
70
|
const purchaseWithCaptcha = (credit_card) => {
|
|
71
71
|
const alert = {
|
|
72
72
|
type: 'working',
|
|
73
|
-
args: { text: 'Submitting your contribution...' }
|
|
73
|
+
args: { text: 'Submitting your contribution...' }
|
|
74
74
|
};
|
|
75
75
|
if (recaptchaKey) {
|
|
76
76
|
try {
|
|
@@ -87,7 +87,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
87
87
|
amount: amount,
|
|
88
88
|
email: email,
|
|
89
89
|
credit_card,
|
|
90
|
-
token: token
|
|
90
|
+
token: token
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -104,7 +104,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
104
104
|
amount: amount,
|
|
105
105
|
email: email,
|
|
106
106
|
credit_card,
|
|
107
|
-
token: ''
|
|
107
|
+
token: ''
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
};
|
|
@@ -165,7 +165,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
165
165
|
handleCreditCard,
|
|
166
166
|
handleSubmit,
|
|
167
167
|
handleReset,
|
|
168
|
-
setErrors
|
|
168
|
+
setErrors
|
|
169
169
|
};
|
|
170
170
|
};
|
|
171
171
|
exports.useDonationsForm = useDonationsForm;
|
|
@@ -6,13 +6,15 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
6
6
|
const submitRef = (0, react_1.useRef)(null);
|
|
7
7
|
const inputRef = (0, react_1.useRef)(null);
|
|
8
8
|
const customerCardId = creditCards[0].customer_card_id;
|
|
9
|
-
const [data, setData] = (0, react_1.useState)({
|
|
9
|
+
const [data, setData] = (0, react_1.useState)({
|
|
10
|
+
customer_card_id: customerCardId
|
|
11
|
+
});
|
|
10
12
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
13
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
-
const options = creditCards.map(
|
|
14
|
+
const options = creditCards.map(i => {
|
|
13
15
|
return {
|
|
14
16
|
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
15
|
-
value: i.customer_card_id
|
|
17
|
+
value: i.customer_card_id
|
|
16
18
|
};
|
|
17
19
|
});
|
|
18
20
|
(0, react_1.useEffect)(() => {
|
|
@@ -53,7 +55,7 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
53
55
|
data,
|
|
54
56
|
submitting,
|
|
55
57
|
handleChange,
|
|
56
|
-
handleSubmit
|
|
58
|
+
handleSubmit
|
|
57
59
|
};
|
|
58
60
|
};
|
|
59
61
|
exports.useGiftCardForm = useGiftCardForm;
|