@open-tender/utils 0.0.69 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/cjs/hooks/menu/useBuilder.d.ts +8 -7
  2. package/dist/cjs/hooks/menu/useBuilder.js +92 -86
  3. package/dist/cjs/hooks/menu/useOrderItem.d.ts +33 -43
  4. package/dist/cjs/hooks/menu/useOrderItem.js +21 -22
  5. package/dist/cjs/hooks/useAddressForm.js +1 -1
  6. package/dist/cjs/hooks/useAllergenForm.js +1 -1
  7. package/dist/cjs/hooks/useCartGuestForm.js +2 -2
  8. package/dist/cjs/hooks/useCheckoutLoginForm.js +1 -1
  9. package/dist/cjs/hooks/useCreditCard.js +2 -2
  10. package/dist/cjs/hooks/useCreditCardForm.js +3 -3
  11. package/dist/cjs/hooks/useCurbside.js +1 -1
  12. package/dist/cjs/hooks/useDineInForm.js +1 -1
  13. package/dist/cjs/hooks/useDonationForm.js +5 -5
  14. package/dist/cjs/hooks/useGiftCardAssignForm.js +1 -1
  15. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +1 -1
  16. package/dist/cjs/hooks/useGiftCardForm.js +6 -4
  17. package/dist/cjs/hooks/useGiftCardsForm.js +22 -9
  18. package/dist/cjs/hooks/useGuestForm.js +1 -1
  19. package/dist/cjs/hooks/useLevelUpForm.js +1 -1
  20. package/dist/cjs/hooks/useOrderFulfillmentForm.js +3 -3
  21. package/dist/cjs/hooks/useOrderRating.js +1 -1
  22. package/dist/cjs/hooks/useOrderRatingForm.js +1 -1
  23. package/dist/cjs/hooks/useProfileForm.js +3 -3
  24. package/dist/cjs/hooks/useResetPasswordForm.js +2 -2
  25. package/dist/cjs/hooks/useSendResetForm.js +4 -2
  26. package/dist/cjs/hooks/useSignUpForm.js +14 -10
  27. package/dist/cjs/hooks/useSignUpGuestForm.js +3 -3
  28. package/dist/cjs/hooks/useSigninForm.js +1 -1
  29. package/dist/cjs/utils/cart.d.ts +97 -453
  30. package/dist/cjs/utils/cart.js +288 -361
  31. package/dist/cjs/utils/customer.js +1 -1
  32. package/dist/cjs/utils/errors.js +4 -2
  33. package/dist/cjs/utils/favorites.d.ts +3 -3
  34. package/dist/cjs/utils/favorites.js +11 -4
  35. package/dist/cjs/utils/helpers.d.ts +8 -3
  36. package/dist/cjs/utils/helpers.js +31 -3
  37. package/dist/cjs/utils/index.d.ts +1 -0
  38. package/dist/cjs/utils/index.js +1 -0
  39. package/dist/cjs/utils/maps.js +1 -1
  40. package/dist/cjs/utils/orders.d.ts +3 -3
  41. package/dist/cjs/utils/refunds.d.ts +4 -4
  42. package/dist/cjs/utils/revenueCenters.d.ts +11 -0
  43. package/dist/cjs/utils/revenueCenters.js +125 -0
  44. package/dist/cjs/utils/rewards.js +5 -5
  45. package/dist/cjs/utils/theme.js +7 -7
  46. package/dist/esm/hooks/menu/useBuilder.d.ts +8 -7
  47. package/dist/esm/hooks/menu/useBuilder.js +92 -86
  48. package/dist/esm/hooks/menu/useOrderItem.d.ts +33 -43
  49. package/dist/esm/hooks/menu/useOrderItem.js +22 -23
  50. package/dist/esm/hooks/useAddressForm.js +1 -1
  51. package/dist/esm/hooks/useAllergenForm.js +1 -1
  52. package/dist/esm/hooks/useCartGuestForm.js +2 -2
  53. package/dist/esm/hooks/useCheckoutLoginForm.js +1 -1
  54. package/dist/esm/hooks/useCreditCard.js +3 -3
  55. package/dist/esm/hooks/useCreditCardForm.js +3 -3
  56. package/dist/esm/hooks/useCurbside.js +1 -1
  57. package/dist/esm/hooks/useDineInForm.js +1 -1
  58. package/dist/esm/hooks/useDonationForm.js +5 -5
  59. package/dist/esm/hooks/useGiftCardAssignForm.js +1 -1
  60. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +1 -1
  61. package/dist/esm/hooks/useGiftCardForm.js +6 -4
  62. package/dist/esm/hooks/useGiftCardsForm.js +22 -9
  63. package/dist/esm/hooks/useGuestForm.js +1 -1
  64. package/dist/esm/hooks/useLevelUpForm.js +1 -1
  65. package/dist/esm/hooks/useOrderFulfillmentForm.js +3 -3
  66. package/dist/esm/hooks/useOrderRating.js +1 -1
  67. package/dist/esm/hooks/useOrderRatingForm.js +1 -1
  68. package/dist/esm/hooks/useProfileForm.js +3 -3
  69. package/dist/esm/hooks/useResetPasswordForm.js +2 -2
  70. package/dist/esm/hooks/useSendResetForm.js +4 -2
  71. package/dist/esm/hooks/useSignUpForm.js +14 -10
  72. package/dist/esm/hooks/useSignUpGuestForm.js +3 -3
  73. package/dist/esm/hooks/useSigninForm.js +1 -1
  74. package/dist/esm/utils/cart.d.ts +97 -453
  75. package/dist/esm/utils/cart.js +276 -339
  76. package/dist/esm/utils/customer.js +1 -1
  77. package/dist/esm/utils/errors.js +4 -2
  78. package/dist/esm/utils/favorites.d.ts +3 -3
  79. package/dist/esm/utils/favorites.js +11 -4
  80. package/dist/esm/utils/helpers.d.ts +8 -3
  81. package/dist/esm/utils/helpers.js +25 -2
  82. package/dist/esm/utils/index.d.ts +1 -0
  83. package/dist/esm/utils/index.js +1 -0
  84. package/dist/esm/utils/maps.js +1 -1
  85. package/dist/esm/utils/orders.d.ts +3 -3
  86. package/dist/esm/utils/refunds.d.ts +4 -4
  87. package/dist/esm/utils/revenueCenters.d.ts +11 -0
  88. package/dist/esm/utils/revenueCenters.js +115 -0
  89. package/dist/esm/utils/rewards.js +1 -1
  90. package/dist/esm/utils/theme.js +7 -7
  91. package/package.json +2 -4
