@open-tender/utils 0.4.30 → 0.4.32
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/LICENSE.md +21 -21
- package/README.md +2 -2
- package/dist/cjs/__tests__/utils/helpers.test.d.ts +1 -1
- package/dist/cjs/__tests__/utils/helpers.test.js +96 -96
- package/dist/cjs/__tests__/utils/theme.test.d.ts +1 -1
- package/dist/cjs/__tests__/utils/theme.test.js +37 -37
- package/dist/cjs/hooks/index.d.ts +35 -35
- package/dist/cjs/hooks/index.js +38 -38
- package/dist/cjs/hooks/types.d.ts +4 -4
- package/dist/cjs/hooks/types.js +2 -2
- package/dist/cjs/hooks/useAccordion.d.ts +22 -22
- package/dist/cjs/hooks/useAccordion.js +56 -56
- package/dist/cjs/hooks/useAddressForm.d.ts +12 -12
- package/dist/cjs/hooks/useAddressForm.js +83 -83
- package/dist/cjs/hooks/useAllergenForm.d.ts +10 -10
- package/dist/cjs/hooks/useAllergenForm.js +58 -58
- package/dist/cjs/hooks/useBuilder.d.ts +14 -14
- package/dist/cjs/hooks/useBuilder.js +144 -144
- package/dist/cjs/hooks/useCartGuestForm.d.ts +12 -12
- package/dist/cjs/hooks/useCartGuestForm.js +58 -58
- package/dist/cjs/hooks/useCartPoints.d.ts +13 -13
- package/dist/cjs/hooks/useCartPoints.js +74 -74
- package/dist/cjs/hooks/useCommunicationPreferences.js +1 -1
- package/dist/cjs/hooks/useCreditCard.d.ts +13 -13
- package/dist/cjs/hooks/useCreditCard.js +63 -63
- package/dist/cjs/hooks/useCreditCardForm.d.ts +10 -10
- package/dist/cjs/hooks/useCreditCardForm.js +71 -71
- package/dist/cjs/hooks/useCurbside.d.ts +9 -9
- package/dist/cjs/hooks/useCurbside.js +39 -39
- package/dist/cjs/hooks/useDineInForm.d.ts +11 -11
- package/dist/cjs/hooks/useDineInForm.js +56 -56
- package/dist/cjs/hooks/useDonationForm.d.ts +28 -28
- package/dist/cjs/hooks/useDonationForm.js +172 -172
- package/dist/cjs/hooks/useFirstTimes.d.ts +18 -18
- package/dist/cjs/hooks/useFirstTimes.js +81 -81
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +14 -14
- package/dist/cjs/hooks/useGiftCardAssignForm.js +57 -57
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +50 -50
- package/dist/cjs/hooks/useGiftCardForm.d.ts +12 -12
- package/dist/cjs/hooks/useGiftCardForm.js +74 -74
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +31 -31
- package/dist/cjs/hooks/useGiftCardsForm.js +195 -195
- package/dist/cjs/hooks/useGuestCheckoutForm.d.ts +21 -21
- package/dist/cjs/hooks/useGuestCheckoutForm.js +89 -89
- package/dist/cjs/hooks/useGuestForm.d.ts +12 -12
- package/dist/cjs/hooks/useGuestForm.js +60 -60
- package/dist/cjs/hooks/useImage.d.ts +5 -5
- package/dist/cjs/hooks/useImage.js +33 -33
- package/dist/cjs/hooks/useLoginForm.d.ts +12 -12
- package/dist/cjs/hooks/useLoginForm.js +67 -67
- package/dist/cjs/hooks/useMenuItem.d.ts +57 -55
- package/dist/cjs/hooks/useMenuItem.js +67 -67
- package/dist/cjs/hooks/useModifier.d.ts +53 -51
- package/dist/cjs/hooks/useModifier.js +72 -72
- package/dist/cjs/hooks/useModifierGroup.d.ts +15 -15
- package/dist/cjs/hooks/useModifierGroup.js +17 -17
- package/dist/cjs/hooks/useOneTimePasscodeForm.d.ts +16 -16
- package/dist/cjs/hooks/useOneTimePasscodeForm.js +87 -87
- package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +11 -11
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +65 -65
- package/dist/cjs/hooks/useOrderItem.d.ts +48 -46
- package/dist/cjs/hooks/useOrderItem.js +54 -54
- package/dist/cjs/hooks/useOrderRating.d.ts +10 -10
- package/dist/cjs/hooks/useOrderRating.js +34 -34
- package/dist/cjs/hooks/useOrderRatingForm.d.ts +11 -11
- package/dist/cjs/hooks/useOrderRatingForm.js +35 -35
- package/dist/cjs/hooks/useProfileForm.d.ts +15 -15
- package/dist/cjs/hooks/useProfileForm.js +116 -116
- package/dist/cjs/hooks/useResetPasswordForm.d.ts +12 -12
- package/dist/cjs/hooks/useResetPasswordForm.js +77 -77
- package/dist/cjs/hooks/useSendResetForm.d.ts +14 -14
- package/dist/cjs/hooks/useSendResetForm.js +57 -57
- package/dist/cjs/hooks/useSignUpForm.d.ts +20 -20
- package/dist/cjs/hooks/useSignUpForm.js +151 -151
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/cjs/hooks/useSignUpGuestForm.js +122 -113
- package/dist/cjs/hooks/useSigninForm.d.ts +12 -12
- package/dist/cjs/hooks/useSigninForm.js +66 -66
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/utils/cards.d.ts +20 -20
- package/dist/cjs/utils/cards.js +155 -155
- package/dist/cjs/utils/cart.d.ts +202 -198
- package/dist/cjs/utils/cart.js +909 -905
- package/dist/cjs/utils/checkout.d.ts +55 -55
- package/dist/cjs/utils/checkout.js +125 -125
- package/dist/cjs/utils/constants.d.ts +43 -43
- package/dist/cjs/utils/constants.js +58 -58
- package/dist/cjs/utils/customer.d.ts +4 -4
- package/dist/cjs/utils/customer.js +34 -34
- package/dist/cjs/utils/datetimes.d.ts +99 -99
- package/dist/cjs/utils/datetimes.js +601 -601
- package/dist/cjs/utils/errors.d.ts +51 -51
- package/dist/cjs/utils/errors.js +191 -191
- package/dist/cjs/utils/favorites.d.ts +10 -10
- package/dist/cjs/utils/favorites.js +119 -119
- package/dist/cjs/utils/googleMaps.d.ts +14 -14
- package/dist/cjs/utils/googleMaps.js +30 -30
- package/dist/cjs/utils/helpers.d.ts +63 -63
- package/dist/cjs/utils/helpers.js +244 -244
- package/dist/cjs/utils/index.d.ts +19 -19
- package/dist/cjs/utils/index.js +23 -23
- package/dist/cjs/utils/keypad.d.ts +9 -9
- package/dist/cjs/utils/keypad.js +105 -105
- package/dist/cjs/utils/maps.d.ts +226 -226
- package/dist/cjs/utils/maps.js +334 -334
- package/dist/cjs/utils/menu.d.ts +117 -113
- package/dist/cjs/utils/menu.js +82 -82
- package/dist/cjs/utils/orders.d.ts +21 -21
- package/dist/cjs/utils/orders.js +202 -202
- package/dist/cjs/utils/pizzaBuilder.d.ts +10 -10
- package/dist/cjs/utils/pizzaBuilder.js +43 -43
- package/dist/cjs/utils/refunds.d.ts +35 -35
- package/dist/cjs/utils/refunds.js +98 -98
- package/dist/cjs/utils/revenueCenters.d.ts +11 -11
- package/dist/cjs/utils/revenueCenters.js +125 -125
- package/dist/cjs/utils/rewards.d.ts +4 -4
- package/dist/cjs/utils/rewards.js +106 -106
- package/dist/cjs/utils/theme.d.ts +27 -27
- package/dist/cjs/utils/theme.js +266 -266
- package/dist/cjs/utils/version.d.ts +4 -4
- package/dist/cjs/utils/version.js +38 -38
- package/dist/esm/__tests__/utils/helpers.test.d.ts +1 -1
- package/dist/esm/__tests__/utils/helpers.test.js +94 -94
- package/dist/esm/__tests__/utils/theme.test.d.ts +1 -1
- package/dist/esm/__tests__/utils/theme.test.js +35 -35
- package/dist/esm/hooks/index.d.ts +35 -35
- package/dist/esm/hooks/index.js +35 -35
- package/dist/esm/hooks/types.d.ts +4 -4
- package/dist/esm/hooks/types.js +1 -1
- package/dist/esm/hooks/useAccordion.d.ts +22 -22
- package/dist/esm/hooks/useAccordion.js +52 -52
- package/dist/esm/hooks/useAddressForm.d.ts +12 -12
- package/dist/esm/hooks/useAddressForm.js +79 -79
- package/dist/esm/hooks/useAllergenForm.d.ts +10 -10
- package/dist/esm/hooks/useAllergenForm.js +54 -54
- package/dist/esm/hooks/useBuilder.d.ts +14 -14
- package/dist/esm/hooks/useBuilder.js +140 -140
- package/dist/esm/hooks/useCartGuestForm.d.ts +12 -12
- package/dist/esm/hooks/useCartGuestForm.js +54 -54
- package/dist/esm/hooks/useCartPoints.d.ts +13 -13
- package/dist/esm/hooks/useCartPoints.js +70 -70
- package/dist/esm/hooks/useCommunicationPreferences.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +13 -13
- package/dist/esm/hooks/useCreditCard.js +59 -59
- package/dist/esm/hooks/useCreditCardForm.d.ts +10 -10
- package/dist/esm/hooks/useCreditCardForm.js +67 -67
- package/dist/esm/hooks/useCurbside.d.ts +9 -9
- package/dist/esm/hooks/useCurbside.js +35 -35
- package/dist/esm/hooks/useDineInForm.d.ts +11 -11
- package/dist/esm/hooks/useDineInForm.js +52 -52
- package/dist/esm/hooks/useDonationForm.d.ts +28 -28
- package/dist/esm/hooks/useDonationForm.js +168 -168
- package/dist/esm/hooks/useFirstTimes.d.ts +18 -18
- package/dist/esm/hooks/useFirstTimes.js +77 -77
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +14 -14
- package/dist/esm/hooks/useGiftCardAssignForm.js +53 -53
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +46 -46
- package/dist/esm/hooks/useGiftCardForm.d.ts +12 -12
- package/dist/esm/hooks/useGiftCardForm.js +70 -70
- package/dist/esm/hooks/useGiftCardsForm.d.ts +31 -31
- package/dist/esm/hooks/useGiftCardsForm.js +191 -191
- package/dist/esm/hooks/useGuestCheckoutForm.d.ts +21 -21
- package/dist/esm/hooks/useGuestCheckoutForm.js +85 -85
- package/dist/esm/hooks/useGuestForm.d.ts +12 -12
- package/dist/esm/hooks/useGuestForm.js +56 -56
- package/dist/esm/hooks/useImage.d.ts +5 -5
- package/dist/esm/hooks/useImage.js +29 -29
- package/dist/esm/hooks/useLoginForm.d.ts +12 -12
- package/dist/esm/hooks/useLoginForm.js +63 -63
- package/dist/esm/hooks/useMenuItem.d.ts +57 -55
- package/dist/esm/hooks/useMenuItem.js +63 -63
- package/dist/esm/hooks/useModifier.d.ts +53 -51
- package/dist/esm/hooks/useModifier.js +68 -68
- package/dist/esm/hooks/useModifierGroup.d.ts +15 -15
- package/dist/esm/hooks/useModifierGroup.js +13 -13
- package/dist/esm/hooks/useOneTimePasscodeForm.d.ts +16 -16
- package/dist/esm/hooks/useOneTimePasscodeForm.js +83 -83
- package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +11 -11
- package/dist/esm/hooks/useOrderFulfillmentForm.js +61 -61
- package/dist/esm/hooks/useOrderItem.d.ts +48 -46
- package/dist/esm/hooks/useOrderItem.js +50 -50
- package/dist/esm/hooks/useOrderRating.d.ts +10 -10
- package/dist/esm/hooks/useOrderRating.js +30 -30
- package/dist/esm/hooks/useOrderRatingForm.d.ts +11 -11
- package/dist/esm/hooks/useOrderRatingForm.js +31 -31
- package/dist/esm/hooks/useProfileForm.d.ts +15 -15
- package/dist/esm/hooks/useProfileForm.js +112 -112
- package/dist/esm/hooks/useResetPasswordForm.d.ts +12 -12
- package/dist/esm/hooks/useResetPasswordForm.js +73 -73
- package/dist/esm/hooks/useSendResetForm.d.ts +14 -14
- package/dist/esm/hooks/useSendResetForm.js +53 -53
- package/dist/esm/hooks/useSignUpForm.d.ts +20 -20
- package/dist/esm/hooks/useSignUpForm.js +147 -147
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/esm/hooks/useSignUpGuestForm.js +118 -109
- package/dist/esm/hooks/useSigninForm.d.ts +12 -12
- package/dist/esm/hooks/useSigninForm.js +62 -62
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/cards.d.ts +20 -20
- package/dist/esm/utils/cards.js +146 -146
- package/dist/esm/utils/cart.d.ts +202 -198
- package/dist/esm/utils/cart.js +868 -864
- package/dist/esm/utils/checkout.d.ts +55 -55
- package/dist/esm/utils/checkout.js +117 -117
- package/dist/esm/utils/constants.d.ts +43 -43
- package/dist/esm/utils/constants.js +55 -55
- package/dist/esm/utils/customer.d.ts +4 -4
- package/dist/esm/utils/customer.js +29 -29
- package/dist/esm/utils/datetimes.d.ts +99 -99
- package/dist/esm/utils/datetimes.js +531 -531
- package/dist/esm/utils/errors.d.ts +51 -51
- package/dist/esm/utils/errors.js +180 -180
- package/dist/esm/utils/favorites.d.ts +10 -10
- package/dist/esm/utils/favorites.js +109 -109
- package/dist/esm/utils/googleMaps.d.ts +14 -14
- package/dist/esm/utils/googleMaps.js +26 -26
- package/dist/esm/utils/helpers.d.ts +63 -63
- package/dist/esm/utils/helpers.js +205 -205
- package/dist/esm/utils/index.d.ts +19 -19
- package/dist/esm/utils/index.js +20 -20
- package/dist/esm/utils/keypad.d.ts +9 -9
- package/dist/esm/utils/keypad.js +97 -97
- package/dist/esm/utils/maps.d.ts +226 -226
- package/dist/esm/utils/maps.js +316 -316
- package/dist/esm/utils/menu.d.ts +117 -113
- package/dist/esm/utils/menu.js +74 -74
- package/dist/esm/utils/orders.d.ts +21 -21
- package/dist/esm/utils/orders.js +185 -185
- package/dist/esm/utils/pizzaBuilder.d.ts +10 -10
- package/dist/esm/utils/pizzaBuilder.js +38 -38
- package/dist/esm/utils/refunds.d.ts +35 -35
- package/dist/esm/utils/refunds.js +90 -90
- package/dist/esm/utils/revenueCenters.d.ts +11 -11
- package/dist/esm/utils/revenueCenters.js +115 -115
- package/dist/esm/utils/rewards.d.ts +4 -4
- package/dist/esm/utils/rewards.js +100 -100
- package/dist/esm/utils/theme.d.ts +27 -27
- package/dist/esm/utils/theme.js +254 -254
- package/dist/esm/utils/version.d.ts +4 -4
- package/dist/esm/utils/version.js +34 -34
- package/package.json +69 -68
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
export const makeRefundCartLookup = (cart) => {
|
|
2
|
-
const lookup = {};
|
|
3
|
-
cart.forEach(item => {
|
|
4
|
-
var _a;
|
|
5
|
-
const { line_no, quantity, price_total } = item;
|
|
6
|
-
lookup[line_no !== null && line_no !== void 0 ? line_no : 0] = { quantity, price_total };
|
|
7
|
-
(_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.forEach(group => group.options.forEach(option => {
|
|
8
|
-
const { line_no, quantity, price } = option;
|
|
9
|
-
lookup[line_no !== null && line_no !== void 0 ? line_no : 0] = { quantity, price };
|
|
10
|
-
}));
|
|
11
|
-
});
|
|
12
|
-
return lookup;
|
|
13
|
-
};
|
|
14
|
-
export const makeAmountsLookup = (items, key = 'id') => {
|
|
15
|
-
return items.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i[key]]: i.amount })), {});
|
|
16
|
-
};
|
|
17
|
-
export const makeRefundLookup = (order) => {
|
|
18
|
-
const { cart, gift_cards, surcharges, discounts, taxes, totals, tenders } = order;
|
|
19
|
-
const { subtotal, gift_card, surcharge, discount, tax, tip, shipping, total } = totals;
|
|
20
|
-
return {
|
|
21
|
-
cart: makeRefundCartLookup(cart),
|
|
22
|
-
gift_cards: gift_cards ? makeAmountsLookup(gift_cards, 'code') : null,
|
|
23
|
-
surcharges: makeAmountsLookup(surcharges),
|
|
24
|
-
discounts: makeAmountsLookup(discounts),
|
|
25
|
-
taxes: makeAmountsLookup(taxes),
|
|
26
|
-
tenders: makeAmountsLookup(tenders, 'tender_index'),
|
|
27
|
-
subtotal,
|
|
28
|
-
gift_card,
|
|
29
|
-
surcharge,
|
|
30
|
-
discount,
|
|
31
|
-
tax,
|
|
32
|
-
tip,
|
|
33
|
-
shipping,
|
|
34
|
-
total
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
const adjustAmount = (amount, refundAmount) => {
|
|
38
|
-
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
39
|
-
};
|
|
40
|
-
export const adjustAmounts = (order, lookup, list, key = 'id') => {
|
|
41
|
-
if (!order[list])
|
|
42
|
-
return order;
|
|
43
|
-
order[list].forEach((i) => {
|
|
44
|
-
const amount = lookup[list][i[key]];
|
|
45
|
-
if (amount)
|
|
46
|
-
i.amount = adjustAmount(i.amount, amount);
|
|
47
|
-
});
|
|
48
|
-
return order;
|
|
49
|
-
};
|
|
50
|
-
const amounts = [
|
|
51
|
-
'subtotal',
|
|
52
|
-
'gift_card',
|
|
53
|
-
'surcharge',
|
|
54
|
-
'discount',
|
|
55
|
-
'tax',
|
|
56
|
-
'tip',
|
|
57
|
-
'shipping',
|
|
58
|
-
'total'
|
|
59
|
-
];
|
|
60
|
-
export const makeNetOrder = (order, refunds) => {
|
|
61
|
-
if (!refunds || !refunds.length)
|
|
62
|
-
return order;
|
|
63
|
-
let copy = JSON.parse(JSON.stringify(order));
|
|
64
|
-
refunds.forEach(refund => {
|
|
65
|
-
const lookup = makeRefundLookup(refund);
|
|
66
|
-
copy.cart.forEach((i) => {
|
|
67
|
-
var _a, _b, _c, _d, _e;
|
|
68
|
-
const item = lookup.cart[(_a = i.line_no) !== null && _a !== void 0 ? _a : 0];
|
|
69
|
-
if (item) {
|
|
70
|
-
i.quantity = (_c = ((_b = i.quantity) !== null && _b !== void 0 ? _b : 0) - item.quantity) !== null && _c !== void 0 ? _c : 0;
|
|
71
|
-
i.price_total = adjustAmount(i.price_total, (_d = item.price_total) !== null && _d !== void 0 ? _d : '0.0');
|
|
72
|
-
}
|
|
73
|
-
if (i.quantity === 0) {
|
|
74
|
-
(_e = i.groups) === null || _e === void 0 ? void 0 : _e.forEach(group => group.options.forEach(option => {
|
|
75
|
-
option.quantity = 0;
|
|
76
|
-
option.price_total = '0.00';
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
copy = adjustAmounts(copy, lookup, 'gift_cards', 'code');
|
|
81
|
-
copy = adjustAmounts(copy, lookup, 'surcharges');
|
|
82
|
-
copy = adjustAmounts(copy, lookup, 'discounts');
|
|
83
|
-
copy = adjustAmounts(copy, lookup, 'taxes');
|
|
84
|
-
copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index');
|
|
85
|
-
amounts.forEach(i => {
|
|
86
|
-
copy.totals[i] = adjustAmount(copy.totals[i], lookup[i]);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
return copy;
|
|
90
|
-
};
|
|
1
|
+
export const makeRefundCartLookup = (cart) => {
|
|
2
|
+
const lookup = {};
|
|
3
|
+
cart.forEach(item => {
|
|
4
|
+
var _a;
|
|
5
|
+
const { line_no, quantity, price_total } = item;
|
|
6
|
+
lookup[line_no !== null && line_no !== void 0 ? line_no : 0] = { quantity, price_total };
|
|
7
|
+
(_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.forEach(group => group.options.forEach(option => {
|
|
8
|
+
const { line_no, quantity, price } = option;
|
|
9
|
+
lookup[line_no !== null && line_no !== void 0 ? line_no : 0] = { quantity, price };
|
|
10
|
+
}));
|
|
11
|
+
});
|
|
12
|
+
return lookup;
|
|
13
|
+
};
|
|
14
|
+
export const makeAmountsLookup = (items, key = 'id') => {
|
|
15
|
+
return items.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i[key]]: i.amount })), {});
|
|
16
|
+
};
|
|
17
|
+
export const makeRefundLookup = (order) => {
|
|
18
|
+
const { cart, gift_cards, surcharges, discounts, taxes, totals, tenders } = order;
|
|
19
|
+
const { subtotal, gift_card, surcharge, discount, tax, tip, shipping, total } = totals;
|
|
20
|
+
return {
|
|
21
|
+
cart: makeRefundCartLookup(cart),
|
|
22
|
+
gift_cards: gift_cards ? makeAmountsLookup(gift_cards, 'code') : null,
|
|
23
|
+
surcharges: makeAmountsLookup(surcharges),
|
|
24
|
+
discounts: makeAmountsLookup(discounts),
|
|
25
|
+
taxes: makeAmountsLookup(taxes),
|
|
26
|
+
tenders: makeAmountsLookup(tenders, 'tender_index'),
|
|
27
|
+
subtotal,
|
|
28
|
+
gift_card,
|
|
29
|
+
surcharge,
|
|
30
|
+
discount,
|
|
31
|
+
tax,
|
|
32
|
+
tip,
|
|
33
|
+
shipping,
|
|
34
|
+
total
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const adjustAmount = (amount, refundAmount) => {
|
|
38
|
+
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
39
|
+
};
|
|
40
|
+
export const adjustAmounts = (order, lookup, list, key = 'id') => {
|
|
41
|
+
if (!order[list])
|
|
42
|
+
return order;
|
|
43
|
+
order[list].forEach((i) => {
|
|
44
|
+
const amount = lookup[list][i[key]];
|
|
45
|
+
if (amount)
|
|
46
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
47
|
+
});
|
|
48
|
+
return order;
|
|
49
|
+
};
|
|
50
|
+
const amounts = [
|
|
51
|
+
'subtotal',
|
|
52
|
+
'gift_card',
|
|
53
|
+
'surcharge',
|
|
54
|
+
'discount',
|
|
55
|
+
'tax',
|
|
56
|
+
'tip',
|
|
57
|
+
'shipping',
|
|
58
|
+
'total'
|
|
59
|
+
];
|
|
60
|
+
export const makeNetOrder = (order, refunds) => {
|
|
61
|
+
if (!refunds || !refunds.length)
|
|
62
|
+
return order;
|
|
63
|
+
let copy = JSON.parse(JSON.stringify(order));
|
|
64
|
+
refunds.forEach(refund => {
|
|
65
|
+
const lookup = makeRefundLookup(refund);
|
|
66
|
+
copy.cart.forEach((i) => {
|
|
67
|
+
var _a, _b, _c, _d, _e;
|
|
68
|
+
const item = lookup.cart[(_a = i.line_no) !== null && _a !== void 0 ? _a : 0];
|
|
69
|
+
if (item) {
|
|
70
|
+
i.quantity = (_c = ((_b = i.quantity) !== null && _b !== void 0 ? _b : 0) - item.quantity) !== null && _c !== void 0 ? _c : 0;
|
|
71
|
+
i.price_total = adjustAmount(i.price_total, (_d = item.price_total) !== null && _d !== void 0 ? _d : '0.0');
|
|
72
|
+
}
|
|
73
|
+
if (i.quantity === 0) {
|
|
74
|
+
(_e = i.groups) === null || _e === void 0 ? void 0 : _e.forEach(group => group.options.forEach(option => {
|
|
75
|
+
option.quantity = 0;
|
|
76
|
+
option.price_total = '0.00';
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
copy = adjustAmounts(copy, lookup, 'gift_cards', 'code');
|
|
81
|
+
copy = adjustAmounts(copy, lookup, 'surcharges');
|
|
82
|
+
copy = adjustAmounts(copy, lookup, 'discounts');
|
|
83
|
+
copy = adjustAmounts(copy, lookup, 'taxes');
|
|
84
|
+
copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index');
|
|
85
|
+
amounts.forEach(i => {
|
|
86
|
+
copy.totals[i] = adjustAmount(copy.totals[i], lookup[i]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return copy;
|
|
90
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Address, OrderType, RevenueCenter, ServiceType } from '@open-tender/types';
|
|
2
|
-
export declare const makeOrderAddress: (address: Address | null) => string;
|
|
3
|
-
export declare const makeFullAddress: (address: Address) => string;
|
|
4
|
-
export declare const makeOrderTypeFromParam: (param: string) => (string | boolean)[] | null;
|
|
5
|
-
export declare const makeServiceTypeName: (serviceType: ServiceType, isCatering: boolean, isOutpost: boolean, outpostName: string) => string | undefined;
|
|
6
|
-
export declare const makeOrderTypeName: (orderType: OrderType, serviceType: ServiceType) => string | undefined;
|
|
7
|
-
export declare const makeNotAcceptingOrdersMsg: (serviceType: ServiceType) => string;
|
|
8
|
-
export declare const makeRevenueCenterMsg: (revenueCenter: RevenueCenter, serviceType: ServiceType, requestedAt: string, statusMessages: Record<string, string>) => {
|
|
9
|
-
message: any;
|
|
10
|
-
color: string;
|
|
11
|
-
};
|
|
1
|
+
import { Address, OrderType, RevenueCenter, ServiceType } from '@open-tender/types';
|
|
2
|
+
export declare const makeOrderAddress: (address: Address | null) => string;
|
|
3
|
+
export declare const makeFullAddress: (address: Address) => string;
|
|
4
|
+
export declare const makeOrderTypeFromParam: (param: string) => (string | boolean)[] | null;
|
|
5
|
+
export declare const makeServiceTypeName: (serviceType: ServiceType, isCatering: boolean, isOutpost: boolean, outpostName: string) => string | undefined;
|
|
6
|
+
export declare const makeOrderTypeName: (orderType: OrderType, serviceType: ServiceType) => string | undefined;
|
|
7
|
+
export declare const makeNotAcceptingOrdersMsg: (serviceType: ServiceType) => string;
|
|
8
|
+
export declare const makeRevenueCenterMsg: (revenueCenter: RevenueCenter, serviceType: ServiceType, requestedAt: string, statusMessages: Record<string, string>) => {
|
|
9
|
+
message: any;
|
|
10
|
+
color: string;
|
|
11
|
+
};
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { serviceTypeNamesMap } from './constants';
|
|
2
|
-
import { fmtDate, formatDateStr, isoToDate, makeOrderTimes, makeReadableDateStrFromIso, makeWeekday, time24ToDate, timezoneMap } from './datetimes';
|
|
3
|
-
import { capitalize } from './helpers';
|
|
4
|
-
export const makeOrderAddress = (address) => {
|
|
5
|
-
const { street, unit, city, state, postal_code } = address || {};
|
|
6
|
-
return street
|
|
7
|
-
? `${street}${unit ? `, ${unit}` : ''}`
|
|
8
|
-
: postal_code
|
|
9
|
-
? `${postal_code} ${city}, ${state}`
|
|
10
|
-
: 'No address provided';
|
|
11
|
-
};
|
|
12
|
-
export const makeFullAddress = (address) => {
|
|
13
|
-
const { street, city, state, postal_code } = address || {};
|
|
14
|
-
return `${street ? `${street}, ` : ''}${city}, ${state} ${postal_code}`;
|
|
15
|
-
};
|
|
16
|
-
export const makeOrderTypeFromParam = (param) => {
|
|
17
|
-
switch (param) {
|
|
18
|
-
case 'outpost':
|
|
19
|
-
return ['OLO', 'PICKUP', true];
|
|
20
|
-
case 'pickup':
|
|
21
|
-
return ['OLO', 'PICKUP'];
|
|
22
|
-
case 'delivery':
|
|
23
|
-
return ['OLO', 'DELIVERY'];
|
|
24
|
-
case 'catering':
|
|
25
|
-
return ['CATERING', 'DELIVERY'];
|
|
26
|
-
case 'merch':
|
|
27
|
-
return ['MERCH', 'DELIVERY'];
|
|
28
|
-
default:
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
export const makeServiceTypeName = (serviceType, isCatering, isOutpost, outpostName) => {
|
|
33
|
-
let serviceTypeName = serviceTypeNamesMap[serviceType];
|
|
34
|
-
if (isCatering) {
|
|
35
|
-
serviceTypeName = `Catering ${serviceTypeName}`;
|
|
36
|
-
}
|
|
37
|
-
else if (isOutpost) {
|
|
38
|
-
serviceTypeName = `${outpostName || 'Outpost'} ${serviceTypeName}`;
|
|
39
|
-
}
|
|
40
|
-
return serviceTypeName;
|
|
41
|
-
};
|
|
42
|
-
export const makeOrderTypeName = (orderType, serviceType) => {
|
|
43
|
-
return orderType === 'OLO'
|
|
44
|
-
? serviceTypeNamesMap[serviceType]
|
|
45
|
-
: capitalize(orderType);
|
|
46
|
-
};
|
|
47
|
-
const makeOrderMsg = (tz, serviceType, requestedAt, firstTime, orderTime, waitTime) => {
|
|
48
|
-
var _a, _b;
|
|
49
|
-
if (!firstTime && !orderTime)
|
|
50
|
-
return null;
|
|
51
|
-
let readableDate;
|
|
52
|
-
if (firstTime) {
|
|
53
|
-
const seconds = firstTime.utc ? isoToDate(firstTime.utc).getSeconds() : 0;
|
|
54
|
-
const estimate = requestedAt !== 'asap' && seconds ? 'at about' : 'at';
|
|
55
|
-
readableDate =
|
|
56
|
-
requestedAt === 'asap' && firstTime.has_asap
|
|
57
|
-
? `in about ${waitTime} minutes`
|
|
58
|
-
: makeReadableDateStrFromIso(firstTime.utc, tz, true)
|
|
59
|
-
.replace('Today', 'today')
|
|
60
|
-
.replace('Tomorrow', 'TOMORROW')
|
|
61
|
-
.replace('@', estimate);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
const orderTimes = makeOrderTimes([orderTime], tz);
|
|
65
|
-
const { start_time, end_time } = orderTimes[0];
|
|
66
|
-
const startTime = time24ToDate(start_time);
|
|
67
|
-
const startTimeStr = (_a = formatDateStr(startTime.toISOString(), 'h:mma')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
68
|
-
const endTime = time24ToDate(end_time);
|
|
69
|
-
const endTimeStr = (_b = formatDateStr(endTime.toISOString(), 'h:mma')) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
70
|
-
const todayWeekday = makeWeekday();
|
|
71
|
-
const weekday = orderTimes[0].weekday === todayWeekday
|
|
72
|
-
? ''
|
|
73
|
-
: `${capitalize(orderTimes[0].weekday)}, ${fmtDate(orderTimes[0].date, 'MMMM d')} @ `;
|
|
74
|
-
readableDate =
|
|
75
|
-
startTimeStr === endTimeStr
|
|
76
|
-
? `${weekday}${startTimeStr}`
|
|
77
|
-
: `${weekday}${startTimeStr} to ${endTimeStr}`;
|
|
78
|
-
}
|
|
79
|
-
const serviceTypeName = serviceTypeNamesMap[serviceType];
|
|
80
|
-
const orderMsg = `The first available ${serviceTypeName === null || serviceTypeName === void 0 ? void 0 : serviceTypeName.toLowerCase()} time is ${readableDate}`;
|
|
81
|
-
return orderMsg;
|
|
82
|
-
};
|
|
83
|
-
export const makeNotAcceptingOrdersMsg = (serviceType) => {
|
|
84
|
-
const serviceTypeName = serviceTypeNamesMap[serviceType];
|
|
85
|
-
if (!serviceTypeName) {
|
|
86
|
-
return 'This location is not currently accepting orders.';
|
|
87
|
-
}
|
|
88
|
-
return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders. Please try switching to a different order type.`;
|
|
89
|
-
};
|
|
90
|
-
export const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, statusMessages) => {
|
|
91
|
-
var _a;
|
|
92
|
-
const settings = revenueCenter;
|
|
93
|
-
const { first_times, order_times, wait_times } = settings;
|
|
94
|
-
const tz = timezoneMap[(_a = revenueCenter === null || revenueCenter === void 0 ? void 0 : revenueCenter.timezone) !== null && _a !== void 0 ? _a : 'US/Central'];
|
|
95
|
-
const st = serviceType === 'WALKIN' ? 'PICKUP' : serviceType;
|
|
96
|
-
const firstTime = first_times ? first_times[st] : null;
|
|
97
|
-
const orderTime = order_times ? order_times[st] : null;
|
|
98
|
-
const waitTime = wait_times ? wait_times[st] : null;
|
|
99
|
-
const tempClosed = revenueCenter.status === 'CLOSED_TEMPORARILY';
|
|
100
|
-
const statusMsg = !tempClosed
|
|
101
|
-
? statusMessages[revenueCenter.status]
|
|
102
|
-
: null;
|
|
103
|
-
const orderMsg = !statusMsg && (firstTime || (orderTime && orderTime.length))
|
|
104
|
-
? makeOrderMsg(tz, serviceType, requestedAt, firstTime, orderTime ? orderTime[0] : null, waitTime !== null && waitTime !== void 0 ? waitTime : 0)
|
|
105
|
-
: null;
|
|
106
|
-
let message = orderMsg ||
|
|
107
|
-
(statusMsg ? statusMsg.subtitle : makeNotAcceptingOrdersMsg(serviceType));
|
|
108
|
-
let color = orderMsg ? 'success' : 'alert';
|
|
109
|
-
if (tempClosed) {
|
|
110
|
-
color = 'alert';
|
|
111
|
-
message = message.charAt(0).toLowerCase() + message.substring(1);
|
|
112
|
-
message = `This location is temporarily closed for technical or operational reasons. Please try back later today, otherwise ${message} if you want to place an order now.`;
|
|
113
|
-
}
|
|
114
|
-
return { message, color };
|
|
115
|
-
};
|
|
1
|
+
import { serviceTypeNamesMap } from './constants';
|
|
2
|
+
import { fmtDate, formatDateStr, isoToDate, makeOrderTimes, makeReadableDateStrFromIso, makeWeekday, time24ToDate, timezoneMap } from './datetimes';
|
|
3
|
+
import { capitalize } from './helpers';
|
|
4
|
+
export const makeOrderAddress = (address) => {
|
|
5
|
+
const { street, unit, city, state, postal_code } = address || {};
|
|
6
|
+
return street
|
|
7
|
+
? `${street}${unit ? `, ${unit}` : ''}`
|
|
8
|
+
: postal_code
|
|
9
|
+
? `${postal_code} ${city}, ${state}`
|
|
10
|
+
: 'No address provided';
|
|
11
|
+
};
|
|
12
|
+
export const makeFullAddress = (address) => {
|
|
13
|
+
const { street, city, state, postal_code } = address || {};
|
|
14
|
+
return `${street ? `${street}, ` : ''}${city}, ${state} ${postal_code}`;
|
|
15
|
+
};
|
|
16
|
+
export const makeOrderTypeFromParam = (param) => {
|
|
17
|
+
switch (param) {
|
|
18
|
+
case 'outpost':
|
|
19
|
+
return ['OLO', 'PICKUP', true];
|
|
20
|
+
case 'pickup':
|
|
21
|
+
return ['OLO', 'PICKUP'];
|
|
22
|
+
case 'delivery':
|
|
23
|
+
return ['OLO', 'DELIVERY'];
|
|
24
|
+
case 'catering':
|
|
25
|
+
return ['CATERING', 'DELIVERY'];
|
|
26
|
+
case 'merch':
|
|
27
|
+
return ['MERCH', 'DELIVERY'];
|
|
28
|
+
default:
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const makeServiceTypeName = (serviceType, isCatering, isOutpost, outpostName) => {
|
|
33
|
+
let serviceTypeName = serviceTypeNamesMap[serviceType];
|
|
34
|
+
if (isCatering) {
|
|
35
|
+
serviceTypeName = `Catering ${serviceTypeName}`;
|
|
36
|
+
}
|
|
37
|
+
else if (isOutpost) {
|
|
38
|
+
serviceTypeName = `${outpostName || 'Outpost'} ${serviceTypeName}`;
|
|
39
|
+
}
|
|
40
|
+
return serviceTypeName;
|
|
41
|
+
};
|
|
42
|
+
export const makeOrderTypeName = (orderType, serviceType) => {
|
|
43
|
+
return orderType === 'OLO'
|
|
44
|
+
? serviceTypeNamesMap[serviceType]
|
|
45
|
+
: capitalize(orderType);
|
|
46
|
+
};
|
|
47
|
+
const makeOrderMsg = (tz, serviceType, requestedAt, firstTime, orderTime, waitTime) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (!firstTime && !orderTime)
|
|
50
|
+
return null;
|
|
51
|
+
let readableDate;
|
|
52
|
+
if (firstTime) {
|
|
53
|
+
const seconds = firstTime.utc ? isoToDate(firstTime.utc).getSeconds() : 0;
|
|
54
|
+
const estimate = requestedAt !== 'asap' && seconds ? 'at about' : 'at';
|
|
55
|
+
readableDate =
|
|
56
|
+
requestedAt === 'asap' && firstTime.has_asap
|
|
57
|
+
? `in about ${waitTime} minutes`
|
|
58
|
+
: makeReadableDateStrFromIso(firstTime.utc, tz, true)
|
|
59
|
+
.replace('Today', 'today')
|
|
60
|
+
.replace('Tomorrow', 'TOMORROW')
|
|
61
|
+
.replace('@', estimate);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const orderTimes = makeOrderTimes([orderTime], tz);
|
|
65
|
+
const { start_time, end_time } = orderTimes[0];
|
|
66
|
+
const startTime = time24ToDate(start_time);
|
|
67
|
+
const startTimeStr = (_a = formatDateStr(startTime.toISOString(), 'h:mma')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
68
|
+
const endTime = time24ToDate(end_time);
|
|
69
|
+
const endTimeStr = (_b = formatDateStr(endTime.toISOString(), 'h:mma')) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
70
|
+
const todayWeekday = makeWeekday();
|
|
71
|
+
const weekday = orderTimes[0].weekday === todayWeekday
|
|
72
|
+
? ''
|
|
73
|
+
: `${capitalize(orderTimes[0].weekday)}, ${fmtDate(orderTimes[0].date, 'MMMM d')} @ `;
|
|
74
|
+
readableDate =
|
|
75
|
+
startTimeStr === endTimeStr
|
|
76
|
+
? `${weekday}${startTimeStr}`
|
|
77
|
+
: `${weekday}${startTimeStr} to ${endTimeStr}`;
|
|
78
|
+
}
|
|
79
|
+
const serviceTypeName = serviceTypeNamesMap[serviceType];
|
|
80
|
+
const orderMsg = `The first available ${serviceTypeName === null || serviceTypeName === void 0 ? void 0 : serviceTypeName.toLowerCase()} time is ${readableDate}`;
|
|
81
|
+
return orderMsg;
|
|
82
|
+
};
|
|
83
|
+
export const makeNotAcceptingOrdersMsg = (serviceType) => {
|
|
84
|
+
const serviceTypeName = serviceTypeNamesMap[serviceType];
|
|
85
|
+
if (!serviceTypeName) {
|
|
86
|
+
return 'This location is not currently accepting orders.';
|
|
87
|
+
}
|
|
88
|
+
return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders. Please try switching to a different order type.`;
|
|
89
|
+
};
|
|
90
|
+
export const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, statusMessages) => {
|
|
91
|
+
var _a;
|
|
92
|
+
const settings = revenueCenter;
|
|
93
|
+
const { first_times, order_times, wait_times } = settings;
|
|
94
|
+
const tz = timezoneMap[(_a = revenueCenter === null || revenueCenter === void 0 ? void 0 : revenueCenter.timezone) !== null && _a !== void 0 ? _a : 'US/Central'];
|
|
95
|
+
const st = serviceType === 'WALKIN' ? 'PICKUP' : serviceType;
|
|
96
|
+
const firstTime = first_times ? first_times[st] : null;
|
|
97
|
+
const orderTime = order_times ? order_times[st] : null;
|
|
98
|
+
const waitTime = wait_times ? wait_times[st] : null;
|
|
99
|
+
const tempClosed = revenueCenter.status === 'CLOSED_TEMPORARILY';
|
|
100
|
+
const statusMsg = !tempClosed
|
|
101
|
+
? statusMessages[revenueCenter.status]
|
|
102
|
+
: null;
|
|
103
|
+
const orderMsg = !statusMsg && (firstTime || (orderTime && orderTime.length))
|
|
104
|
+
? makeOrderMsg(tz, serviceType, requestedAt, firstTime, orderTime ? orderTime[0] : null, waitTime !== null && waitTime !== void 0 ? waitTime : 0)
|
|
105
|
+
: null;
|
|
106
|
+
let message = orderMsg ||
|
|
107
|
+
(statusMsg ? statusMsg.subtitle : makeNotAcceptingOrdersMsg(serviceType));
|
|
108
|
+
let color = orderMsg ? 'success' : 'alert';
|
|
109
|
+
if (tempClosed) {
|
|
110
|
+
color = 'alert';
|
|
111
|
+
message = message.charAt(0).toLowerCase() + message.substring(1);
|
|
112
|
+
message = `This location is temporarily closed for technical or operational reasons. Please try back later today, otherwise ${message} if you want to place an order now.`;
|
|
113
|
+
}
|
|
114
|
+
return { message, color };
|
|
115
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
|
-
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
-
export declare const makeLimitations: (item: Discount) => string;
|
|
4
|
-
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
1
|
+
import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
|
+
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
+
export declare const makeLimitations: (item: Discount) => string;
|
|
4
|
+
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { formatDateStr, getMinutesfromDate, makeLocalDateStr, time24ToMinutes } from './datetimes';
|
|
2
|
-
import { makeImageMap } from './helpers';
|
|
3
|
-
export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
4
|
-
if (!deals || !deals.length)
|
|
5
|
-
return [];
|
|
6
|
-
if (orderType) {
|
|
7
|
-
deals = deals.filter(i => !i.order_type || i.order_type === orderType);
|
|
8
|
-
}
|
|
9
|
-
if (serviceType) {
|
|
10
|
-
deals = deals.filter(i => !i.service_type || i.service_type === serviceType);
|
|
11
|
-
}
|
|
12
|
-
if (revenueCenterId) {
|
|
13
|
-
deals = deals.filter(i => {
|
|
14
|
-
var _a;
|
|
15
|
-
return !((_a = i.revenue_centers) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
16
|
-
i.revenue_centers
|
|
17
|
-
.map(r => r.revenue_center_id)
|
|
18
|
-
.includes(revenueCenterId);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
const minutes = getMinutesfromDate(new Date());
|
|
22
|
-
deals = deals.filter(i => {
|
|
23
|
-
if (!i.dayparts.length)
|
|
24
|
-
return true;
|
|
25
|
-
const validDayparts = i.dayparts.filter(d => {
|
|
26
|
-
const start = time24ToMinutes(d.start_time);
|
|
27
|
-
const end = time24ToMinutes(d.end_time);
|
|
28
|
-
return start <= minutes && minutes <= end;
|
|
29
|
-
});
|
|
30
|
-
return validDayparts.length > 0;
|
|
31
|
-
});
|
|
32
|
-
return deals;
|
|
33
|
-
};
|
|
34
|
-
const makeDiscountServiceType = (serviceType) => {
|
|
35
|
-
switch (serviceType) {
|
|
36
|
-
case 'WALKIN':
|
|
37
|
-
return 'In-store only';
|
|
38
|
-
case 'PICKUP':
|
|
39
|
-
return 'Pickup only';
|
|
40
|
-
case 'DELIVERY':
|
|
41
|
-
return 'Delivery only';
|
|
42
|
-
default:
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const makeDiscountOrderType = (orderType) => {
|
|
47
|
-
switch (orderType) {
|
|
48
|
-
case 'OLO':
|
|
49
|
-
return '';
|
|
50
|
-
case 'CATERING':
|
|
51
|
-
return 'Catering only';
|
|
52
|
-
case 'MERCH':
|
|
53
|
-
return 'Merch only';
|
|
54
|
-
default:
|
|
55
|
-
return '';
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const makeChannelType = (channelType) => {
|
|
59
|
-
switch (channelType) {
|
|
60
|
-
case 'APP':
|
|
61
|
-
return 'App Only!';
|
|
62
|
-
case 'ONLINE':
|
|
63
|
-
return 'Online Only!';
|
|
64
|
-
case 'POS':
|
|
65
|
-
return 'At POS Only!';
|
|
66
|
-
case 'KIOSK':
|
|
67
|
-
return 'Kiosk Only!';
|
|
68
|
-
default:
|
|
69
|
-
return '';
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
export const makeLimitations = (item) => {
|
|
73
|
-
const { channel_type, order_type, service_type } = item;
|
|
74
|
-
const serviceType = makeDiscountServiceType(service_type);
|
|
75
|
-
const orderType = makeDiscountOrderType(order_type);
|
|
76
|
-
const channelType = channel_type && makeChannelType(channel_type);
|
|
77
|
-
const comma = serviceType && orderType ? ', ' : '';
|
|
78
|
-
const dash = (serviceType || orderType) && channelType ? ' - ' : '';
|
|
79
|
-
if (serviceType || orderType || channelType) {
|
|
80
|
-
return `
|
|
81
|
-
${serviceType || ''}
|
|
82
|
-
${comma}
|
|
83
|
-
${orderType || ''}
|
|
84
|
-
${dash}
|
|
85
|
-
${channelType || ''}
|
|
86
|
-
`;
|
|
87
|
-
}
|
|
88
|
-
return 'Valid on all online & app orders';
|
|
89
|
-
};
|
|
90
|
-
export const makeDiscountEnhanced = (item) => {
|
|
91
|
-
const today = makeLocalDateStr(new Date(), 0, 'yyyy-MM-dd');
|
|
92
|
-
const imageMap = makeImageMap(item.images);
|
|
93
|
-
const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
|
|
94
|
-
const todayOnly = item.end_date === today;
|
|
95
|
-
const expiration = item.end_date
|
|
96
|
-
? formatDateStr(item.end_date, 'MMM d')
|
|
97
|
-
: null;
|
|
98
|
-
const limitations = makeLimitations(item);
|
|
99
|
-
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
100
|
-
};
|
|
1
|
+
import { formatDateStr, getMinutesfromDate, makeLocalDateStr, time24ToMinutes } from './datetimes';
|
|
2
|
+
import { makeImageMap } from './helpers';
|
|
3
|
+
export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
4
|
+
if (!deals || !deals.length)
|
|
5
|
+
return [];
|
|
6
|
+
if (orderType) {
|
|
7
|
+
deals = deals.filter(i => !i.order_type || i.order_type === orderType);
|
|
8
|
+
}
|
|
9
|
+
if (serviceType) {
|
|
10
|
+
deals = deals.filter(i => !i.service_type || i.service_type === serviceType);
|
|
11
|
+
}
|
|
12
|
+
if (revenueCenterId) {
|
|
13
|
+
deals = deals.filter(i => {
|
|
14
|
+
var _a;
|
|
15
|
+
return !((_a = i.revenue_centers) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
16
|
+
i.revenue_centers
|
|
17
|
+
.map(r => r.revenue_center_id)
|
|
18
|
+
.includes(revenueCenterId);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const minutes = getMinutesfromDate(new Date());
|
|
22
|
+
deals = deals.filter(i => {
|
|
23
|
+
if (!i.dayparts.length)
|
|
24
|
+
return true;
|
|
25
|
+
const validDayparts = i.dayparts.filter(d => {
|
|
26
|
+
const start = time24ToMinutes(d.start_time);
|
|
27
|
+
const end = time24ToMinutes(d.end_time);
|
|
28
|
+
return start <= minutes && minutes <= end;
|
|
29
|
+
});
|
|
30
|
+
return validDayparts.length > 0;
|
|
31
|
+
});
|
|
32
|
+
return deals;
|
|
33
|
+
};
|
|
34
|
+
const makeDiscountServiceType = (serviceType) => {
|
|
35
|
+
switch (serviceType) {
|
|
36
|
+
case 'WALKIN':
|
|
37
|
+
return 'In-store only';
|
|
38
|
+
case 'PICKUP':
|
|
39
|
+
return 'Pickup only';
|
|
40
|
+
case 'DELIVERY':
|
|
41
|
+
return 'Delivery only';
|
|
42
|
+
default:
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const makeDiscountOrderType = (orderType) => {
|
|
47
|
+
switch (orderType) {
|
|
48
|
+
case 'OLO':
|
|
49
|
+
return '';
|
|
50
|
+
case 'CATERING':
|
|
51
|
+
return 'Catering only';
|
|
52
|
+
case 'MERCH':
|
|
53
|
+
return 'Merch only';
|
|
54
|
+
default:
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const makeChannelType = (channelType) => {
|
|
59
|
+
switch (channelType) {
|
|
60
|
+
case 'APP':
|
|
61
|
+
return 'App Only!';
|
|
62
|
+
case 'ONLINE':
|
|
63
|
+
return 'Online Only!';
|
|
64
|
+
case 'POS':
|
|
65
|
+
return 'At POS Only!';
|
|
66
|
+
case 'KIOSK':
|
|
67
|
+
return 'Kiosk Only!';
|
|
68
|
+
default:
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const makeLimitations = (item) => {
|
|
73
|
+
const { channel_type, order_type, service_type } = item;
|
|
74
|
+
const serviceType = makeDiscountServiceType(service_type);
|
|
75
|
+
const orderType = makeDiscountOrderType(order_type);
|
|
76
|
+
const channelType = channel_type && makeChannelType(channel_type);
|
|
77
|
+
const comma = serviceType && orderType ? ', ' : '';
|
|
78
|
+
const dash = (serviceType || orderType) && channelType ? ' - ' : '';
|
|
79
|
+
if (serviceType || orderType || channelType) {
|
|
80
|
+
return `
|
|
81
|
+
${serviceType || ''}
|
|
82
|
+
${comma}
|
|
83
|
+
${orderType || ''}
|
|
84
|
+
${dash}
|
|
85
|
+
${channelType || ''}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
return 'Valid on all online & app orders';
|
|
89
|
+
};
|
|
90
|
+
export const makeDiscountEnhanced = (item) => {
|
|
91
|
+
const today = makeLocalDateStr(new Date(), 0, 'yyyy-MM-dd');
|
|
92
|
+
const imageMap = makeImageMap(item.images);
|
|
93
|
+
const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
|
|
94
|
+
const todayOnly = item.end_date === today;
|
|
95
|
+
const expiration = item.end_date
|
|
96
|
+
? formatDateStr(item.end_date, 'MMM d')
|
|
97
|
+
: null;
|
|
98
|
+
const limitations = makeLimitations(item);
|
|
99
|
+
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
100
|
+
};
|