@open-tender/utils 0.4.35 → 0.4.36
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/.DS_Store +0 -0
- 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 -157
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/cjs/hooks/useSignUpGuestForm.js +113 -124
- 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 +100 -100
- 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 -153
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/esm/hooks/useSignUpGuestForm.js +109 -120
- 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 +94 -94
- 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 -69
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAccordion = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
7
|
-
var _a;
|
|
8
|
-
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true } = config || {};
|
|
9
|
-
const [open, setOpen] = (0, react_1.useState)(null);
|
|
10
|
-
const { groups, ingredients, totalCals, madeFor, notes } = builtItem;
|
|
11
|
-
const hasMadeFor = showMadeFor && !cartId ? true : false;
|
|
12
|
-
const hasNotes = showNotes ? true : false;
|
|
13
|
-
const hasInstructions = hasMadeFor || hasNotes;
|
|
14
|
-
const hasCals = showCals && totalCals ? true : false;
|
|
15
|
-
const nutritionalInfo = hasCals ? (0, utils_1.calcNutritionalInfo)(builtItem) : null;
|
|
16
|
-
const hasIngredients = ingredients && ingredients.length > 0 ? true : false;
|
|
17
|
-
const instructionsTitle = hasMadeFor && hasNotes
|
|
18
|
-
? 'Name / Special Instructions'
|
|
19
|
-
: hasMadeFor
|
|
20
|
-
? 'Name'
|
|
21
|
-
: hasNotes
|
|
22
|
-
? 'Special Instructions'
|
|
23
|
-
: '';
|
|
24
|
-
const sizeGroup = groups ? groups.find(i => i.isSize) : null;
|
|
25
|
-
const selectedSize = sizeGroup
|
|
26
|
-
? (_a = sizeGroup === null || sizeGroup === void 0 ? void 0 : sizeGroup.options) === null || _a === void 0 ? void 0 : _a.find(i => { var _a; return ((_a = i.quantity) !== null && _a !== void 0 ? _a : 0) >= 1; })
|
|
27
|
-
: null;
|
|
28
|
-
const showAccordion = sizeGroup || hasCustomize || hasInstructions || hasIngredients || hasCals;
|
|
29
|
-
const toggleSize = (optionId) => {
|
|
30
|
-
if (sizeGroup) {
|
|
31
|
-
toggleOption([[sizeGroup.id, optionId]]);
|
|
32
|
-
setOpen(null);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
open,
|
|
37
|
-
setOpen,
|
|
38
|
-
groups,
|
|
39
|
-
ingredients,
|
|
40
|
-
totalCals,
|
|
41
|
-
madeFor,
|
|
42
|
-
notes,
|
|
43
|
-
hasMadeFor,
|
|
44
|
-
hasNotes,
|
|
45
|
-
hasInstructions,
|
|
46
|
-
hasCals,
|
|
47
|
-
nutritionalInfo,
|
|
48
|
-
hasIngredients,
|
|
49
|
-
instructionsTitle,
|
|
50
|
-
sizeGroup,
|
|
51
|
-
selectedSize,
|
|
52
|
-
showAccordion,
|
|
53
|
-
toggleSize
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.useAccordion = useAccordion;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAccordion = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true } = config || {};
|
|
9
|
+
const [open, setOpen] = (0, react_1.useState)(null);
|
|
10
|
+
const { groups, ingredients, totalCals, madeFor, notes } = builtItem;
|
|
11
|
+
const hasMadeFor = showMadeFor && !cartId ? true : false;
|
|
12
|
+
const hasNotes = showNotes ? true : false;
|
|
13
|
+
const hasInstructions = hasMadeFor || hasNotes;
|
|
14
|
+
const hasCals = showCals && totalCals ? true : false;
|
|
15
|
+
const nutritionalInfo = hasCals ? (0, utils_1.calcNutritionalInfo)(builtItem) : null;
|
|
16
|
+
const hasIngredients = ingredients && ingredients.length > 0 ? true : false;
|
|
17
|
+
const instructionsTitle = hasMadeFor && hasNotes
|
|
18
|
+
? 'Name / Special Instructions'
|
|
19
|
+
: hasMadeFor
|
|
20
|
+
? 'Name'
|
|
21
|
+
: hasNotes
|
|
22
|
+
? 'Special Instructions'
|
|
23
|
+
: '';
|
|
24
|
+
const sizeGroup = groups ? groups.find(i => i.isSize) : null;
|
|
25
|
+
const selectedSize = sizeGroup
|
|
26
|
+
? (_a = sizeGroup === null || sizeGroup === void 0 ? void 0 : sizeGroup.options) === null || _a === void 0 ? void 0 : _a.find(i => { var _a; return ((_a = i.quantity) !== null && _a !== void 0 ? _a : 0) >= 1; })
|
|
27
|
+
: null;
|
|
28
|
+
const showAccordion = sizeGroup || hasCustomize || hasInstructions || hasIngredients || hasCals;
|
|
29
|
+
const toggleSize = (optionId) => {
|
|
30
|
+
if (sizeGroup) {
|
|
31
|
+
toggleOption([[sizeGroup.id, optionId]]);
|
|
32
|
+
setOpen(null);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
open,
|
|
37
|
+
setOpen,
|
|
38
|
+
groups,
|
|
39
|
+
ingredients,
|
|
40
|
+
totalCals,
|
|
41
|
+
madeFor,
|
|
42
|
+
notes,
|
|
43
|
+
hasMadeFor,
|
|
44
|
+
hasNotes,
|
|
45
|
+
hasInstructions,
|
|
46
|
+
hasCals,
|
|
47
|
+
nutritionalInfo,
|
|
48
|
+
hasIngredients,
|
|
49
|
+
instructionsTitle,
|
|
50
|
+
sizeGroup,
|
|
51
|
+
selectedSize,
|
|
52
|
+
showAccordion,
|
|
53
|
+
toggleSize
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.useAccordion = useAccordion;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Address, FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useAddressForm: (address: Address, loading: RequestStatus, error: RequestError, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
|
|
4
|
-
fields: FormFields;
|
|
5
|
-
data: Address;
|
|
6
|
-
errors: Record<string, string>;
|
|
7
|
-
submitting: boolean;
|
|
8
|
-
handleChange: (name: string, value: string | number | boolean) => void;
|
|
9
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
10
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
|
-
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
12
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Address, FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useAddressForm: (address: Address, loading: RequestStatus, error: RequestError, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
|
|
4
|
+
fields: FormFields;
|
|
5
|
+
data: Address;
|
|
6
|
+
errors: Record<string, string>;
|
|
7
|
+
submitting: boolean;
|
|
8
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
9
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
10
|
+
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
|
+
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
12
|
+
};
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAddressForm = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const useAddressForm = (address, loading, error, update, callback) => {
|
|
7
|
-
const submitRef = (0, react_1.useRef)(null);
|
|
8
|
-
const inputRef = (0, react_1.useRef)(null);
|
|
9
|
-
const [data, setData] = (0, react_1.useState)(address);
|
|
10
|
-
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
|
-
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
-
const fields = [
|
|
13
|
-
{
|
|
14
|
-
label: 'Company',
|
|
15
|
-
name: 'company',
|
|
16
|
-
type: 'text'
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
label: 'Contact Person',
|
|
20
|
-
name: 'contact',
|
|
21
|
-
type: 'text'
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
label: 'Contact Phone',
|
|
25
|
-
name: 'phone',
|
|
26
|
-
type: 'tel'
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
label: 'Description',
|
|
30
|
-
name: 'description',
|
|
31
|
-
type: 'text'
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
label: 'Notes',
|
|
35
|
-
name: 'notes',
|
|
36
|
-
type: 'text'
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
label: 'Is Default',
|
|
40
|
-
name: 'is_default',
|
|
41
|
-
type: 'checkbox'
|
|
42
|
-
}
|
|
43
|
-
];
|
|
44
|
-
(0, react_1.useEffect)(() => {
|
|
45
|
-
var _a, _b;
|
|
46
|
-
if (loading === 'idle') {
|
|
47
|
-
setSubmitting(false);
|
|
48
|
-
if (error) {
|
|
49
|
-
setErrors((0, utils_1.makeFormErrors)(error));
|
|
50
|
-
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, [loading, error]);
|
|
54
|
-
const handleChange = (name, value) => {
|
|
55
|
-
const inputValue = name === 'phone' ? (0, utils_1.makePhone)((value !== null && value !== void 0 ? value : '')) : value;
|
|
56
|
-
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
57
|
-
};
|
|
58
|
-
const handleSubmit = (evt) => {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
61
|
-
setSubmitting(true);
|
|
62
|
-
const updatedData = Object.assign({}, data);
|
|
63
|
-
delete updatedData.customer_address_id;
|
|
64
|
-
delete updatedData.created_at;
|
|
65
|
-
delete updatedData.last_used_at;
|
|
66
|
-
const addressId = data.customer_address_id;
|
|
67
|
-
if (addressId) {
|
|
68
|
-
update(addressId, updatedData, callback);
|
|
69
|
-
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return {
|
|
73
|
-
fields,
|
|
74
|
-
data,
|
|
75
|
-
errors,
|
|
76
|
-
submitting,
|
|
77
|
-
handleChange,
|
|
78
|
-
handleSubmit,
|
|
79
|
-
submitRef,
|
|
80
|
-
inputRef
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
exports.useAddressForm = useAddressForm;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAddressForm = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const useAddressForm = (address, loading, error, update, callback) => {
|
|
7
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
8
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
9
|
+
const [data, setData] = (0, react_1.useState)(address);
|
|
10
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
+
const fields = [
|
|
13
|
+
{
|
|
14
|
+
label: 'Company',
|
|
15
|
+
name: 'company',
|
|
16
|
+
type: 'text'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: 'Contact Person',
|
|
20
|
+
name: 'contact',
|
|
21
|
+
type: 'text'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'Contact Phone',
|
|
25
|
+
name: 'phone',
|
|
26
|
+
type: 'tel'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'Description',
|
|
30
|
+
name: 'description',
|
|
31
|
+
type: 'text'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
label: 'Notes',
|
|
35
|
+
name: 'notes',
|
|
36
|
+
type: 'text'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: 'Is Default',
|
|
40
|
+
name: 'is_default',
|
|
41
|
+
type: 'checkbox'
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
(0, react_1.useEffect)(() => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (loading === 'idle') {
|
|
47
|
+
setSubmitting(false);
|
|
48
|
+
if (error) {
|
|
49
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
50
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [loading, error]);
|
|
54
|
+
const handleChange = (name, value) => {
|
|
55
|
+
const inputValue = name === 'phone' ? (0, utils_1.makePhone)((value !== null && value !== void 0 ? value : '')) : value;
|
|
56
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
57
|
+
};
|
|
58
|
+
const handleSubmit = (evt) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
61
|
+
setSubmitting(true);
|
|
62
|
+
const updatedData = Object.assign({}, data);
|
|
63
|
+
delete updatedData.customer_address_id;
|
|
64
|
+
delete updatedData.created_at;
|
|
65
|
+
delete updatedData.last_used_at;
|
|
66
|
+
const addressId = data.customer_address_id;
|
|
67
|
+
if (addressId) {
|
|
68
|
+
update(addressId, updatedData, callback);
|
|
69
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
fields,
|
|
74
|
+
data,
|
|
75
|
+
errors,
|
|
76
|
+
submitting,
|
|
77
|
+
handleChange,
|
|
78
|
+
handleSubmit,
|
|
79
|
+
submitRef,
|
|
80
|
+
inputRef
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.useAddressForm = useAddressForm;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Allergens, CustomerAllergens, RequestError } from '@open-tender/types';
|
|
3
|
-
export declare const useAllergenForm: (allergens: Allergens, selectedAllergens: Allergens, isLoading: boolean | undefined, error: RequestError, setAllergens: (allergens: Allergens) => void, updateAllergens?: ((allergen: CustomerAllergens) => void) | null | undefined, callback?: () => void) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
submitting: boolean;
|
|
6
|
-
allergenIds: number[];
|
|
7
|
-
errors: Record<string, string>;
|
|
8
|
-
handleChange: (allergenId: number, checked: boolean) => void;
|
|
9
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
10
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Allergens, CustomerAllergens, RequestError } from '@open-tender/types';
|
|
3
|
+
export declare const useAllergenForm: (allergens: Allergens, selectedAllergens: Allergens, isLoading: boolean | undefined, error: RequestError, setAllergens: (allergens: Allergens) => void, updateAllergens?: ((allergen: CustomerAllergens) => void) | null | undefined, callback?: () => void) => {
|
|
4
|
+
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
+
submitting: boolean;
|
|
6
|
+
allergenIds: number[];
|
|
7
|
+
errors: Record<string, string>;
|
|
8
|
+
handleChange: (allergenId: number, checked: boolean) => void;
|
|
9
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
10
|
+
};
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useAllergenForm = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const useAllergenForm = (allergens, selectedAllergens, isLoading = false, error, setAllergens, updateAllergens, callback) => {
|
|
7
|
-
const submitRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [data, setData] = (0, react_1.useState)([]);
|
|
9
|
-
const [errors, setErrors] = (0, react_1.useState)({});
|
|
10
|
-
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
11
|
-
const allergenIds = data.map(i => i.allergen_id);
|
|
12
|
-
// const formError = error ? error.detail || error.message : null
|
|
13
|
-
(0, react_1.useEffect)(() => {
|
|
14
|
-
// uses isLoading boolean because loading state is based on
|
|
15
|
-
// both brand allergens and customer allergens loading
|
|
16
|
-
if (!isLoading) {
|
|
17
|
-
setSubmitting(false);
|
|
18
|
-
if (error) {
|
|
19
|
-
setErrors((0, utils_1.makeFormErrors)(error));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}, [isLoading, error]);
|
|
23
|
-
(0, react_1.useEffect)(() => {
|
|
24
|
-
if (!isLoading)
|
|
25
|
-
setData(selectedAllergens);
|
|
26
|
-
}, [isLoading, selectedAllergens]);
|
|
27
|
-
const handleChange = (allergenId, checked) => {
|
|
28
|
-
const allergen = allergens.find(i => i.allergen_id === allergenId);
|
|
29
|
-
if (!allergen)
|
|
30
|
-
return;
|
|
31
|
-
const newData = checked
|
|
32
|
-
? [...data, allergen]
|
|
33
|
-
: data.filter(i => i.allergen_id !== allergenId);
|
|
34
|
-
setData(newData);
|
|
35
|
-
};
|
|
36
|
-
const handleSubmit = (evt) => {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
39
|
-
setSubmitting(updateAllergens !== null);
|
|
40
|
-
setAllergens(data);
|
|
41
|
-
if (updateAllergens) {
|
|
42
|
-
const newData = data.map(i => ({ allergen_id: i.allergen_id }));
|
|
43
|
-
updateAllergens(newData);
|
|
44
|
-
}
|
|
45
|
-
if (callback)
|
|
46
|
-
callback();
|
|
47
|
-
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
submitRef,
|
|
51
|
-
submitting,
|
|
52
|
-
allergenIds,
|
|
53
|
-
errors,
|
|
54
|
-
handleChange,
|
|
55
|
-
handleSubmit
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
exports.useAllergenForm = useAllergenForm;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAllergenForm = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const useAllergenForm = (allergens, selectedAllergens, isLoading = false, error, setAllergens, updateAllergens, callback) => {
|
|
7
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
8
|
+
const [data, setData] = (0, react_1.useState)([]);
|
|
9
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
10
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
11
|
+
const allergenIds = data.map(i => i.allergen_id);
|
|
12
|
+
// const formError = error ? error.detail || error.message : null
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
// uses isLoading boolean because loading state is based on
|
|
15
|
+
// both brand allergens and customer allergens loading
|
|
16
|
+
if (!isLoading) {
|
|
17
|
+
setSubmitting(false);
|
|
18
|
+
if (error) {
|
|
19
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, [isLoading, error]);
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
if (!isLoading)
|
|
25
|
+
setData(selectedAllergens);
|
|
26
|
+
}, [isLoading, selectedAllergens]);
|
|
27
|
+
const handleChange = (allergenId, checked) => {
|
|
28
|
+
const allergen = allergens.find(i => i.allergen_id === allergenId);
|
|
29
|
+
if (!allergen)
|
|
30
|
+
return;
|
|
31
|
+
const newData = checked
|
|
32
|
+
? [...data, allergen]
|
|
33
|
+
: data.filter(i => i.allergen_id !== allergenId);
|
|
34
|
+
setData(newData);
|
|
35
|
+
};
|
|
36
|
+
const handleSubmit = (evt) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
39
|
+
setSubmitting(updateAllergens !== null);
|
|
40
|
+
setAllergens(data);
|
|
41
|
+
if (updateAllergens) {
|
|
42
|
+
const newData = data.map(i => ({ allergen_id: i.allergen_id }));
|
|
43
|
+
updateAllergens(newData);
|
|
44
|
+
}
|
|
45
|
+
if (callback)
|
|
46
|
+
callback();
|
|
47
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
submitRef,
|
|
51
|
+
submitting,
|
|
52
|
+
allergenIds,
|
|
53
|
+
errors,
|
|
54
|
+
handleChange,
|
|
55
|
+
handleSubmit
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.useAllergenForm = useAllergenForm;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CartItem, CartLevels } from '@open-tender/types';
|
|
2
|
-
export declare const useBuilder: (orderItem: CartItem) => {
|
|
3
|
-
item: CartItem;
|
|
4
|
-
increment: () => void;
|
|
5
|
-
decrement: () => void;
|
|
6
|
-
setQuantity: (quantity: number) => void;
|
|
7
|
-
setMadeFor: (madeFor: string) => void;
|
|
8
|
-
setNotes: (notes: string) => void;
|
|
9
|
-
setMadeForNotes: (madeFor: string, notes: string) => void;
|
|
10
|
-
toggleOption: (levels: CartLevels) => void;
|
|
11
|
-
incrementOption: (levels: CartLevels) => void;
|
|
12
|
-
decrementOption: (levels: CartLevels) => void;
|
|
13
|
-
setOptionQuantity: (levels: CartLevels, quantity: number) => void;
|
|
14
|
-
};
|
|
1
|
+
import { CartItem, CartLevels } from '@open-tender/types';
|
|
2
|
+
export declare const useBuilder: (orderItem: CartItem) => {
|
|
3
|
+
item: CartItem;
|
|
4
|
+
increment: () => void;
|
|
5
|
+
decrement: () => void;
|
|
6
|
+
setQuantity: (quantity: number) => void;
|
|
7
|
+
setMadeFor: (madeFor: string) => void;
|
|
8
|
+
setNotes: (notes: string) => void;
|
|
9
|
+
setMadeForNotes: (madeFor: string, notes: string) => void;
|
|
10
|
+
toggleOption: (levels: CartLevels) => void;
|
|
11
|
+
incrementOption: (levels: CartLevels) => void;
|
|
12
|
+
decrementOption: (levels: CartLevels) => void;
|
|
13
|
+
setOptionQuantity: (levels: CartLevels, quantity: number) => void;
|
|
14
|
+
};
|