@@ -3,19 +3,20 @@ import { calcPrices } from '../../utils';
3
3
  export const useBuilder = (orderItem) => {
4
4
  const [item, setItem] = useState(orderItem);
5
5
  const increment = () => {
6
- var _a, _b, _c, _d;
7
6
  const newQuantity = item.max
8
- ? Math.min(((_a = item.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = item.increment) !== null && _b !== void 0 ? _b : 0), item.max)
9
- : ((_c = item.quantity) !== null && _c !== void 0 ? _c : 0) + ((_d = item.increment) !== null && _d !== void 0 ? _d : 0);
10
- setItem(calcPrices(Object.assign(Object.assign({}, item), { quantity: newQuantity })));
7
+ ? Math.min(item.quantity + item.increment, item.max)
8
+ : item.quantity + item.increment;
9
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
10
+ setItem(pricedItem);
11
11
  };
12
12
  const decrement = () => {
13
- var _a, _b, _c;
14
- const newQuantity = Math.max(((_a = item.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = item.increment) !== null && _b !== void 0 ? _b : 0), ((_c = item.min) !== null && _c !== void 0 ? _c : 0));
15
- setItem(calcPrices(Object.assign(Object.assign({}, item), { quantity: newQuantity })));
13
+ const newQuantity = Math.max(item.quantity - item.increment, item.min);
14
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
15
+ setItem(pricedItem);
16
16
  };
17
17
  const setQuantity = (quantity) => {
18
- setItem(calcPrices(Object.assign(Object.assign({}, item), { quantity: quantity })));
18
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { quantity }));
19
+ setItem(pricedItem);
19
20
  };
