@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
|
@@ -3,19 +3,20 @@ import { calcPrices } from '../../utils';
|
|
|
3
3
|
export const useBuilder = (orderItem) => {
|
|
4
4
|
const [item, setItem] = useState(orderItem);
|
|
5
5
|
const increment = () => {
|
|
6
|
-
var _a, _b, _c, _d;
|
|
7
6
|
const newQuantity = item.max
|
|
8
|
-
? Math.min(
|
|
9
|
-
:
|
|
10
|
-
|
|
7
|
+
? Math.min(item.quantity + item.increment, item.max)
|
|
8
|
+
: item.quantity + item.increment;
|
|
9
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
|
|
10
|
+
setItem(pricedItem);
|
|
11
11
|
};
|
|
12
12
|
const decrement = () => {
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
setItem(
|
|
13
|
+
const newQuantity = Math.max(item.quantity - item.increment, item.min);
|
|
14
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
|
|
15
|
+
setItem(pricedItem);
|
|
16
16
|
};
|
|
17
17
|
const setQuantity = (quantity) => {
|
|
18
|
-
|
|
18
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity }));
|
|
19
|
+
setItem(pricedItem);
|
|
19
20
|
};
|
|
20
21
|
const setMadeFor = (madeFor) => {
|
|
21
22
|
setItem(Object.assign(Object.assign({}, item), { madeFor }));
|
|
@@ -23,93 +24,78 @@ export const useBuilder = (orderItem) => {
|
|
|
23
24
|
const setNotes = (notes) => {
|
|
24
25
|
setItem(Object.assign(Object.assign({}, item), { notes }));
|
|
25
26
|
};
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const newQuantity = option.id === optionId ? 1 : 0;
|
|
33
|
-
return Object.assign(Object.assign({}, option), { quantity: newQuantity });
|
|
34
|
-
});
|
|
35
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
36
|
-
}
|
|
37
|
-
return group;
|
|
27
|
+
const setMadeForNotes = (madeFor, notes) => {
|
|
28
|
+
setItem(Object.assign(Object.assign({}, item), { madeFor, notes }));
|
|
29
|
+
};
|
|
30
|
+
const toggleGroupOption = (group, optionId) => {
|
|
31
|
+
const options = group.options.map(option => {
|
|
32
|
+
return Object.assign(Object.assign({}, option), { quantity: option.id === optionId ? 1 : 0 });
|
|
38
33
|
});
|
|
39
|
-
|
|
34
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
40
35
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
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);
|
|
47
|
-
if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
|
|
48
|
-
return group;
|
|
49
|
-
const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
|
|
50
|
-
var _a, _b, _c, _d;
|
|
51
|
-
if (option.id === optionId) {
|
|
52
|
-
let quantity = ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = option.increment) !== null && _b !== void 0 ? _b : 0);
|
|
53
|
-
const quantities = [quantity];
|
|
54
|
-
if (option.max !== 0)
|
|
55
|
-
quantities.push(((_c = option.max) !== null && _c !== void 0 ? _c : 0));
|
|
56
|
-
if (group.max !== 0)
|
|
57
|
-
quantities.push(((_d = group.max) !== null && _d !== void 0 ? _d : 0) - (count !== null && count !== void 0 ? count : 0));
|
|
58
|
-
quantity = Math.min(...quantities);
|
|
59
|
-
return Object.assign(Object.assign({}, option), { quantity });
|
|
60
|
-
}
|
|
61
|
-
return option;
|
|
62
|
-
});
|
|
63
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
64
|
-
}
|
|
36
|
+
const incrementGroupOption = (group, optionId) => {
|
|
37
|
+
const count = group.options
|
|
38
|
+
.filter(o => o.id !== optionId)
|
|
39
|
+
.reduce((t, o) => t + o.quantity, 0);
|
|
40
|
+
if (group.max !== 0 && count >= group.max)
|
|
65
41
|
return group;
|
|
42
|
+
const options = group.options.map(option => {
|
|
43
|
+
if (option.id === optionId) {
|
|
44
|
+
let quantity = option.quantity + option.increment;
|
|
45
|
+
const quantities = [quantity];
|
|
46
|
+
if (option.max !== 0)
|
|
47
|
+
quantities.push(option.max);
|
|
48
|
+
if (group.max !== 0)
|
|
49
|
+
quantities.push(group.max - count);
|
|
50
|
+
quantity = Math.min(...quantities);
|
|
51
|
+
return Object.assign(Object.assign({}, option), { quantity });
|
|
52
|
+
}
|
|
53
|
+
return option;
|
|
66
54
|
});
|
|
67
|
-
|
|
55
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
68
56
|
};
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const options = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
|
|
75
|
-
var _a, _b;
|
|
76
|
-
if (option.id === optionId) {
|
|
77
|
-
const quantity = Math.max(((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = option.increment) !== null && _b !== void 0 ? _b : 0), 0);
|
|
78
|
-
return Object.assign(Object.assign({}, option), { quantity });
|
|
79
|
-
}
|
|
80
|
-
return option;
|
|
81
|
-
});
|
|
82
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
57
|
+
const decrementGroupOption = (group, optionId) => {
|
|
58
|
+
const options = group.options.map(option => {
|
|
59
|
+
if (option.id === optionId) {
|
|
60
|
+
const quantity = Math.max(option.quantity - option.increment, 0);
|
|
61
|
+
return Object.assign(Object.assign({}, option), { quantity });
|
|
83
62
|
}
|
|
63
|
+
return option;
|
|
64
|
+
});
|
|
65
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
66
|
+
};
|
|
67
|
+
const setGroupOptionQuantity = (group, optionId, quantity) => {
|
|
68
|
+
if (quantity === undefined)
|
|
69
|
+
return group;
|
|
70
|
+
const count = group.options
|
|
71
|
+
.filter(o => o.id !== optionId)
|
|
72
|
+
.reduce((t, o) => t + o.quantity, 0);
|
|
73
|
+
if (group.max !== 0 && count >= group.max)
|
|
84
74
|
return group;
|
|
75
|
+
const options = group.options.map(option => {
|
|
76
|
+
if (option.id === optionId) {
|
|
77
|
+
const quantities = quantity ? [quantity] : [0];
|
|
78
|
+
if (option.max !== 0)
|
|
79
|
+
quantities.push(option.max);
|
|
80
|
+
if (group.max !== 0)
|
|
81
|
+
quantities.push(group.max - count);
|
|
82
|
+
quantity = Math.min(...quantities);
|
|
83
|
+
quantity = Math.max(quantity, option.min);
|
|
84
|
+
return Object.assign(Object.assign({}, option), { quantity });
|
|
85
|
+
}
|
|
86
|
+
return option;
|
|
85
87
|
});
|
|
86
|
-
|
|
88
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
87
89
|
};
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var _a, _b, _c;
|
|
90
|
+
const updateGroups = (groups, levels, fn, quantity) => {
|
|
91
|
+
const [[groupId, optionId], ...rest] = levels;
|
|
92
|
+
return groups.map(group => {
|
|
92
93
|
if (group.id === groupId) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
|
|
97
|
-
var _a, _b, _c;
|
|
98
|
-
const optionGroups = nested || option.groups || [];
|
|
94
|
+
if (!rest.length)
|
|
95
|
+
return fn(group, optionId, quantity);
|
|
96
|
+
const options = group.options.map(option => {
|
|
99
97
|
if (option.id === optionId) {
|
|
100
|
-
|
|
101
|
-
return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
const quantities = [quantity];
|
|
105
|
-
if (option.max !== 0)
|
|
106
|
-
quantities.push(((_a = option.max) !== null && _a !== void 0 ? _a : 0));
|
|
107
|
-
if (group.max !== 0)
|
|
108
|
-
quantities.push(((_b = group.max) !== null && _b !== void 0 ? _b : 0) - (count !== null && count !== void 0 ? count : 0));
|
|
109
|
-
quantity = Math.min(...quantities);
|
|
110
|
-
quantity = Math.max(quantity, ((_c = option.min) !== null && _c !== void 0 ? _c : 0));
|
|
111
|
-
return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
|
|
112
|
-
}
|
|
98
|
+
return Object.assign(Object.assign({}, option), { groups: updateGroups(option.groups, rest, fn) });
|
|
113
99
|
}
|
|
114
100
|
return option;
|
|
115
101
|
});
|
|
@@ -117,7 +103,26 @@ export const useBuilder = (orderItem) => {
|
|
|
117
103
|
}
|
|
118
104
|
return group;
|
|
119
105
|
});
|
|
120
|
-
|
|
106
|
+
};
|
|
107
|
+
const toggleOption = (levels) => {
|
|
108
|
+
const groups = updateGroups(item.groups, levels, toggleGroupOption);
|
|
109
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
110
|
+
setItem(pricedItem);
|
|
111
|
+
};
|
|
112
|
+
const incrementOption = (levels) => {
|
|
113
|
+
const groups = updateGroups(item.groups, levels, incrementGroupOption);
|
|
114
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
115
|
+
setItem(pricedItem);
|
|
116
|
+
};
|
|
117
|
+
const decrementOption = (levels) => {
|
|
118
|
+
const groups = updateGroups(item.groups, levels, decrementGroupOption);
|
|
119
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
120
|
+
setItem(pricedItem);
|
|
121
|
+
};
|
|
122
|
+
const setOptionQuantity = (levels, quantity) => {
|
|
123
|
+
const groups = updateGroups(item.groups, levels, setGroupOptionQuantity, quantity);
|
|
124
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
|
|
125
|
+
setItem(pricedItem);
|
|
121
126
|
};
|
|
122
127
|
return {
|
|
123
128
|
item,
|
|
@@ -126,9 +131,10 @@ export const useBuilder = (orderItem) => {
|
|
|
126
131
|
setQuantity,
|
|
127
132
|
setMadeFor,
|
|
128
133
|
setNotes,
|
|
134
|
+
setMadeForNotes,
|
|
129
135
|
toggleOption,
|
|
130
136
|
incrementOption,
|
|
131
137
|
decrementOption,
|
|
132
|
-
setOptionQuantity
|
|
138
|
+
setOptionQuantity
|
|
133
139
|
};
|
|
134
140
|
};
|
|
@@ -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
|
};
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import { formatDollars, getItemOptions } from
|
|
2
|
-
export const useOrderItem = (orderItem, favorite = null,
|
|
3
|
-
|
|
4
|
-
const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile, } = displaySettings;
|
|
1
|
+
import { formatDollars, getItemOptions, hasGroupsBelowMin } from '../../utils';
|
|
2
|
+
export const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySettings, cartCounts = {}, isMobile = true) => {
|
|
3
|
+
const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile } = displaySettings;
|
|
5
4
|
const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
|
|
6
|
-
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, } = orderItem;
|
|
7
|
-
const cartCount =
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const sizeOnly = sizeGroup && (groups === null || groups === void 0 ? void 0 : groups.length) === 1;
|
|
5
|
+
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, isSoldOut } = orderItem;
|
|
6
|
+
const cartCount = cartCounts[orderItem.id] || 0;
|
|
7
|
+
const displayTags = showTags && tags.length ? tags : [];
|
|
8
|
+
const displayAllergens = showAllergens && allergens.length ? allergens : [];
|
|
9
|
+
const contains = allergens.filter(allergen => allergenAlerts.includes(allergen));
|
|
10
|
+
const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
|
|
11
|
+
const sizeGroup = groups.find(i => i.isSize);
|
|
12
|
+
const sizeOnly = sizeGroup && groups.length === 1;
|
|
15
13
|
const defaultOption = !sizeGroup
|
|
16
14
|
? null
|
|
17
|
-
:
|
|
15
|
+
: sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
|
|
18
16
|
const currentPrice = totalPrice
|
|
19
17
|
? totalPrice
|
|
20
18
|
: defaultOption
|
|
21
19
|
? defaultOption.price
|
|
22
20
|
: price;
|
|
23
|
-
const displayPrice = formatDollars(
|
|
21
|
+
const displayPrice = formatDollars(currentPrice.toString());
|
|
24
22
|
const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
|
|
25
23
|
const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
|
|
26
|
-
const groupsBelowMin = (
|
|
27
|
-
const isIncomplete = totalPrice === 0 ||
|
|
28
|
-
const nonSizeGroups = groups
|
|
24
|
+
const groupsBelowMin = hasGroupsBelowMin(null, groups);
|
|
25
|
+
const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
|
|
26
|
+
const nonSizeGroups = groups.filter(i => !i.isSize);
|
|
29
27
|
const currentOptions = getItemOptions({ groups: nonSizeGroups });
|
|
30
|
-
const hasSelections =
|
|
28
|
+
const hasSelections = currentOptions.length > 0;
|
|
31
29
|
const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
|
|
32
30
|
const desc = showDesc === 'HIDE'
|
|
33
31
|
? ''
|
|
@@ -35,11 +33,12 @@ export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenA
|
|
|
35
33
|
? shortDescription
|
|
36
34
|
: description;
|
|
37
35
|
const optionNames = favorite
|
|
38
|
-
?
|
|
39
|
-
|
|
40
|
-
const names =
|
|
36
|
+
? favorite.item.groups
|
|
37
|
+
.reduce((arr, group) => {
|
|
38
|
+
const names = group.options.map(o => o.name);
|
|
41
39
|
return [...arr, ...names];
|
|
42
|
-
}, [])
|
|
40
|
+
}, [])
|
|
41
|
+
.join(', ')
|
|
43
42
|
: null;
|
|
44
43
|
const displayDesc = optionNames || desc;
|
|
45
44
|
return Object.assign(Object.assign({}, orderItem), { showImage,
|
|
@@ -12,7 +12,7 @@ export const useAddressForm = (address, loading, error, update, callback) => {
|
|
|
12
12
|
{ label: 'Contact Phone', name: 'phone', type: 'phone-pad' },
|
|
13
13
|
{ label: 'Description', name: 'description', type: 'default' },
|
|
14
14
|
{ label: 'Notes', name: 'notes', type: 'default' },
|
|
15
|
-
{ label: 'Is Default', name: 'is_default', type: 'checkbox' }
|
|
15
|
+
{ label: 'Is Default', name: 'is_default', type: 'checkbox' }
|
|
16
16
|
];
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
var _a, _b;
|
|
@@ -6,7 +6,7 @@ export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
|
6
6
|
const [submitting, setSubmitting] = useState(false);
|
|
7
7
|
const fields = [
|
|
8
8
|
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
9
|
-
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
9
|
+
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
10
10
|
];
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
return () => {
|
|
@@ -39,6 +39,6 @@ export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
|
39
39
|
data,
|
|
40
40
|
submitting,
|
|
41
41
|
handleChange,
|
|
42
|
-
handleSubmit
|
|
42
|
+
handleSubmit
|
|
43
43
|
};
|
|
44
44
|
};
|
|
@@ -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,13 +1,13 @@
|
|
|
1
1
|
import { useRef, useState } from 'react';
|
|
2
|
-
import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard
|
|
2
|
+
import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard } from '../';
|
|
3
3
|
const defaultState = {
|
|
4
4
|
acct: '',
|
|
5
5
|
exp: '',
|
|
6
6
|
cvv: '',
|
|
7
7
|
zip: '',
|
|
8
|
-
is_default: false
|
|
8
|
+
is_default: false
|
|
9
9
|
};
|
|
10
|
-
const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
10
|
+
export const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
11
11
|
const [initCard, initCardType] = formatCard(initState);
|
|
12
12
|
const submitRef = useRef(null);
|
|
13
13
|
const [data, setData] = useState(initCard || defaultState);
|
|
@@ -49,7 +49,6 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
|
49
49
|
setErrors,
|
|
50
50
|
handleChange,
|
|
51
51
|
handleBlur,
|
|
52
|
-
isComplete
|
|
52
|
+
isComplete
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
|
-
export default useCreditCard;
|
|
@@ -35,7 +35,7 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
35
35
|
if (!token) {
|
|
36
36
|
setSubmitting(false);
|
|
37
37
|
setErrors({
|
|
38
|
-
form: 'Please complete the recaptcha before submitting'
|
|
38
|
+
form: 'Please complete the recaptcha before submitting'
|
|
39
39
|
});
|
|
40
40
|
if (windowRef)
|
|
41
41
|
windowRef.scrollTo({ top: 0 });
|
|
@@ -48,7 +48,7 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
48
48
|
catch (err) {
|
|
49
49
|
setSubmitting(false);
|
|
50
50
|
setErrors({
|
|
51
|
-
form: 'Please complete the recaptcha before submitting'
|
|
51
|
+
form: 'Please complete the recaptcha before submitting'
|
|
52
52
|
});
|
|
53
53
|
if (windowRef)
|
|
54
54
|
windowRef.scrollTo({ top: 0 });
|
|
@@ -66,6 +66,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
66
66
|
recaptchaRef,
|
|
67
67
|
data,
|
|
68
68
|
submitting,
|
|
69
|
-
handleSubmit
|
|
69
|
+
handleSubmit
|
|
70
70
|
};
|
|
71
71
|
};
|
|
@@ -40,7 +40,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
40
40
|
if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
|
|
41
41
|
const options = creditCards.map(i => ({
|
|
42
42
|
label: `${i.card_type_name} ending in ${i.last4}`,
|
|
43
|
-
value: i.customer_card_id
|
|
43
|
+
value: i.customer_card_id
|
|
44
44
|
}));
|
|
45
45
|
setCreditCardOptions(options);
|
|
46
46
|
const defaultCard = creditCards.length
|
|
@@ -67,7 +67,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
67
67
|
const purchaseWithCaptcha = (credit_card) => {
|
|
68
68
|
const alert = {
|
|
69
69
|
type: 'working',
|
|
70
|
-
args: { text: 'Submitting your contribution...' }
|
|
70
|
+
args: { text: 'Submitting your contribution...' }
|
|
71
71
|
};
|
|
72
72
|
if (recaptchaKey) {
|
|
73
73
|
try {
|
|
@@ -84,7 +84,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
84
84
|
amount: amount,
|
|
85
85
|
email: email,
|
|
86
86
|
credit_card,
|
|
87
|
-
token: token
|
|
87
|
+
token: token
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -101,7 +101,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
101
101
|
amount: amount,
|
|
102
102
|
email: email,
|
|
103
103
|
credit_card,
|
|
104
|
-
token: ''
|
|
104
|
+
token: ''
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
};
|
|
@@ -162,6 +162,6 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
162
162
|
handleCreditCard,
|
|
163
163
|
handleSubmit,
|
|
164
164
|
handleReset,
|
|
165
|
-
setErrors
|
|
165
|
+
setErrors
|
|
166
166
|
};
|
|
167
167
|
};
|
|
@@ -3,13 +3,15 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
|
|
|
3
3
|
const submitRef = useRef(null);
|
|
4
4
|
const inputRef = useRef(null);
|
|
5
5
|
const customerCardId = creditCards[0].customer_card_id;
|
|
6
|
-
const [data, setData] = useState({
|
|
6
|
+
const [data, setData] = useState({
|
|
7
|
+
customer_card_id: customerCardId
|
|
8
|
+
});
|
|
7
9
|
const [errors, setErrors] = useState({});
|
|
8
10
|
const [submitting, setSubmitting] = useState(false);
|
|
9
|
-
const options = creditCards.map(
|
|
11
|
+
const options = creditCards.map(i => {
|
|
10
12
|
return {
|
|
11
13
|
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
12
|
-
value: i.customer_card_id
|
|
14
|
+
value: i.customer_card_id
|
|
13
15
|
};
|
|
14
16
|
});
|
|
15
17
|
useEffect(() => {
|
|
@@ -50,6 +52,6 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
|
|
|
50
52
|
data,
|
|
51
53
|
submitting,
|
|
52
54
|
handleChange,
|
|
53
|
-
handleSubmit
|
|
55
|
+
handleSubmit
|
|
54
56
|
};
|
|
55
57
|
};
|