@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,48 +1,48 @@
|
|
|
1
|
-
import { CartCounts, CartItem, ThemeMenuItemsContentDescription, MenuItemFavorite } from '@open-tender/types';
|
|
2
|
-
export declare const useOrderItem: (orderItem: CartItem, favorite?: MenuItemFavorite | null, allergenAlerts?: string[], cartCounts?: CartCounts, showCals?: boolean, showTags?: boolean, showAllergens?: boolean, showDesc?: ThemeMenuItemsContentDescription) => {
|
|
3
|
-
displayDesc: string | null;
|
|
4
|
-
displayTags: string[];
|
|
5
|
-
displayAllergens: string[];
|
|
6
|
-
displayPrice: string;
|
|
7
|
-
displayCals: string | null;
|
|
8
|
-
isIncomplete: boolean;
|
|
9
|
-
isSoldOut: boolean;
|
|
10
|
-
allergenAlert: string | null;
|
|
11
|
-
hasSelections: boolean;
|
|
12
|
-
sizeOnly: boolean | undefined;
|
|
13
|
-
cartCount: number;
|
|
14
|
-
cartGuestId: number | null;
|
|
15
|
-
customerId: number | null;
|
|
16
|
-
index?: number | undefined;
|
|
17
|
-
madeFor: string | null;
|
|
18
|
-
notes: string | null;
|
|
19
|
-
signature?: string | undefined;
|
|
20
|
-
similarItems: number[];
|
|
21
|
-
upsellItems: number[];
|
|
22
|
-
allergens: string[];
|
|
23
|
-
allergens_list?: import("@open-tender/types").MenuItemAllergens | undefined;
|
|
24
|
-
cals: number | null;
|
|
25
|
-
description: string | null;
|
|
26
|
-
groups: import("@open-tender/types").CartItemGroups;
|
|
27
|
-
id: number;
|
|
28
|
-
imageUrl: string | null;
|
|
29
|
-
increment: number;
|
|
30
|
-
ingredients: string | null;
|
|
31
|
-
max: number;
|
|
32
|
-
min: number;
|
|
33
|
-
name: string;
|
|
34
|
-
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
35
|
-
points: number | null;
|
|
36
|
-
price: number;
|
|
37
|
-
quantity: number;
|
|
38
|
-
shorthand: string | null;
|
|
39
|
-
shortDescription: string | null;
|
|
40
|
-
shortName: string;
|
|
41
|
-
slug: string;
|
|
42
|
-
tags: string[];
|
|
43
|
-
tags_list?: import("@open-tender/types").MenuItemTags | undefined;
|
|
44
|
-
totalAllergens: string[];
|
|
45
|
-
totalCals: number | null;
|
|
46
|
-
totalPoints: number | null;
|
|
47
|
-
totalPrice: number | null;
|
|
48
|
-
};
|
|
1
|
+
import { CartCounts, CartItem, ThemeMenuItemsContentDescription, MenuItemFavorite } from '@open-tender/types';
|
|
2
|
+
export declare const useOrderItem: (orderItem: CartItem, favorite?: MenuItemFavorite | null, allergenAlerts?: string[], cartCounts?: CartCounts, showCals?: boolean, showTags?: boolean, showAllergens?: boolean, showDesc?: ThemeMenuItemsContentDescription) => {
|
|
3
|
+
displayDesc: string | null;
|
|
4
|
+
displayTags: string[];
|
|
5
|
+
displayAllergens: string[];
|
|
6
|
+
displayPrice: string;
|
|
7
|
+
displayCals: string | null;
|
|
8
|
+
isIncomplete: boolean;
|
|
9
|
+
isSoldOut: boolean;
|
|
10
|
+
allergenAlert: string | null;
|
|
11
|
+
hasSelections: boolean;
|
|
12
|
+
sizeOnly: boolean | undefined;
|
|
13
|
+
cartCount: number;
|
|
14
|
+
cartGuestId: number | null;
|
|
15
|
+
customerId: number | null;
|
|
16
|
+
index?: number | undefined;
|
|
17
|
+
madeFor: string | null;
|
|
18
|
+
notes: string | null;
|
|
19
|
+
signature?: string | undefined;
|
|
20
|
+
similarItems: number[];
|
|
21
|
+
upsellItems: number[];
|
|
22
|
+
allergens: string[];
|
|
23
|
+
allergens_list?: import("@open-tender/types").MenuItemAllergens | undefined;
|
|
24
|
+
cals: number | null;
|
|
25
|
+
description: string | null;
|
|
26
|
+
groups: import("@open-tender/types").CartItemGroups;
|
|
27
|
+
id: number;
|
|
28
|
+
imageUrl: string | null;
|
|
29
|
+
increment: number;
|
|
30
|
+
ingredients: string | null;
|
|
31
|
+
max: number;
|
|
32
|
+
min: number;
|
|
33
|
+
name: string;
|
|
34
|
+
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
35
|
+
points: number | null;
|
|
36
|
+
price: number;
|
|
37
|
+
quantity: number;
|
|
38
|
+
shorthand: string | null;
|
|
39
|
+
shortDescription: string | null;
|
|
40
|
+
shortName: string;
|
|
41
|
+
slug: string;
|
|
42
|
+
tags: string[];
|
|
43
|
+
tags_list?: import("@open-tender/types").MenuItemTags | undefined;
|
|
44
|
+
totalAllergens: string[];
|
|
45
|
+
totalCals: number | null;
|
|
46
|
+
totalPoints: number | null;
|
|
47
|
+
totalPrice: number | null;
|
|
48
|
+
};
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { formatDollars, getItemOptions, hasGroupsBelowMin } from '../utils';
|
|
2
|
-
export const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], cartCounts = {}, showCals = false, showTags = false, showAllergens = false, showDesc = 'SHOW') => {
|
|
3
|
-
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, isSoldOut } = orderItem;
|
|
4
|
-
const cartCount = cartCounts[orderItem.id] || 0;
|
|
5
|
-
const displayTags = showTags && tags.length ? tags : [];
|
|
6
|
-
const displayAllergens = showAllergens && allergens.length ? allergens : [];
|
|
7
|
-
const contains = allergens.filter(allergen => allergenAlerts.includes(allergen));
|
|
8
|
-
const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
|
|
9
|
-
const sizeGroup = groups.find(i => i.isSize);
|
|
10
|
-
const sizeOnly = sizeGroup && groups.length === 1;
|
|
11
|
-
const defaultOption = !sizeGroup
|
|
12
|
-
? null
|
|
13
|
-
: sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
|
|
14
|
-
const currentPrice = totalPrice
|
|
15
|
-
? totalPrice
|
|
16
|
-
: defaultOption
|
|
17
|
-
? defaultOption.price
|
|
18
|
-
: price;
|
|
19
|
-
const displayPrice = formatDollars(currentPrice.toString());
|
|
20
|
-
const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
|
|
21
|
-
const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
|
|
22
|
-
const groupsBelowMin = hasGroupsBelowMin(null, groups);
|
|
23
|
-
const isIncomplete = quantity === 0 || groupsBelowMin;
|
|
24
|
-
const nonSizeGroups = groups.filter(i => !i.isSize);
|
|
25
|
-
const currentOptions = getItemOptions(Object.assign(Object.assign({}, orderItem), { groups: nonSizeGroups }));
|
|
26
|
-
const hasSelections = currentOptions.length > 0;
|
|
27
|
-
const desc = showDesc === 'SHORT' ? shortDescription : description;
|
|
28
|
-
const optionNames = favorite
|
|
29
|
-
? groups
|
|
30
|
-
.reduce((arr, group) => {
|
|
31
|
-
const names = group.options
|
|
32
|
-
.filter(o => o.quantity > 0)
|
|
33
|
-
.map(o => o.name);
|
|
34
|
-
return [...arr, ...names];
|
|
35
|
-
}, [])
|
|
36
|
-
.join(', ')
|
|
37
|
-
: null;
|
|
38
|
-
const displayDesc = showDesc === 'HIDE' ? '' : optionNames || desc;
|
|
39
|
-
return Object.assign(Object.assign({}, orderItem), { displayDesc,
|
|
40
|
-
displayTags,
|
|
41
|
-
displayAllergens,
|
|
42
|
-
displayPrice,
|
|
43
|
-
displayCals,
|
|
44
|
-
isIncomplete,
|
|
45
|
-
isSoldOut,
|
|
46
|
-
allergenAlert,
|
|
47
|
-
hasSelections,
|
|
48
|
-
sizeOnly,
|
|
49
|
-
cartCount });
|
|
50
|
-
};
|
|
1
|
+
import { formatDollars, getItemOptions, hasGroupsBelowMin } from '../utils';
|
|
2
|
+
export const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], cartCounts = {}, showCals = false, showTags = false, showAllergens = false, showDesc = 'SHOW') => {
|
|
3
|
+
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, isSoldOut } = orderItem;
|
|
4
|
+
const cartCount = cartCounts[orderItem.id] || 0;
|
|
5
|
+
const displayTags = showTags && tags.length ? tags : [];
|
|
6
|
+
const displayAllergens = showAllergens && allergens.length ? allergens : [];
|
|
7
|
+
const contains = allergens.filter(allergen => allergenAlerts.includes(allergen));
|
|
8
|
+
const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
|
|
9
|
+
const sizeGroup = groups.find(i => i.isSize);
|
|
10
|
+
const sizeOnly = sizeGroup && groups.length === 1;
|
|
11
|
+
const defaultOption = !sizeGroup
|
|
12
|
+
? null
|
|
13
|
+
: sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
|
|
14
|
+
const currentPrice = totalPrice
|
|
15
|
+
? totalPrice
|
|
16
|
+
: defaultOption
|
|
17
|
+
? defaultOption.price
|
|
18
|
+
: price;
|
|
19
|
+
const displayPrice = formatDollars(currentPrice.toString());
|
|
20
|
+
const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
|
|
21
|
+
const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
|
|
22
|
+
const groupsBelowMin = hasGroupsBelowMin(null, groups);
|
|
23
|
+
const isIncomplete = quantity === 0 || groupsBelowMin;
|
|
24
|
+
const nonSizeGroups = groups.filter(i => !i.isSize);
|
|
25
|
+
const currentOptions = getItemOptions(Object.assign(Object.assign({}, orderItem), { groups: nonSizeGroups }));
|
|
26
|
+
const hasSelections = currentOptions.length > 0;
|
|
27
|
+
const desc = showDesc === 'SHORT' ? shortDescription : description;
|
|
28
|
+
const optionNames = favorite
|
|
29
|
+
? groups
|
|
30
|
+
.reduce((arr, group) => {
|
|
31
|
+
const names = group.options
|
|
32
|
+
.filter(o => o.quantity > 0)
|
|
33
|
+
.map(o => o.name);
|
|
34
|
+
return [...arr, ...names];
|
|
35
|
+
}, [])
|
|
36
|
+
.join(', ')
|
|
37
|
+
: null;
|
|
38
|
+
const displayDesc = showDesc === 'HIDE' ? '' : optionNames || desc;
|
|
39
|
+
return Object.assign(Object.assign({}, orderItem), { displayDesc,
|
|
40
|
+
displayTags,
|
|
41
|
+
displayAllergens,
|
|
42
|
+
displayPrice,
|
|
43
|
+
displayCals,
|
|
44
|
+
isIncomplete,
|
|
45
|
+
isSoldOut,
|
|
46
|
+
allergenAlert,
|
|
47
|
+
hasSelections,
|
|
48
|
+
sizeOnly,
|
|
49
|
+
cartCount });
|
|
50
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { OrderRating } from '@open-tender/types';
|
|
2
|
-
export declare const useOrderRating: (orderId: number, orderRating: OrderRating, updateRating: (id: number, data: Partial<OrderRating>) => void) => {
|
|
3
|
-
rating: number;
|
|
4
|
-
handleRating: (star: number) => void;
|
|
5
|
-
comments: string;
|
|
6
|
-
handleComments: (inputComments: string) => void;
|
|
7
|
-
handleSubmit: (evt?: any) => void;
|
|
8
|
-
handleClose: () => void;
|
|
9
|
-
stars: number[];
|
|
10
|
-
};
|
|
1
|
+
import { OrderRating } from '@open-tender/types';
|
|
2
|
+
export declare const useOrderRating: (orderId: number, orderRating: OrderRating, updateRating: (id: number, data: Partial<OrderRating>) => void) => {
|
|
3
|
+
rating: number;
|
|
4
|
+
handleRating: (star: number) => void;
|
|
5
|
+
comments: string;
|
|
6
|
+
handleComments: (inputComments: string) => void;
|
|
7
|
+
handleSubmit: (evt?: any) => void;
|
|
8
|
+
handleClose: () => void;
|
|
9
|
+
stars: number[];
|
|
10
|
+
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
export const useOrderRating = (orderId, orderRating, updateRating) => {
|
|
3
|
-
const [rating, setRating] = useState((orderRating && orderRating.rating) || 0);
|
|
4
|
-
const [comments, setComments] = useState((orderRating && orderRating.comments) || '');
|
|
5
|
-
const stars = [1, 2, 3, 4, 5];
|
|
6
|
-
const handleRating = (star) => {
|
|
7
|
-
setRating(star);
|
|
8
|
-
};
|
|
9
|
-
const handleComments = (inputComments) => {
|
|
10
|
-
setComments(inputComments);
|
|
11
|
-
};
|
|
12
|
-
const handleSubmit = (evt) => {
|
|
13
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
14
|
-
const data = { rating, comments };
|
|
15
|
-
updateRating(orderId, data);
|
|
16
|
-
};
|
|
17
|
-
const handleClose = () => {
|
|
18
|
-
setComments((orderRating && orderRating.comments) || '');
|
|
19
|
-
setRating((orderRating && orderRating.rating) || 0);
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
rating,
|
|
23
|
-
handleRating,
|
|
24
|
-
comments,
|
|
25
|
-
handleComments,
|
|
26
|
-
handleSubmit,
|
|
27
|
-
handleClose,
|
|
28
|
-
stars
|
|
29
|
-
};
|
|
30
|
-
};
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
export const useOrderRating = (orderId, orderRating, updateRating) => {
|
|
3
|
+
const [rating, setRating] = useState((orderRating && orderRating.rating) || 0);
|
|
4
|
+
const [comments, setComments] = useState((orderRating && orderRating.comments) || '');
|
|
5
|
+
const stars = [1, 2, 3, 4, 5];
|
|
6
|
+
const handleRating = (star) => {
|
|
7
|
+
setRating(star);
|
|
8
|
+
};
|
|
9
|
+
const handleComments = (inputComments) => {
|
|
10
|
+
setComments(inputComments);
|
|
11
|
+
};
|
|
12
|
+
const handleSubmit = (evt) => {
|
|
13
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
14
|
+
const data = { rating, comments };
|
|
15
|
+
updateRating(orderId, data);
|
|
16
|
+
};
|
|
17
|
+
const handleClose = () => {
|
|
18
|
+
setComments((orderRating && orderRating.comments) || '');
|
|
19
|
+
setRating((orderRating && orderRating.rating) || 0);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
rating,
|
|
23
|
+
handleRating,
|
|
24
|
+
comments,
|
|
25
|
+
handleComments,
|
|
26
|
+
handleSubmit,
|
|
27
|
+
handleClose,
|
|
28
|
+
stars
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { OrderRating } from '@open-tender/types';
|
|
3
|
-
export declare const useOrderRatingForm: (orderId: number | string, orderRating: OrderRating | null, updateRating: (orderId: number | string, data: OrderRating) => void, callback?: () => void) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
stars: number[];
|
|
6
|
-
rating: number;
|
|
7
|
-
handleRating: (star: number) => void;
|
|
8
|
-
comments: string;
|
|
9
|
-
handleComments: (value: string) => void;
|
|
10
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
11
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OrderRating } from '@open-tender/types';
|
|
3
|
+
export declare const useOrderRatingForm: (orderId: number | string, orderRating: OrderRating | null, updateRating: (orderId: number | string, data: OrderRating) => void, callback?: () => void) => {
|
|
4
|
+
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
+
stars: number[];
|
|
6
|
+
rating: number;
|
|
7
|
+
handleRating: (star: number) => void;
|
|
8
|
+
comments: string;
|
|
9
|
+
handleComments: (value: string) => void;
|
|
10
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
11
|
+
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { useRef, useState } from 'react';
|
|
2
|
-
export const useOrderRatingForm = (orderId, orderRating, updateRating, callback) => {
|
|
3
|
-
const submitRef = useRef(null);
|
|
4
|
-
const [rating, setRating] = useState((orderRating === null || orderRating === void 0 ? void 0 : orderRating.rating) || 0);
|
|
5
|
-
const [comments, setComments] = useState((orderRating === null || orderRating === void 0 ? void 0 : orderRating.comments) || '');
|
|
6
|
-
const stars = [1, 2, 3, 4, 5];
|
|
7
|
-
const handleRating = (star) => {
|
|
8
|
-
setRating(star);
|
|
9
|
-
};
|
|
10
|
-
const handleComments = (value) => {
|
|
11
|
-
setComments(value);
|
|
12
|
-
};
|
|
13
|
-
const handleSubmit = (evt) => {
|
|
14
|
-
var _a, _b;
|
|
15
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
16
|
-
const data = { rating, comments };
|
|
17
|
-
updateRating(orderId, data);
|
|
18
|
-
if (callback)
|
|
19
|
-
callback();
|
|
20
|
-
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
submitRef,
|
|
24
|
-
stars,
|
|
25
|
-
rating,
|
|
26
|
-
handleRating,
|
|
27
|
-
comments,
|
|
28
|
-
handleComments,
|
|
29
|
-
handleSubmit
|
|
30
|
-
};
|
|
31
|
-
};
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
export const useOrderRatingForm = (orderId, orderRating, updateRating, callback) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const [rating, setRating] = useState((orderRating === null || orderRating === void 0 ? void 0 : orderRating.rating) || 0);
|
|
5
|
+
const [comments, setComments] = useState((orderRating === null || orderRating === void 0 ? void 0 : orderRating.comments) || '');
|
|
6
|
+
const stars = [1, 2, 3, 4, 5];
|
|
7
|
+
const handleRating = (star) => {
|
|
8
|
+
setRating(star);
|
|
9
|
+
};
|
|
10
|
+
const handleComments = (value) => {
|
|
11
|
+
setComments(value);
|
|
12
|
+
};
|
|
13
|
+
const handleSubmit = (evt) => {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
16
|
+
const data = { rating, comments };
|
|
17
|
+
updateRating(orderId, data);
|
|
18
|
+
if (callback)
|
|
19
|
+
callback();
|
|
20
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
submitRef,
|
|
24
|
+
stars,
|
|
25
|
+
rating,
|
|
26
|
+
handleRating,
|
|
27
|
+
comments,
|
|
28
|
+
handleComments,
|
|
29
|
+
handleSubmit
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Customer, CustomerCreate, FormFieldType, Gender, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const genderOptions: {
|
|
4
|
-
name: string;
|
|
5
|
-
value: Gender;
|
|
6
|
-
}[];
|
|
7
|
-
export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[]) => {
|
|
8
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
|
-
data: Customer | null;
|
|
10
|
-
errors: Record<string, string>;
|
|
11
|
-
submitting: boolean;
|
|
12
|
-
fields: FormFieldType[];
|
|
13
|
-
handleChange: (name: string, value: string | number | boolean) => void;
|
|
14
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
15
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Customer, CustomerCreate, FormFieldType, Gender, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const genderOptions: {
|
|
4
|
+
name: string;
|
|
5
|
+
value: Gender;
|
|
6
|
+
}[];
|
|
7
|
+
export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[]) => {
|
|
8
|
+
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
|
+
data: Customer | null;
|
|
10
|
+
errors: Record<string, string>;
|
|
11
|
+
submitting: boolean;
|
|
12
|
+
fields: FormFieldType[];
|
|
13
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
14
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
15
|
+
};
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { useRef, useState, useEffect, useMemo } from 'react';
|
|
2
|
-
import { makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
|
-
export const genderOptions = [
|
|
4
|
-
{ name: 'not specified', value: 'DECLINED' },
|
|
5
|
-
{ name: 'Male', value: 'MALE' },
|
|
6
|
-
{ name: 'Female', value: 'FEMALE' }
|
|
7
|
-
];
|
|
8
|
-
const allFields = [
|
|
9
|
-
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
10
|
-
{ label: 'Last Name', name: 'last_name', type: 'text', required: true },
|
|
11
|
-
{
|
|
12
|
-
label: 'Email',
|
|
13
|
-
name: 'email',
|
|
14
|
-
type: 'email',
|
|
15
|
-
required: true,
|
|
16
|
-
autoComplete: 'email'
|
|
17
|
-
},
|
|
18
|
-
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
19
|
-
{ label: 'Company', name: 'company', type: 'text' },
|
|
20
|
-
{ label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
|
|
21
|
-
{
|
|
22
|
-
label: 'Gender',
|
|
23
|
-
name: 'gender',
|
|
24
|
-
type: 'select',
|
|
25
|
-
showLabel: true,
|
|
26
|
-
options: genderOptions
|
|
27
|
-
}
|
|
28
|
-
];
|
|
29
|
-
const makePayload = (fields, data) => {
|
|
30
|
-
if (!data)
|
|
31
|
-
return null;
|
|
32
|
-
const rest = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
|
|
33
|
-
rest.birth_date = data.birth_date ? slashesToDashes(data.birth_date) : null;
|
|
34
|
-
rest.gender = data.gender || null;
|
|
35
|
-
return rest;
|
|
36
|
-
};
|
|
37
|
-
export const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
|
|
38
|
-
const submitRef = useRef(null);
|
|
39
|
-
const [data, setData] = useState(profile);
|
|
40
|
-
const [submitting, setSubmitting] = useState(false);
|
|
41
|
-
const [errors, setErrors] = useState({});
|
|
42
|
-
const toRemove = useMemo(() => {
|
|
43
|
-
const removed = [];
|
|
44
|
-
if (optionalFields && !optionalFields.includes('birth_date'))
|
|
45
|
-
removed.push('birth_date');
|
|
46
|
-
if (optionalFields && !optionalFields.includes('gender'))
|
|
47
|
-
removed.push('gender');
|
|
48
|
-
return removed;
|
|
49
|
-
}, [optionalFields]);
|
|
50
|
-
// const fields = allFields.filter((i) => !toRemove.includes(i.name))
|
|
51
|
-
const fields = useMemo(() => {
|
|
52
|
-
return allFields.filter(i => !toRemove.includes(i.name));
|
|
53
|
-
}, [toRemove]);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (loading === 'idle') {
|
|
56
|
-
setSubmitting(false);
|
|
57
|
-
if (error) {
|
|
58
|
-
const errs = makeFormErrors(error);
|
|
59
|
-
if (errs.birth_date) {
|
|
60
|
-
errs.birth_date =
|
|
61
|
-
'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
|
|
62
|
-
}
|
|
63
|
-
setErrors(errs);
|
|
64
|
-
}
|
|
65
|
-
else if (callback && submitting) {
|
|
66
|
-
const payload = makePayload(fields, data);
|
|
67
|
-
if (payload)
|
|
68
|
-
callback(payload);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}, [loading, error, callback, submitting, fields, data]);
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (profile)
|
|
74
|
-
setData(profile);
|
|
75
|
-
}, [profile]);
|
|
76
|
-
const handleChange = (name, value) => {
|
|
77
|
-
const inputValue = name === 'phone'
|
|
78
|
-
? makePhone((value !== null && value !== void 0 ? value : ''))
|
|
79
|
-
: name === 'birth_date'
|
|
80
|
-
? makeBirthDate(value)
|
|
81
|
-
: value;
|
|
82
|
-
if (data)
|
|
83
|
-
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
84
|
-
};
|
|
85
|
-
// const handleRadio = (name: string, value: string) => {
|
|
86
|
-
// if (data) setData({ ...data, [name]: value })
|
|
87
|
-
// }
|
|
88
|
-
const handleSubmit = (evt) => {
|
|
89
|
-
var _a, _b;
|
|
90
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
91
|
-
if (!data)
|
|
92
|
-
return;
|
|
93
|
-
setErrors({});
|
|
94
|
-
setSubmitting(true);
|
|
95
|
-
const payload = makePayload(fields, data);
|
|
96
|
-
if (payload)
|
|
97
|
-
update(payload);
|
|
98
|
-
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
submitRef,
|
|
102
|
-
// accepts_marketing,
|
|
103
|
-
// order_notifications,
|
|
104
|
-
data,
|
|
105
|
-
errors,
|
|
106
|
-
submitting,
|
|
107
|
-
fields,
|
|
108
|
-
handleChange,
|
|
109
|
-
// handleRadio,
|
|
110
|
-
handleSubmit
|
|
111
|
-
};
|
|
112
|
-
};
|
|
1
|
+
import { useRef, useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
|
+
export const genderOptions = [
|
|
4
|
+
{ name: 'not specified', value: 'DECLINED' },
|
|
5
|
+
{ name: 'Male', value: 'MALE' },
|
|
6
|
+
{ name: 'Female', value: 'FEMALE' }
|
|
7
|
+
];
|
|
8
|
+
const allFields = [
|
|
9
|
+
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
10
|
+
{ label: 'Last Name', name: 'last_name', type: 'text', required: true },
|
|
11
|
+
{
|
|
12
|
+
label: 'Email',
|
|
13
|
+
name: 'email',
|
|
14
|
+
type: 'email',
|
|
15
|
+
required: true,
|
|
16
|
+
autoComplete: 'email'
|
|
17
|
+
},
|
|
18
|
+
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
19
|
+
{ label: 'Company', name: 'company', type: 'text' },
|
|
20
|
+
{ label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
|
|
21
|
+
{
|
|
22
|
+
label: 'Gender',
|
|
23
|
+
name: 'gender',
|
|
24
|
+
type: 'select',
|
|
25
|
+
showLabel: true,
|
|
26
|
+
options: genderOptions
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
const makePayload = (fields, data) => {
|
|
30
|
+
if (!data)
|
|
31
|
+
return null;
|
|
32
|
+
const rest = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
|
|
33
|
+
rest.birth_date = data.birth_date ? slashesToDashes(data.birth_date) : null;
|
|
34
|
+
rest.gender = data.gender || null;
|
|
35
|
+
return rest;
|
|
36
|
+
};
|
|
37
|
+
export const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
|
|
38
|
+
const submitRef = useRef(null);
|
|
39
|
+
const [data, setData] = useState(profile);
|
|
40
|
+
const [submitting, setSubmitting] = useState(false);
|
|
41
|
+
const [errors, setErrors] = useState({});
|
|
42
|
+
const toRemove = useMemo(() => {
|
|
43
|
+
const removed = [];
|
|
44
|
+
if (optionalFields && !optionalFields.includes('birth_date'))
|
|
45
|
+
removed.push('birth_date');
|
|
46
|
+
if (optionalFields && !optionalFields.includes('gender'))
|
|
47
|
+
removed.push('gender');
|
|
48
|
+
return removed;
|
|
49
|
+
}, [optionalFields]);
|
|
50
|
+
// const fields = allFields.filter((i) => !toRemove.includes(i.name))
|
|
51
|
+
const fields = useMemo(() => {
|
|
52
|
+
return allFields.filter(i => !toRemove.includes(i.name));
|
|
53
|
+
}, [toRemove]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (loading === 'idle') {
|
|
56
|
+
setSubmitting(false);
|
|
57
|
+
if (error) {
|
|
58
|
+
const errs = makeFormErrors(error);
|
|
59
|
+
if (errs.birth_date) {
|
|
60
|
+
errs.birth_date =
|
|
61
|
+
'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
|
|
62
|
+
}
|
|
63
|
+
setErrors(errs);
|
|
64
|
+
}
|
|
65
|
+
else if (callback && submitting) {
|
|
66
|
+
const payload = makePayload(fields, data);
|
|
67
|
+
if (payload)
|
|
68
|
+
callback(payload);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, [loading, error, callback, submitting, fields, data]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (profile)
|
|
74
|
+
setData(profile);
|
|
75
|
+
}, [profile]);
|
|
76
|
+
const handleChange = (name, value) => {
|
|
77
|
+
const inputValue = name === 'phone'
|
|
78
|
+
? makePhone((value !== null && value !== void 0 ? value : ''))
|
|
79
|
+
: name === 'birth_date'
|
|
80
|
+
? makeBirthDate(value)
|
|
81
|
+
: value;
|
|
82
|
+
if (data)
|
|
83
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
84
|
+
};
|
|
85
|
+
// const handleRadio = (name: string, value: string) => {
|
|
86
|
+
// if (data) setData({ ...data, [name]: value })
|
|
87
|
+
// }
|
|
88
|
+
const handleSubmit = (evt) => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
91
|
+
if (!data)
|
|
92
|
+
return;
|
|
93
|
+
setErrors({});
|
|
94
|
+
setSubmitting(true);
|
|
95
|
+
const payload = makePayload(fields, data);
|
|
96
|
+
if (payload)
|
|
97
|
+
update(payload);
|
|
98
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
submitRef,
|
|
102
|
+
// accepts_marketing,
|
|
103
|
+
// order_notifications,
|
|
104
|
+
data,
|
|
105
|
+
errors,
|
|
106
|
+
submitting,
|
|
107
|
+
fields,
|
|
108
|
+
handleChange,
|
|
109
|
+
// handleRadio,
|
|
110
|
+
handleSubmit
|
|
111
|
+
};
|
|
112
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FormFields, RequestError, RequestStatus, ResetPasswordData } from '@open-tender/types';
|
|
3
|
-
export declare const useResetPasswordForm: (loading: RequestStatus, error: RequestError, reset: (newPassword: string, resetToken: string) => void, resetToken: string) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields: FormFields;
|
|
7
|
-
data: Partial<ResetPasswordData>;
|
|
8
|
-
errors: Record<string, string>;
|
|
9
|
-
submitting: boolean;
|
|
10
|
-
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
12
|
-
};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FormFields, RequestError, RequestStatus, ResetPasswordData } from '@open-tender/types';
|
|
3
|
+
export declare const useResetPasswordForm: (loading: RequestStatus, error: RequestError, reset: (newPassword: string, resetToken: string) => void, resetToken: string) => {
|
|
4
|
+
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
+
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: Partial<ResetPasswordData>;
|
|
8
|
+
errors: Record<string, string>;
|
|
9
|
+
submitting: boolean;
|
|
10
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
12
|
+
};
|