20
21
  const setMadeFor = (madeFor) => {
21
22
  setItem(Object.assign(Object.assign({}, item), { madeFor }));
@@ -23,93 +24,78 @@ export const useBuilder = (orderItem) => {
23
24
  const setNotes = (notes) => {
24
25
  setItem(Object.assign(Object.assign({}, item), { notes }));
25
26
  };
26
- const toggleOption = (groupId, optionId) => {
27
- var _a;
28
- const groups = (_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
29
- var _a;
30
- if (group.id === groupId) {
31
- const options = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
32
- const newQuantity = option.id === optionId ? 1 : 0;
33
- return Object.assign(Object.assign({}, option), { quantity: newQuantity });
34
- });
35
- return Object.assign(Object.assign({}, group), { options });
36
- }
37
- return group;
27
+ const setMadeForNotes = (madeFor, notes) => {
28
+ setItem(Object.assign(Object.assign({}, item), { madeFor, notes }));
29
+ };
30
+ const toggleGroupOption = (group, optionId) => {
31
+ const options = group.options.map(option => {
32
+ return Object.assign(Object.assign({}, option), { quantity: option.id === optionId ? 1 : 0 });
38
33
  });
39
- setItem(calcPrices(Object.assign(Object.assign({}, item), { groups: groups })));
34
+ return Object.assign(Object.assign({}, group), { options });
40
35
  };
41
- const incrementOption = (groupId, optionId) => {
42
- var _a;
43
- const groups = (_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
44
- var _a, _b, _c;
45
- if (group.id === groupId) {
46
- const count = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
47
- if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
48
- return group;
49
- const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
50
- var _a, _b, _c, _d;
51
- if (option.id === optionId) {
52
- let quantity = ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = option.increment) !== null && _b !== void 0 ? _b : 0);
53
- const quantities = [quantity];
54
- if (option.max !== 0)
55
- quantities.push(((_c = option.max) !== null && _c !== void 0 ? _c : 0));
56
- if (group.max !== 0)
57
- quantities.push(((_d = group.max) !== null && _d !== void 0 ? _d : 0) - (count !== null && count !== void 0 ? count : 0));
58
- quantity = Math.min(...quantities);
59
- return Object.assign(Object.assign({}, option), { quantity });
60
- }
61
- return option;
62
- });
63
- return Object.assign(Object.assign({}, group), { options });
64
- }
36
+ const incrementGroupOption = (group, optionId) => {
37
+ const count = group.options
38
+ .filter(o => o.id !== optionId)
39
+ .reduce((t, o) => t + o.quantity, 0);
40
+ if (group.max !== 0 && count >= group.max)
65
41
  return group;
42
+ const options = group.options.map(option => {
43
+ if (option.id === optionId) {
44
+ let quantity = option.quantity + option.increment;
45
+ const quantities = [quantity];
46
+ if (option.max !== 0)
47
+ quantities.push(option.max);
48
+ if (group.max !== 0)
49
+ quantities.push(group.max - count);
50
+ quantity = Math.min(...quantities);
51
+ return Object.assign(Object.assign({}, option), { quantity });
52
+ }
53
+ return option;
66
54
  });
67
- setItem(calcPrices(Object.assign(Object.assign({}, item), { groups: groups })));
55
+ return Object.assign(Object.assign({}, group), { options });
68
56
  };
