@open-tender/utils 0.4.31 → 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 -57
- package/dist/cjs/hooks/useMenuItem.js +67 -67
- package/dist/cjs/hooks/useModifier.d.ts +53 -53
- 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 -48
- 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 -202
- package/dist/cjs/utils/cart.js +909 -909
- 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 -117
- 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 -57
- package/dist/esm/hooks/useMenuItem.js +63 -63
- package/dist/esm/hooks/useModifier.d.ts +53 -53
- 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 -48
- 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 -202
- package/dist/esm/utils/cart.js +868 -868
- 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 -117
- 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,140 +1,140 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { calcPrices } from '../utils';
|
|
3
|
-
export const useBuilder = (orderItem) => {
|
|
4
|
-
const [item, setItem] = useState(orderItem);
|
|
5
|
-
const increment = () => {
|
|
6
|
-
const newQuantity = item.max
|
|
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
|
-
};
|
|
12
|
-
const decrement = () => {
|
|
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
|
-
};
|
|
17
|
-
const setQuantity = (quantity) => {
|
|
18
|
-
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity }));
|
|
19
|
-
setItem(pricedItem);
|
|
20
|
-
};
|
|
21
|
-
const setMadeFor = (madeFor) => {
|
|
22
|
-
setItem(Object.assign(Object.assign({}, item), { madeFor }));
|
|
23
|
-
};
|
|
24
|
-
const setNotes = (notes) => {
|
|
25
|
-
setItem(Object.assign(Object.assign({}, item), { notes }));
|
|
26
|
-
};
|
|
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 });
|
|
33
|
-
});
|
|
34
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
35
|
-
};
|
|
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)
|
|
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;
|
|
54
|
-
});
|
|
55
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
56
|
-
};
|
|
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 });
|
|
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)
|
|
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;
|
|
87
|
-
});
|
|
88
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
89
|
-
};
|
|
90
|
-
const updateGroups = (groups, levels, fn, quantity) => {
|
|
91
|
-
const [[groupId, optionId], ...rest] = levels;
|
|
92
|
-
return groups.map(group => {
|
|
93
|
-
if (group.id === groupId) {
|
|
94
|
-
if (!rest.length)
|
|
95
|
-
return fn(group, optionId, quantity);
|
|
96
|
-
const options = group.options.map(option => {
|
|
97
|
-
if (option.id === optionId) {
|
|
98
|
-
return Object.assign(Object.assign({}, option), { groups: updateGroups(option.groups, rest, fn) });
|
|
99
|
-
}
|
|
100
|
-
return option;
|
|
101
|
-
});
|
|
102
|
-
return Object.assign(Object.assign({}, group), { options });
|
|
103
|
-
}
|
|
104
|
-
return group;
|
|
105
|
-
});
|
|
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);
|
|
126
|
-
};
|
|
127
|
-
return {
|
|
128
|
-
item,
|
|
129
|
-
increment,
|
|
130
|
-
decrement,
|
|
131
|
-
setQuantity,
|
|
132
|
-
setMadeFor,
|
|
133
|
-
setNotes,
|
|
134
|
-
setMadeForNotes,
|
|
135
|
-
toggleOption,
|
|
136
|
-
incrementOption,
|
|
137
|
-
decrementOption,
|
|
138
|
-
setOptionQuantity
|
|
139
|
-
};
|
|
140
|
-
};
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { calcPrices } from '../utils';
|
|
3
|
+
export const useBuilder = (orderItem) => {
|
|
4
|
+
const [item, setItem] = useState(orderItem);
|
|
5
|
+
const increment = () => {
|
|
6
|
+
const newQuantity = item.max
|
|
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
|
+
};
|
|
12
|
+
const decrement = () => {
|
|
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
|
+
};
|
|
17
|
+
const setQuantity = (quantity) => {
|
|
18
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity }));
|
|
19
|
+
setItem(pricedItem);
|
|
20
|
+
};
|
|
21
|
+
const setMadeFor = (madeFor) => {
|
|
22
|
+
setItem(Object.assign(Object.assign({}, item), { madeFor }));
|
|
23
|
+
};
|
|
24
|
+
const setNotes = (notes) => {
|
|
25
|
+
setItem(Object.assign(Object.assign({}, item), { notes }));
|
|
26
|
+
};
|
|
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 });
|
|
33
|
+
});
|
|
34
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
35
|
+
};
|
|
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)
|
|
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;
|
|
54
|
+
});
|
|
55
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
56
|
+
};
|
|
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 });
|
|
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)
|
|
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;
|
|
87
|
+
});
|
|
88
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
89
|
+
};
|
|
90
|
+
const updateGroups = (groups, levels, fn, quantity) => {
|
|
91
|
+
const [[groupId, optionId], ...rest] = levels;
|
|
92
|
+
return groups.map(group => {
|
|
93
|
+
if (group.id === groupId) {
|
|
94
|
+
if (!rest.length)
|
|
95
|
+
return fn(group, optionId, quantity);
|
|
96
|
+
const options = group.options.map(option => {
|
|
97
|
+
if (option.id === optionId) {
|
|
98
|
+
return Object.assign(Object.assign({}, option), { groups: updateGroups(option.groups, rest, fn) });
|
|
99
|
+
}
|
|
100
|
+
return option;
|
|
101
|
+
});
|
|
102
|
+
return Object.assign(Object.assign({}, group), { options });
|
|
103
|
+
}
|
|
104
|
+
return group;
|
|
105
|
+
});
|
|
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);
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
item,
|
|
129
|
+
increment,
|
|
130
|
+
decrement,
|
|
131
|
+
setQuantity,
|
|
132
|
+
setMadeFor,
|
|
133
|
+
setNotes,
|
|
134
|
+
setMadeForNotes,
|
|
135
|
+
toggleOption,
|
|
136
|
+
incrementOption,
|
|
137
|
+
decrementOption,
|
|
138
|
+
setOptionQuantity
|
|
139
|
+
};
|
|
140
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FormFields, GroupOrderGuestCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCartGuestForm: (loading: RequestStatus, error: RequestError, cartId: number, joinCart: (data: GroupOrderGuestCreate, callback?: () => void) => void) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
data: GroupOrderGuestCreate;
|
|
7
|
-
errors: Record<string, string>;
|
|
8
|
-
submitting: boolean;
|
|
9
|
-
fields: FormFields;
|
|
10
|
-
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
12
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FormFields, GroupOrderGuestCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useCartGuestForm: (loading: RequestStatus, error: RequestError, cartId: number, joinCart: (data: GroupOrderGuestCreate, callback?: () => void) => void) => {
|
|
4
|
+
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
+
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
+
data: GroupOrderGuestCreate;
|
|
7
|
+
errors: Record<string, string>;
|
|
8
|
+
submitting: boolean;
|
|
9
|
+
fields: FormFields;
|
|
10
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
12
|
+
};
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { useRef, useState, useEffect } from 'react';
|
|
2
|
-
import { makeFormErrors } from '../utils';
|
|
3
|
-
const initState = {
|
|
4
|
-
first_name: '',
|
|
5
|
-
last_name: ''
|
|
6
|
-
};
|
|
7
|
-
export const useCartGuestForm = (loading, error, cartId, joinCart) => {
|
|
8
|
-
const submitRef = useRef(null);
|
|
9
|
-
const inputRef = useRef(null);
|
|
10
|
-
const [data, setData] = useState(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
11
|
-
const [submitting, setSubmitting] = useState(false);
|
|
12
|
-
const [errors, setErrors] = useState({});
|
|
13
|
-
const fields = [
|
|
14
|
-
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
15
|
-
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
16
|
-
];
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
return () => {
|
|
19
|
-
setData(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
20
|
-
setErrors({});
|
|
21
|
-
};
|
|
22
|
-
}, [cartId]);
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
if (loading === 'idle') {
|
|
26
|
-
setSubmitting(false);
|
|
27
|
-
if (error) {
|
|
28
|
-
setErrors(makeFormErrors(error));
|
|
29
|
-
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}, [loading, error]);
|
|
33
|
-
const handleChange = (name, value) => {
|
|
34
|
-
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
35
|
-
};
|
|
36
|
-
const handleSubmit = (evt) => {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
39
|
-
setErrors({});
|
|
40
|
-
setSubmitting(true);
|
|
41
|
-
joinCart(data);
|
|
42
|
-
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
submitRef,
|
|
46
|
-
inputRef,
|
|
47
|
-
data,
|
|
48
|
-
errors,
|
|
49
|
-
submitting,
|
|
50
|
-
fields,
|
|
51
|
-
handleChange,
|
|
52
|
-
handleSubmit
|
|
53
|
-
};
|
|
54
|
-
};
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
|
+
import { makeFormErrors } from '../utils';
|
|
3
|
+
const initState = {
|
|
4
|
+
first_name: '',
|
|
5
|
+
last_name: ''
|
|
6
|
+
};
|
|
7
|
+
export const useCartGuestForm = (loading, error, cartId, joinCart) => {
|
|
8
|
+
const submitRef = useRef(null);
|
|
9
|
+
const inputRef = useRef(null);
|
|
10
|
+
const [data, setData] = useState(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
11
|
+
const [submitting, setSubmitting] = useState(false);
|
|
12
|
+
const [errors, setErrors] = useState({});
|
|
13
|
+
const fields = [
|
|
14
|
+
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
15
|
+
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
16
|
+
];
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
return () => {
|
|
19
|
+
setData(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
20
|
+
setErrors({});
|
|
21
|
+
};
|
|
22
|
+
}, [cartId]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (loading === 'idle') {
|
|
26
|
+
setSubmitting(false);
|
|
27
|
+
if (error) {
|
|
28
|
+
setErrors(makeFormErrors(error));
|
|
29
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}, [loading, error]);
|
|
33
|
+
const handleChange = (name, value) => {
|
|
34
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
35
|
+
};
|
|
36
|
+
const handleSubmit = (evt) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
39
|
+
setErrors({});
|
|
40
|
+
setSubmitting(true);
|
|
41
|
+
joinCart(data);
|
|
42
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
submitRef,
|
|
46
|
+
inputRef,
|
|
47
|
+
data,
|
|
48
|
+
errors,
|
|
49
|
+
submitting,
|
|
50
|
+
fields,
|
|
51
|
+
handleChange,
|
|
52
|
+
handleSubmit
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Cart, CartItemWithPoints, CheckoutCheck, CheckoutForm, CheckoutPoints, OrderCreatePoints } from '@open-tender/types';
|
|
3
|
-
export declare const useCartPoints: (cart: Cart | null, check: CheckoutCheck | null, form: CheckoutForm, updatePoints: (points: OrderCreatePoints) => void) => {
|
|
4
|
-
cartDiff: number;
|
|
5
|
-
cartWithPoints: CartItemWithPoints[];
|
|
6
|
-
points: import("@open-tender/types").CheckoutConfigLoyalty | null | undefined;
|
|
7
|
-
pointsBalance: number;
|
|
8
|
-
pointsRemaining: number;
|
|
9
|
-
pointsApplied: number;
|
|
10
|
-
pointsName: string | null;
|
|
11
|
-
pointsObj: CheckoutPoints | null;
|
|
12
|
-
setCartLength: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
13
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Cart, CartItemWithPoints, CheckoutCheck, CheckoutForm, CheckoutPoints, OrderCreatePoints } from '@open-tender/types';
|
|
3
|
+
export declare const useCartPoints: (cart: Cart | null, check: CheckoutCheck | null, form: CheckoutForm, updatePoints: (points: OrderCreatePoints) => void) => {
|
|
4
|
+
cartDiff: number;
|
|
5
|
+
cartWithPoints: CartItemWithPoints[];
|
|
6
|
+
points: import("@open-tender/types").CheckoutConfigLoyalty | null | undefined;
|
|
7
|
+
pointsBalance: number;
|
|
8
|
+
pointsRemaining: number;
|
|
9
|
+
pointsApplied: number;
|
|
10
|
+
pointsName: string | null;
|
|
11
|
+
pointsObj: CheckoutPoints | null;
|
|
12
|
+
setCartLength: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
13
|
+
};
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
2
|
-
export const useCartPoints = (cart, check, form, updatePoints) => {
|
|
3
|
-
var _a;
|
|
4
|
-
const [cartLength, setCartLength] = useState((cart === null || cart === void 0 ? void 0 : cart.length) || 0);
|
|
5
|
-
const { points } = (check === null || check === void 0 ? void 0 : check.config) || {};
|
|
6
|
-
const pointsBalance = points ? parseInt(points.balance) : 0;
|
|
7
|
-
const pointsRemaining = points ? parseInt(points.remaining) : 0;
|
|
8
|
-
const { cart: items = [] } = check || {};
|
|
9
|
-
const itemsPoints = items.length
|
|
10
|
-
? items.reduce((obj, i, index) => {
|
|
11
|
-
if (!i.points)
|
|
12
|
-
return obj;
|
|
13
|
-
return Object.assign(Object.assign({}, obj), { [index]: Object.assign({ index }, i.points) });
|
|
14
|
-
}, {})
|
|
15
|
-
: null;
|
|
16
|
-
const hasPoints = points && itemsPoints;
|
|
17
|
-
const cartWithPoints = (cart === null || cart === void 0 ? void 0 : cart.map((i, index) => (Object.assign(Object.assign({}, i), { index, points: hasPoints ? itemsPoints[index.toString()] : null })))) || [];
|
|
18
|
-
const pointsApplied = useMemo(() => (form.points ? form.points.reduce((t, i) => (t += i.points), 0) : 0), [form.points]);
|
|
19
|
-
const cartDiff = ((_a = cart === null || cart === void 0 ? void 0 : cart.length) !== null && _a !== void 0 ? _a : 0) - (cartLength !== null && cartLength !== void 0 ? cartLength : 0);
|
|
20
|
-
const pointsName = points ? points.name.toLowerCase() : null;
|
|
21
|
-
const applyPoints = (item) => {
|
|
22
|
-
if (!item.points || item.index === undefined)
|
|
23
|
-
return;
|
|
24
|
-
const currentItem = form.points.find(i => i.index === item.index);
|
|
25
|
-
const currentPoints = currentItem ? currentItem.points : 0;
|
|
26
|
-
if (currentPoints >= item.points.total)
|
|
27
|
-
return;
|
|
28
|
-
const updatedItem = {
|
|
29
|
-
index: item.index,
|
|
30
|
-
points: currentPoints + item.points.per
|
|
31
|
-
};
|
|
32
|
-
const otherItems = form.points.filter(i => i.index !== item.index);
|
|
33
|
-
const updatedPoints = [...otherItems, updatedItem];
|
|
34
|
-
updatePoints(updatedPoints);
|
|
35
|
-
};
|
|
36
|
-
const removePoints = (item) => {
|
|
37
|
-
if (!item.points || item.index === undefined)
|
|
38
|
-
return;
|
|
39
|
-
const currentItem = form.points.find(i => i.index === item.index);
|
|
40
|
-
const currentPoints = currentItem ? currentItem.points : 0;
|
|
41
|
-
if (currentPoints === 0)
|
|
42
|
-
return;
|
|
43
|
-
const updatedItem = {
|
|
44
|
-
index: item.index,
|
|
45
|
-
points: currentPoints - item.points.per
|
|
46
|
-
};
|
|
47
|
-
const otherItems = form.points.filter(i => i.index !== item.index);
|
|
48
|
-
const updatedPoints = updatedItem.points > 0 ? [...otherItems, updatedItem] : otherItems;
|
|
49
|
-
updatePoints(updatedPoints);
|
|
50
|
-
};
|
|
51
|
-
const pointsObj = points
|
|
52
|
-
? {
|
|
53
|
-
points,
|
|
54
|
-
applied: form.points || [],
|
|
55
|
-
apply: applyPoints,
|
|
56
|
-
remove: removePoints
|
|
57
|
-
}
|
|
58
|
-
: null;
|
|
59
|
-
return {
|
|
60
|
-
cartDiff,
|
|
61
|
-
cartWithPoints,
|
|
62
|
-
points,
|
|
63
|
-
pointsBalance,
|
|
64
|
-
pointsRemaining,
|
|
65
|
-
pointsApplied,
|
|
66
|
-
pointsName,
|
|
67
|
-
pointsObj,
|
|
68
|
-
setCartLength
|
|
69
|
-
};
|
|
70
|
-
};
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
export const useCartPoints = (cart, check, form, updatePoints) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const [cartLength, setCartLength] = useState((cart === null || cart === void 0 ? void 0 : cart.length) || 0);
|
|
5
|
+
const { points } = (check === null || check === void 0 ? void 0 : check.config) || {};
|
|
6
|
+
const pointsBalance = points ? parseInt(points.balance) : 0;
|
|
7
|
+
const pointsRemaining = points ? parseInt(points.remaining) : 0;
|
|
8
|
+
const { cart: items = [] } = check || {};
|
|
9
|
+
const itemsPoints = items.length
|
|
10
|
+
? items.reduce((obj, i, index) => {
|
|
11
|
+
if (!i.points)
|
|
12
|
+
return obj;
|
|
13
|
+
return Object.assign(Object.assign({}, obj), { [index]: Object.assign({ index }, i.points) });
|
|
14
|
+
}, {})
|
|
15
|
+
: null;
|
|
16
|
+
const hasPoints = points && itemsPoints;
|
|
17
|
+
const cartWithPoints = (cart === null || cart === void 0 ? void 0 : cart.map((i, index) => (Object.assign(Object.assign({}, i), { index, points: hasPoints ? itemsPoints[index.toString()] : null })))) || [];
|
|
18
|
+
const pointsApplied = useMemo(() => (form.points ? form.points.reduce((t, i) => (t += i.points), 0) : 0), [form.points]);
|
|
19
|
+
const cartDiff = ((_a = cart === null || cart === void 0 ? void 0 : cart.length) !== null && _a !== void 0 ? _a : 0) - (cartLength !== null && cartLength !== void 0 ? cartLength : 0);
|
|
20
|
+
const pointsName = points ? points.name.toLowerCase() : null;
|
|
21
|
+
const applyPoints = (item) => {
|
|
22
|
+
if (!item.points || item.index === undefined)
|
|
23
|
+
return;
|
|
24
|
+
const currentItem = form.points.find(i => i.index === item.index);
|
|
25
|
+
const currentPoints = currentItem ? currentItem.points : 0;
|
|
26
|
+
if (currentPoints >= item.points.total)
|
|
27
|
+
return;
|
|
28
|
+
const updatedItem = {
|
|
29
|
+
index: item.index,
|
|
30
|
+
points: currentPoints + item.points.per
|
|
31
|
+
};
|
|
32
|
+
const otherItems = form.points.filter(i => i.index !== item.index);
|
|
33
|
+
const updatedPoints = [...otherItems, updatedItem];
|
|
34
|
+
updatePoints(updatedPoints);
|
|
35
|
+
};
|
|
36
|
+
const removePoints = (item) => {
|
|
37
|
+
if (!item.points || item.index === undefined)
|
|
38
|
+
return;
|
|
39
|
+
const currentItem = form.points.find(i => i.index === item.index);
|
|
40
|
+
const currentPoints = currentItem ? currentItem.points : 0;
|
|
41
|
+
if (currentPoints === 0)
|
|
42
|
+
return;
|
|
43
|
+
const updatedItem = {
|
|
44
|
+
index: item.index,
|
|
45
|
+
points: currentPoints - item.points.per
|
|
46
|
+
};
|
|
47
|
+
const otherItems = form.points.filter(i => i.index !== item.index);
|
|
48
|
+
const updatedPoints = updatedItem.points > 0 ? [...otherItems, updatedItem] : otherItems;
|
|
49
|
+
updatePoints(updatedPoints);
|
|
50
|
+
};
|
|
51
|
+
const pointsObj = points
|
|
52
|
+
? {
|
|
53
|
+
points,
|
|
54
|
+
applied: form.points || [],
|
|
55
|
+
apply: applyPoints,
|
|
56
|
+
remove: removePoints
|
|
57
|
+
}
|
|
58
|
+
: null;
|
|
59
|
+
return {
|
|
60
|
+
cartDiff,
|
|
61
|
+
cartWithPoints,
|
|
62
|
+
points,
|
|
63
|
+
pointsBalance,
|
|
64
|
+
pointsRemaining,
|
|
65
|
+
pointsApplied,
|
|
66
|
+
pointsName,
|
|
67
|
+
pointsObj,
|
|
68
|
+
setCartLength
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { CreditCardData, CreditCardErrors } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCard: (initState: CreditCardData | null, cardErrors?: CreditCardErrors, disabled?: boolean, includeAddress?: boolean) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<null>;
|
|
5
|
-
data: CreditCardData;
|
|
6
|
-
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
7
|
-
errors: CreditCardErrors;
|
|
8
|
-
disabled: boolean;
|
|
9
|
-
setErrors: import("react").Dispatch<import("react").SetStateAction<CreditCardErrors>>;
|
|
10
|
-
handleChange: (name: keyof CreditCardData, value: string | boolean) => void;
|
|
11
|
-
handleBlur: (name: keyof CreditCardErrors) => void;
|
|
12
|
-
isComplete: boolean;
|
|
13
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CreditCardData, CreditCardErrors } from '@open-tender/types';
|
|
3
|
+
export declare const useCreditCard: (initState: CreditCardData | null, cardErrors?: CreditCardErrors, disabled?: boolean, includeAddress?: boolean) => {
|
|
4
|
+
submitRef: import("react").MutableRefObject<null>;
|
|
5
|
+
data: CreditCardData;
|
|
6
|
+
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
7
|
+
errors: CreditCardErrors;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
setErrors: import("react").Dispatch<import("react").SetStateAction<CreditCardErrors>>;
|
|
10
|
+
handleChange: (name: keyof CreditCardData, value: string | boolean) => void;
|
|
11
|
+
handleBlur: (name: keyof CreditCardErrors) => void;
|
|
12
|
+
isComplete: boolean;
|
|
13
|
+
};
|