69
- const decrementOption = (groupId, optionId) => {
70
- var _a;
71
- const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
72
- var _a;
73
- if (group.id === groupId) {
74
- const options = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
75
- var _a, _b;
76
- if (option.id === optionId) {
77
- const quantity = Math.max(((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = option.increment) !== null && _b !== void 0 ? _b : 0), 0);
78
- return Object.assign(Object.assign({}, option), { quantity });
79
- }
80
- return option;
81
- });
82
- return Object.assign(Object.assign({}, group), { options });
57
+ const decrementGroupOption = (group, optionId) => {
58
+ const options = group.options.map(option => {
59
+ if (option.id === optionId) {
60
+ const quantity = Math.max(option.quantity - option.increment, 0);
61
+ return Object.assign(Object.assign({}, option), { quantity });
83
62
  }
63
+ return option;
64
+ });
65
+ return Object.assign(Object.assign({}, group), { options });
66
+ };
67
+ const setGroupOptionQuantity = (group, optionId, quantity) => {
68
+ if (quantity === undefined)
69
+ return group;
70
+ const count = group.options
71
+ .filter(o => o.id !== optionId)
72
+ .reduce((t, o) => t + o.quantity, 0);
73
+ if (group.max !== 0 && count >= group.max)
84
74
  return group;
75
+ const options = group.options.map(option => {
76
+ if (option.id === optionId) {
77
+ const quantities = quantity ? [quantity] : [0];
78
+ if (option.max !== 0)
79
+ quantities.push(option.max);
80
+ if (group.max !== 0)
81
+ quantities.push(group.max - count);
82
+ quantity = Math.min(...quantities);
83
+ quantity = Math.max(quantity, option.min);
84
+ return Object.assign(Object.assign({}, option), { quantity });
85
+ }
86
+ return option;
85
87
  });
86
- setItem(calcPrices(Object.assign(Object.assign({}, item), { groups: groups })));
88
+ return Object.assign(Object.assign({}, group), { options });
87
89
  };
88
- const setOptionQuantity = (groupId, optionId, quantity, nested) => {
89
- var _a;
90
- const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
91
- var _a, _b, _c;
90
+ const updateGroups = (groups, levels, fn, quantity) => {
91
+ const [[groupId, optionId], ...rest] = levels;
92
+ return groups.map(group => {
92
93
  if (group.id === groupId) {
93
- const count = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
94
- if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
95
- return group;
96
- const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
97
- var _a, _b, _c;
98
- const optionGroups = nested || option.groups || [];
94
+ if (!rest.length)
95
+ return fn(group, optionId, quantity);
96
+ const options = group.options.map(option => {
99
97
  if (option.id === optionId) {
100
- if (`${quantity}` === '') {
101
- return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
102
- }
103
- else {
104
- const quantities = [quantity];
105
- if (option.max !== 0)
106
- quantities.push(((_a = option.max) !== null && _a !== void 0 ? _a : 0));
107
- if (group.max !== 0)
108
- quantities.push(((_b = group.max) !== null && _b !== void 0 ? _b : 0) - (count !== null && count !== void 0 ? count : 0));
109
- quantity = Math.min(...quantities);
110
- quantity = Math.max(quantity, ((_c = option.min) !== null && _c !== void 0 ? _c : 0));
111
- return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
112
- }
98
+ return Object.assign(Object.assign({}, option), { groups: updateGroups(option.groups, rest, fn) });
113
99
  }
114
100
  return option;
115
101
  });
@@ -117,7 +103,26 @@ export const useBuilder = (orderItem) => {
117
103
  }
118
104
  return group;
119
105
  });
120
- setItem(calcPrices(Object.assign(Object.assign({}, item), { groups: groups })));
106
+ };
107
+ const toggleOption = (levels) => {
108
+ const groups = updateGroups(item.groups, levels, toggleGroupOption);
109
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
110
+ setItem(pricedItem);
111
+ };
112
+ const incrementOption = (levels) => {
113
+ const groups = updateGroups(item.groups, levels, incrementGroupOption);
114
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
115
+ setItem(pricedItem);
116
+ };
117
+ const decrementOption = (levels) => {
118
+ const groups = updateGroups(item.groups, levels, decrementGroupOption);
119
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
120
+ setItem(pricedItem);
121
+ };
122
+ const setOptionQuantity = (levels, quantity) => {
123
+ const groups = updateGroups(item.groups, levels, setGroupOptionQuantity, quantity);
124
+ const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups: groups }));
125
+ setItem(pricedItem);
121
126
  };
122
127
  return {
123
128
  item,
@@ -126,9 +131,10 @@ export const useBuilder = (orderItem) => {
126
131
  setQuantity,
127
132
  setMadeFor,
128
133
  setNotes,
134
+ setMadeForNotes,
129
135
  toggleOption,
130
136
  incrementOption,
131
137
  decrementOption,
132
- setOptionQuantity,
138
+ setOptionQuantity
133
139
  };
134
140
  };
@@ -1,7 +1,7 @@
1
- import { CartCounts, Favorite, CartItem, SoldOut, ConfigDisplaySetting } from "@open-tender/types";
2
- export declare const useOrderItem: (orderItem: Partial<CartItem>, favorite?: Partial<Favorite> | null, soldOut?: SoldOut, allergenAlerts?: Array<string>, displaySettings?: Partial<ConfigDisplaySetting>, cartCounts?: CartCounts, isMobile?: boolean) => {
3
- showImage: boolean | undefined;
4
- displayDesc: any;
1
+ import { CartCounts, Favorite, CartItem, ConfigDisplaySetting } from '@open-tender/types';
2
+ export declare const useOrderItem: (orderItem: CartItem, favorite: Favorite | null | undefined, allergenAlerts: string[] | undefined, displaySettings: ConfigDisplaySetting, cartCounts?: CartCounts, isMobile?: boolean) => {
3
+ showImage: boolean;
4
+ displayDesc: string | null;
5
5
  displayTags: string[];
6
6
  displayAllergens: string[];
7
7
  displayPrice: string;
@@ -10,47 +10,37 @@ export declare const useOrderItem: (orderItem: Partial<CartItem>, favorite?: Par
10
10
  isSoldOut: boolean;
11
11
  allergenAlert: string | null;
12
12
  hasSelections: boolean;
13
- showQuickAdd: boolean | undefined;
13
+ showQuickAdd: boolean;
14
14
  sizeOnly: boolean | undefined;
15
15
  cartCount: number;
16
+ cartGuestId: number | null;
17
+ customerId: number | null;
16
18
  index?: number | undefined;
17
- id?: number | undefined;
18
- name?: string | undefined;
19
- shortName?: string | undefined;
20
- cart_guest_id?: number | null | undefined;
21
- category?: string | null | undefined;
22
- customer_id?: number | null | undefined;
23
- description?: string | null | undefined;
24
- imageUrl?: string | null | undefined;
25
- slug?: string | undefined;
26
- allergens?: string[] | undefined;
27
- tags?: string[] | undefined;
28
- ingredients?: string | null | undefined;
29
- madeFor?: string | null | undefined;
30
- notes?: string | null | undefined;
31
- nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
32
- cals?: number | null | undefined;
33
- groups?: import("@open-tender/types").CartItemGroups | undefined;
34
- quantity?: number | undefined;
35
- price?: number | undefined;
36
- increment?: number | undefined;
37
- max?: number | undefined;
38
- min?: number | undefined;
39
- points?: any;
40
- upsellItems?: number[] | undefined;
41
- similarItems?: number[] | undefined;
42
- totalPrice?: number | undefined;
43
- totalPoints?: number | null | undefined;
44
- totalCals?: number | null | undefined;
45
- item_no?: number | undefined;
46
- nutritional_info?: import("@open-tender/types").NutritionalInfo | null | undefined;
47
- price_total?: number | undefined;
48
- favorite_id?: number | undefined;
49
- images?: import("@open-tender/types").OrderItemImages | undefined;
50
- short_description?: string | undefined;
51
- shortDescription?: string | undefined;
52
- made_for?: string | undefined;
19
+ madeFor: string | null;
20
+ notes: string | null;
53
21
  signature?: string | undefined;
54
- isDefault?: number | boolean | undefined;
55
- favorite?: Favorite | undefined;
22
+ similarItems: number[];
23
+ upsellItems: number[];
24
+ allergens: string[];
25
+ cals: number | null;
26
+ description: string | null;
27
+ groups: import("@open-tender/types").CartItemGroups;
28
+ id: number;
29
+ imageUrl: string | null;
30
+ increment: number;
31
+ ingredients: string | null;
32
+ max: number;
33
+ min: number;
34
+ name: string;
35
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
36
+ points: number | null;
37
+ price: number;
38
+ quantity: number;
39
+ shortDescription: string | null;
40
+ shortName: string;
41
+ slug: string;
42
+ tags: string[];
43
+ totalCals: number | null;
44
+ totalPoints: number | null;
45
+ totalPrice: number | null;
56
46
  };
@@ -1,33 +1,31 @@
1
- import { formatDollars, getItemOptions } from "../../utils";
2
- export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts = [], displaySettings = {}, cartCounts = {}, isMobile = true) => {
3
- var _a, _b, _c, _d, _e;
4
- const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile, } = displaySettings;
1
+ import { formatDollars, getItemOptions, hasGroupsBelowMin } from '../../utils';
2
+ export const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySettings, cartCounts = {}, isMobile = true) => {
3
+ const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile } = displaySettings;
5
4
  const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
6
- const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, } = orderItem;
7
- const cartCount = orderItem.id ? cartCounts[orderItem.id] : 0;
8
- const isSoldOut = orderItem.id ? soldOut.includes(orderItem.id) : false;
9
- const displayTags = showTags && (tags === null || tags === void 0 ? void 0 : tags.length) ? tags : [];
10
- const displayAllergens = showAllergens && (allergens === null || allergens === void 0 ? void 0 : allergens.length) ? allergens : [];
11
- const contains = allergens === null || allergens === void 0 ? void 0 : allergens.filter((allergen) => allergenAlerts.includes(allergen));
12
- const allergenAlert = (contains === null || contains === void 0 ? void 0 : contains.length) ? `${contains.join(', ')}` : null;
13
- const sizeGroup = groups === null || groups === void 0 ? void 0 : groups.find((i) => i.isSize);
14
- const sizeOnly = sizeGroup && (groups === null || groups === void 0 ? void 0 : groups.length) === 1;
5
+ const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, isSoldOut } = orderItem;
6
+ const cartCount = cartCounts[orderItem.id] || 0;
7
+ const displayTags = showTags && tags.length ? tags : [];
8
+ const displayAllergens = showAllergens && allergens.length ? allergens : [];
9
+ const contains = allergens.filter(allergen => allergenAlerts.includes(allergen));
10
+ const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
11
+ const sizeGroup = groups.find(i => i.isSize);
12
+ const sizeOnly = sizeGroup && groups.length === 1;
15
13
  const defaultOption = !sizeGroup
16
14
  ? null
17
- : ((_a = sizeGroup === null || sizeGroup === void 0 ? void 0 : sizeGroup.options) === null || _a === void 0 ? void 0 : _a.find((i) => i.isDefault)) || sizeGroup.options[0];
15
+ : sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
18
16
  const currentPrice = totalPrice
19
17
  ? totalPrice
20
18
  : defaultOption
21
19
  ? defaultOption.price
22
20
  : price;
23
- const displayPrice = formatDollars(`${currentPrice}`);
21
+ const displayPrice = formatDollars(currentPrice.toString());
24
22
  const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
25
23
  const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
26
- const groupsBelowMin = ((_b = groups === null || groups === void 0 ? void 0 : groups.filter((g) => { var _a, _b; return ((_a = g.quantity) !== null && _a !== void 0 ? _a : 0) < ((_b = g.min) !== null && _b !== void 0 ? _b : 0); }).length) !== null && _b !== void 0 ? _b : 0) > 0;
27
- const isIncomplete = totalPrice === 0 || `${quantity}` === '' || groupsBelowMin;
28
- const nonSizeGroups = groups === null || groups === void 0 ? void 0 : groups.filter((i) => !i.isSize);
24
+ const groupsBelowMin = hasGroupsBelowMin(null, groups);
25
+ const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
26
+ const nonSizeGroups = groups.filter(i => !i.isSize);
29
27
  const currentOptions = getItemOptions({ groups: nonSizeGroups });
30
- const hasSelections = ((_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.length) !== null && _c !== void 0 ? _c : 0) > 0;
28
+ const hasSelections = currentOptions.length > 0;
31
29
  const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
32
30
  const desc = showDesc === 'HIDE'
33
31
  ? ''
@@ -35,11 +33,12 @@ export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenA
35
33
  ? shortDescription
36
34
  : description;
37
35
  const optionNames = favorite
38
- ? (_e = (_d = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _d === void 0 ? void 0 : _d.groups) === null || _e === void 0 ? void 0 : _e.reduce((arr, group) => {
39
- var _a, _b;
40
- const names = (_b = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((o) => o.name)) !== null && _b !== void 0 ? _b : [];
36
+ ? favorite.item.groups
37
+ .reduce((arr, group) => {
38
+ const names = group.options.map(o => o.name);
41
39
  return [...arr, ...names];
42
- }, []).join(', ')
40
+ }, [])
41
+ .join(', ')
43
42
  : null;
44
43
  const displayDesc = optionNames || desc;
45
44
  return Object.assign(Object.assign({}, orderItem), { showImage,
@@ -12,7 +12,7 @@ export const useAddressForm = (address, loading, error, update, callback) => {
12
12
  { label: 'Contact Phone', name: 'phone', type: 'phone-pad' },
13
13
  { label: 'Description', name: 'description', type: 'default' },
14
14
  { label: 'Notes', name: 'notes', type: 'default' },
15
- { label: 'Is Default', name: 'is_default', type: 'checkbox' },
15
+ { label: 'Is Default', name: 'is_default', type: 'checkbox' }
16
16
  ];
17
17
  useEffect(() => {
18
18
  var _a, _b;
@@ -41,6 +41,6 @@ export const useAllergenForm = (allergens, selectedAllergens, isLoading = false,
41
41
  allergenIds,
42
42
  formError,
43
43
  handleChange,
44
- handleSubmit,
44
+ handleSubmit
45
45
  };
46
46
  };
@@ -6,7 +6,7 @@ export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
6
6
  const [submitting, setSubmitting] = useState(false);
7
7
  const fields = [
8
8
  { label: 'First Name', name: 'first_name', type: 'text', required: true },
9
- { label: 'Last Name', name: 'last_name', type: 'text', required: true },
9
+ { label: 'Last Name', name: 'last_name', type: 'text', required: true }
10
10
  ];
11
11
  useEffect(() => {
12
12
  return () => {
@@ -39,6 +39,6 @@ export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
39
39
  data,
40
40
  submitting,
41
41
  handleChange,
42
- handleSubmit,
42
+ handleSubmit
43
43
  };
44
44
  };
@@ -34,6 +34,6 @@ export const useLoginForm = (loading, error, login, callback) => {
34
34
  data,
35
35
  submitting,
36
36
  handleChange,
37
- handleSubmit,
37
+ handleSubmit
38
38
  };
39
39
  };
@@ -1,11 +1,11 @@
1
1
  import { useRef, useState } from 'react';
2
- import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard, } from '../';
2
+ import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard } from '../';
3
3
  const defaultState = {
4
4
  acct: '',
5
5
  exp: '',
6
6
  cvv: '',
7
7
  zip: '',
8
- is_default: false,
8
+ is_default: false
9
9
  };
10
10
  export const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
11
11
  const [initCard, initCardType] = formatCard(initState);
@@ -49,6 +49,6 @@ export const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
49
49
  setErrors,
50
50
  handleChange,
51
51
  handleBlur,
52
- isComplete,
52
+ isComplete
53
53
  };
54
54
  };
@@ -35,7 +35,7 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
35
35
  if (!token) {
36
36
  setSubmitting(false);
37
37
  setErrors({
38
- form: 'Please complete the recaptcha before submitting',
38
+ form: 'Please complete the recaptcha before submitting'
39
39
  });
40
40
  if (windowRef)
41
41
  windowRef.scrollTo({ top: 0 });
@@ -48,7 +48,7 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
48
48
  catch (err) {
49
49
  setSubmitting(false);
50
50
  setErrors({
51
- form: 'Please complete the recaptcha before submitting',
51
+ form: 'Please complete the recaptcha before submitting'
52
52
  });
53
53
  if (windowRef)
54
54
  windowRef.scrollTo({ top: 0 });
@@ -66,6 +66,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
66
66
  recaptchaRef,
67
67
  data,
68
68
  submitting,
69
- handleSubmit,
69
+ handleSubmit
70
70
  };
71
71
  };
@@ -30,6 +30,6 @@ export const useCurbside = (orderId, fulfillment, loading, error, update, settin
30
30
  errors,
31
31
  submitting,
32
32
  handleChange,
33
- handleSubmit,
33
+ handleSubmit
34
34
  };
35
35
  };
@@ -24,6 +24,6 @@ export const useDineInForm = (initialData = {}, submitGuest) => {
24
24
  data,
25
25
  errMsg,
26
26
  handleChange,
27
- handleSubmit,
27
+ handleSubmit
28
28
  };
29
29
  };
@@ -40,7 +40,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
40
40
  if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
41
41
  const options = creditCards.map(i => ({
42
42
  label: `${i.card_type_name} ending in ${i.last4}`,
43
- value: i.customer_card_id,
43
+ value: i.customer_card_id
44
44
  }));
45
45
  setCreditCardOptions(options);
46
46
  const defaultCard = creditCards.length
@@ -67,7 +67,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
67
67
  const purchaseWithCaptcha = (credit_card) => {
68
68
  const alert = {
69
69
  type: 'working',
70
- args: { text: 'Submitting your contribution...' },
70
+ args: { text: 'Submitting your contribution...' }
71
71
  };
72
72
  if (recaptchaKey) {
73
73
  try {
@@ -84,7 +84,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
84
84
  amount: amount,
85
85
  email: email,
86
86
  credit_card,
87
- token: token,
87
+ token: token
88
88
  });
89
89
  }
90
90
  }
@@ -101,7 +101,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
101
101
  amount: amount,
102
102
  email: email,
103
103
  credit_card,
104
- token: '',
104
+ token: ''
105
105
  });
106
106
  }
107
107
  };
@@ -162,6 +162,6 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
162
162
  handleCreditCard,
163
163
  handleSubmit,
164
164
  handleReset,
165
- setErrors,
165
+ setErrors
166
166
  };
167
167
  };
@@ -39,6 +39,6 @@ export const useGiftCardAssignForm = (loading, error, assign, callback) => {
39
39
  errors,
40
40
  submitting,
41
41
  handleChange,
42
- handleSubmit,
42
+ handleSubmit
43
43
  };
44
44
  };
@@ -32,6 +32,6 @@ export const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, c
32
32
  errors,
33
33
  submitting,
34
34
  handleChange,
35
- handleSubmit,
35
+ handleSubmit
36
36
  };
37
37
  };
@@ -3,13 +3,15 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
3
3
  const submitRef = useRef(null);
4
4
  const inputRef = useRef(null);
5
5
  const customerCardId = creditCards[0].customer_card_id;
6
- const [data, setData] = useState({ customer_card_id: customerCardId });
6
+ const [data, setData] = useState({
7
+ customer_card_id: customerCardId
8
+ });
7
9
  const [errors, setErrors] = useState({});
8
10
  const [submitting, setSubmitting] = useState(false);
9
- const options = creditCards.map((i) => {
11
+ const options = creditCards.map(i => {
10
12
  return {
11
13
  name: `${i.card_type_name} ending in ${i.last4}`,
12
- value: i.customer_card_id,
14
+ value: i.customer_card_id
13
15
  };
14
16
  });
15
17
  useEffect(() => {
@@ -50,6 +52,6 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
50
52
  data,
51
53
  submitting,
52
54
  handleChange,
53
- handleSubmit,
55
+ handleSubmit
54
56
  };
55
57
  };