@open-tender/utils 0.0.68 → 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 (99) 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.d.ts +1 -2
  10. package/dist/cjs/hooks/useCreditCard.js +4 -3
  11. package/dist/cjs/hooks/useCreditCardForm.js +3 -3
  12. package/dist/cjs/hooks/useCurbside.js +1 -1
  13. package/dist/cjs/hooks/useDineInForm.js +1 -1
  14. package/dist/cjs/hooks/useDonationForm.js +5 -5
  15. package/dist/cjs/hooks/useGiftCardAssignForm.js +1 -1
  16. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +1 -1
  17. package/dist/cjs/hooks/useGiftCardForm.js +6 -4
  18. package/dist/cjs/hooks/useGiftCardsForm.js +22 -9
  19. package/dist/cjs/hooks/useGuestForm.js +1 -1
  20. package/dist/cjs/hooks/useImage.d.ts +1 -2
  21. package/dist/cjs/hooks/useImage.js +2 -1
  22. package/dist/cjs/hooks/useLevelUpForm.d.ts +1 -2
  23. package/dist/cjs/hooks/useLevelUpForm.js +3 -2
  24. package/dist/cjs/hooks/useOrderFulfillmentForm.js +3 -3
  25. package/dist/cjs/hooks/useOrderRating.js +1 -1
  26. package/dist/cjs/hooks/useOrderRatingForm.js +1 -1
  27. package/dist/cjs/hooks/useProfileForm.js +3 -3
  28. package/dist/cjs/hooks/useResetPasswordForm.js +2 -2
  29. package/dist/cjs/hooks/useSendResetForm.js +4 -2
  30. package/dist/cjs/hooks/useSignUpForm.js +14 -10
  31. package/dist/cjs/hooks/useSignUpGuestForm.js +3 -3
  32. package/dist/cjs/hooks/useSigninForm.js +1 -1
  33. package/dist/cjs/utils/cart.d.ts +97 -453
  34. package/dist/cjs/utils/cart.js +288 -361
  35. package/dist/cjs/utils/customer.js +1 -1
  36. package/dist/cjs/utils/errors.js +4 -2
  37. package/dist/cjs/utils/favorites.d.ts +3 -3
  38. package/dist/cjs/utils/favorites.js +11 -4
  39. package/dist/cjs/utils/helpers.d.ts +8 -3
  40. package/dist/cjs/utils/helpers.js +31 -3
  41. package/dist/cjs/utils/index.d.ts +1 -0
  42. package/dist/cjs/utils/index.js +1 -0
  43. package/dist/cjs/utils/maps.js +1 -1
  44. package/dist/cjs/utils/orders.d.ts +3 -3
  45. package/dist/cjs/utils/refunds.d.ts +4 -4
  46. package/dist/cjs/utils/revenueCenters.d.ts +11 -0
  47. package/dist/cjs/utils/revenueCenters.js +125 -0
  48. package/dist/cjs/utils/rewards.js +5 -5
  49. package/dist/cjs/utils/theme.js +7 -7
  50. package/dist/esm/hooks/menu/useBuilder.d.ts +8 -7
  51. package/dist/esm/hooks/menu/useBuilder.js +92 -86
  52. package/dist/esm/hooks/menu/useOrderItem.d.ts +33 -43
  53. package/dist/esm/hooks/menu/useOrderItem.js +22 -23
  54. package/dist/esm/hooks/useAddressForm.js +1 -1
  55. package/dist/esm/hooks/useAllergenForm.js +1 -1
  56. package/dist/esm/hooks/useCartGuestForm.js +2 -2
  57. package/dist/esm/hooks/useCheckoutLoginForm.js +1 -1
  58. package/dist/esm/hooks/useCreditCard.d.ts +1 -2
  59. package/dist/esm/hooks/useCreditCard.js +4 -5
  60. package/dist/esm/hooks/useCreditCardForm.js +3 -3
  61. package/dist/esm/hooks/useCurbside.js +1 -1
  62. package/dist/esm/hooks/useDineInForm.js +1 -1
  63. package/dist/esm/hooks/useDonationForm.js +5 -5
  64. package/dist/esm/hooks/useGiftCardAssignForm.js +1 -1
  65. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +1 -1
  66. package/dist/esm/hooks/useGiftCardForm.js +6 -4
  67. package/dist/esm/hooks/useGiftCardsForm.js +22 -9
  68. package/dist/esm/hooks/useGuestForm.js +1 -1
  69. package/dist/esm/hooks/useImage.d.ts +1 -2
  70. package/dist/esm/hooks/useImage.js +1 -2
  71. package/dist/esm/hooks/useLevelUpForm.d.ts +1 -2
  72. package/dist/esm/hooks/useLevelUpForm.js +2 -3
  73. package/dist/esm/hooks/useOrderFulfillmentForm.js +3 -3
  74. package/dist/esm/hooks/useOrderRating.js +1 -1
  75. package/dist/esm/hooks/useOrderRatingForm.js +1 -1
  76. package/dist/esm/hooks/useProfileForm.js +3 -3
  77. package/dist/esm/hooks/useResetPasswordForm.js +2 -2
  78. package/dist/esm/hooks/useSendResetForm.js +4 -2
  79. package/dist/esm/hooks/useSignUpForm.js +14 -10
  80. package/dist/esm/hooks/useSignUpGuestForm.js +3 -3
  81. package/dist/esm/hooks/useSigninForm.js +1 -1
  82. package/dist/esm/utils/cart.d.ts +97 -453
  83. package/dist/esm/utils/cart.js +276 -339
  84. package/dist/esm/utils/customer.js +1 -1
  85. package/dist/esm/utils/errors.js +4 -2
  86. package/dist/esm/utils/favorites.d.ts +3 -3
  87. package/dist/esm/utils/favorites.js +11 -4
  88. package/dist/esm/utils/helpers.d.ts +8 -3
  89. package/dist/esm/utils/helpers.js +25 -2
  90. package/dist/esm/utils/index.d.ts +1 -0
  91. package/dist/esm/utils/index.js +1 -0
  92. package/dist/esm/utils/maps.js +1 -1
  93. package/dist/esm/utils/orders.d.ts +3 -3
  94. package/dist/esm/utils/refunds.d.ts +4 -4
  95. package/dist/esm/utils/revenueCenters.d.ts +11 -0
  96. package/dist/esm/utils/revenueCenters.js +115 -0
  97. package/dist/esm/utils/rewards.js +1 -1
  98. package/dist/esm/utils/theme.js +7 -7
  99. package/package.json +2 -4
@@ -1,13 +1,14 @@
1
- import { CartItem, CartItemOptions, MenuItem } from '@open-tender/types';
2
- export declare const useBuilder: (orderItem: Partial<CartItem & MenuItem>) => {
3
- item: Partial<CartItem>;
1
+ import { CartItem, CartLevels } from '@open-tender/types';
2
+ export declare const useBuilder: (orderItem: CartItem) => {
3
+ item: CartItem;
4
4
  increment: () => void;
5
5
  decrement: () => void;
6
6
  setQuantity: (quantity: number) => void;
7
7
  setMadeFor: (madeFor: string) => void;
8
8
  setNotes: (notes: string) => void;
9
- toggleOption: (groupId: number, optionId: number) => void;
10
- incrementOption: (groupId: number, optionId: number) => void;
11
- decrementOption: (groupId: number, optionId: number) => void;
12
- setOptionQuantity: (groupId: number, optionId: number, quantity: number, nested: CartItemOptions) => 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;
13
14
  };
@@ -6,19 +6,20 @@ const utils_1 = require("../../utils");
6
6
  const useBuilder = (orderItem) => {
7
7
  const [item, setItem] = (0, react_1.useState)(orderItem);
8
8
  const increment = () => {
9
- var _a, _b, _c, _d;
10
9
  const newQuantity = item.max
11
- ? Math.min(((_a = item.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = item.increment) !== null && _b !== void 0 ? _b : 0), item.max)
12
- : ((_c = item.quantity) !== null && _c !== void 0 ? _c : 0) + ((_d = item.increment) !== null && _d !== void 0 ? _d : 0);
13
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity })));
10
+ ? Math.min(item.quantity + item.increment, item.max)
11
+ : item.quantity + item.increment;
12
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
13
+ setItem(pricedItem);
14
14
  };
15
15
  const decrement = () => {
16
- var _a, _b, _c;
17
- 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));
18
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity })));
16
+ const newQuantity = Math.max(item.quantity - item.increment, item.min);
17
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
18
+ setItem(pricedItem);
19
19
  };
20
20
  const setQuantity = (quantity) => {
21
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity: quantity })));
21
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { quantity }));
22
+ setItem(pricedItem);
22
23
  };
23
24
  const setMadeFor = (madeFor) => {
24
25
  setItem(Object.assign(Object.assign({}, item), { madeFor }));
@@ -26,93 +27,78 @@ const useBuilder = (orderItem) => {
26
27
  const setNotes = (notes) => {
27
28
  setItem(Object.assign(Object.assign({}, item), { notes }));
28
29
  };
29
- const toggleOption = (groupId, optionId) => {
30
- var _a;
31
- const groups = (_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
32
- var _a;
33
- if (group.id === groupId) {
34
- const options = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
35
- const newQuantity = option.id === optionId ? 1 : 0;
36
- return Object.assign(Object.assign({}, option), { quantity: newQuantity });
37
- });
38
- return Object.assign(Object.assign({}, group), { options });
39
- }
40
- return group;
30
+ const setMadeForNotes = (madeFor, notes) => {
31
+ setItem(Object.assign(Object.assign({}, item), { madeFor, notes }));
32
+ };
33
+ const toggleGroupOption = (group, optionId) => {
34
+ const options = group.options.map(option => {
35
+ return Object.assign(Object.assign({}, option), { quantity: option.id === optionId ? 1 : 0 });
41
36
  });
42
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups })));
37
+ return Object.assign(Object.assign({}, group), { options });
43
38
  };
44
- const incrementOption = (groupId, optionId) => {
45
- var _a;
46
- const groups = (_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
47
- var _a, _b, _c;
48
- if (group.id === groupId) {
49
- 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);
50
- if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
51
- return group;
52
- const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
53
- var _a, _b, _c, _d;
54
- if (option.id === optionId) {
55
- let quantity = ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = option.increment) !== null && _b !== void 0 ? _b : 0);
56
- const quantities = [quantity];
57
- if (option.max !== 0)
58
- quantities.push(((_c = option.max) !== null && _c !== void 0 ? _c : 0));
59
- if (group.max !== 0)
60
- quantities.push(((_d = group.max) !== null && _d !== void 0 ? _d : 0) - (count !== null && count !== void 0 ? count : 0));
61
- quantity = Math.min(...quantities);
62
- return Object.assign(Object.assign({}, option), { quantity });
63
- }
64
- return option;
65
- });
66
- return Object.assign(Object.assign({}, group), { options });
67
- }
39
+ const incrementGroupOption = (group, optionId) => {
40
+ const count = group.options
41
+ .filter(o => o.id !== optionId)
42
+ .reduce((t, o) => t + o.quantity, 0);
43
+ if (group.max !== 0 && count >= group.max)
68
44
  return group;
45
+ const options = group.options.map(option => {
46
+ if (option.id === optionId) {
47
+ let quantity = option.quantity + option.increment;
48
+ const quantities = [quantity];
49
+ if (option.max !== 0)
50
+ quantities.push(option.max);
51
+ if (group.max !== 0)
52
+ quantities.push(group.max - count);
53
+ quantity = Math.min(...quantities);
54
+ return Object.assign(Object.assign({}, option), { quantity });
55
+ }
56
+ return option;
69
57
  });
70
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups })));
58
+ return Object.assign(Object.assign({}, group), { options });
71
59
  };
72
- const decrementOption = (groupId, optionId) => {
73
- var _a;
74
- const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
75
- var _a;
76
- if (group.id === groupId) {
77
- const options = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
78
- var _a, _b;
79
- if (option.id === optionId) {
80
- const quantity = Math.max(((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = option.increment) !== null && _b !== void 0 ? _b : 0), 0);
81
- return Object.assign(Object.assign({}, option), { quantity });
82
- }
83
- return option;
84
- });
85
- return Object.assign(Object.assign({}, group), { options });
60
+ const decrementGroupOption = (group, optionId) => {
61
+ const options = group.options.map(option => {
62
+ if (option.id === optionId) {
63
+ const quantity = Math.max(option.quantity - option.increment, 0);
64
+ return Object.assign(Object.assign({}, option), { quantity });
86
65
  }
66
+ return option;
67
+ });
68
+ return Object.assign(Object.assign({}, group), { options });
69
+ };
70
+ const setGroupOptionQuantity = (group, optionId, quantity) => {
71
+ if (quantity === undefined)
72
+ return group;
73
+ const count = group.options
74
+ .filter(o => o.id !== optionId)
75
+ .reduce((t, o) => t + o.quantity, 0);
76
+ if (group.max !== 0 && count >= group.max)
87
77
  return group;
78
+ const options = group.options.map(option => {
79
+ if (option.id === optionId) {
80
+ const quantities = quantity ? [quantity] : [0];
81
+ if (option.max !== 0)
82
+ quantities.push(option.max);
83
+ if (group.max !== 0)
84
+ quantities.push(group.max - count);
85
+ quantity = Math.min(...quantities);
86
+ quantity = Math.max(quantity, option.min);
87
+ return Object.assign(Object.assign({}, option), { quantity });
88
+ }
89
+ return option;
88
90
  });
89
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups })));
91
+ return Object.assign(Object.assign({}, group), { options });
90
92
  };
91
- const setOptionQuantity = (groupId, optionId, quantity, nested) => {
92
- var _a;
93
- const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
94
- var _a, _b, _c;
93
+ const updateGroups = (groups, levels, fn, quantity) => {
94
+ const [[groupId, optionId], ...rest] = levels;
95
+ return groups.map(group => {
95
96
  if (group.id === groupId) {
96
- 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);
97
- if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
98
- return group;
99
- const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
100
- var _a, _b, _c;
101
- const optionGroups = nested || option.groups || [];
97
+ if (!rest.length)
98
+ return fn(group, optionId, quantity);
99
+ const options = group.options.map(option => {
102
100
  if (option.id === optionId) {
103
- if (`${quantity}` === '') {
104
- return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
105
- }
106
- else {
107
- const quantities = [quantity];
108
- if (option.max !== 0)
109
- quantities.push(((_a = option.max) !== null && _a !== void 0 ? _a : 0));
110
- if (group.max !== 0)
111
- quantities.push(((_b = group.max) !== null && _b !== void 0 ? _b : 0) - (count !== null && count !== void 0 ? count : 0));
112
- quantity = Math.min(...quantities);
113
- quantity = Math.max(quantity, ((_c = option.min) !== null && _c !== void 0 ? _c : 0));
114
- return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
115
- }
101
+ return Object.assign(Object.assign({}, option), { groups: updateGroups(option.groups, rest, fn) });
116
102
  }
117
103
  return option;
118
104
  });
@@ -120,7 +106,26 @@ const useBuilder = (orderItem) => {
120
106
  }
121
107
  return group;
122
108
  });
123
- setItem((0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups })));
109
+ };
110
+ const toggleOption = (levels) => {
111
+ const groups = updateGroups(item.groups, levels, toggleGroupOption);
112
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
113
+ setItem(pricedItem);
114
+ };
115
+ const incrementOption = (levels) => {
116
+ const groups = updateGroups(item.groups, levels, incrementGroupOption);
117
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
118
+ setItem(pricedItem);
119
+ };
120
+ const decrementOption = (levels) => {
121
+ const groups = updateGroups(item.groups, levels, decrementGroupOption);
122
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
123
+ setItem(pricedItem);
124
+ };
125
+ const setOptionQuantity = (levels, quantity) => {
126
+ const groups = updateGroups(item.groups, levels, setGroupOptionQuantity, quantity);
127
+ const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups: groups }));
128
+ setItem(pricedItem);
124
129
  };
125
130
  return {
126
131
  item,
@@ -129,10 +134,11 @@ const useBuilder = (orderItem) => {
129
134
  setQuantity,
130
135
  setMadeFor,
131
136
  setNotes,
137
+ setMadeForNotes,
132
138
  toggleOption,
133
139
  incrementOption,
134
140
  decrementOption,
135
- setOptionQuantity,
141
+ setOptionQuantity
136
142
  };
137
143
  };
138
144
  exports.useBuilder = useBuilder;
@@ -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
  };
@@ -2,35 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOrderItem = void 0;
4
4
  const utils_1 = require("../../utils");
5
- const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts = [], displaySettings = {}, cartCounts = {}, isMobile = true) => {
6
- var _a, _b, _c, _d, _e;
7
- const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile, } = displaySettings;
5
+ const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySettings, cartCounts = {}, isMobile = true) => {
6
+ const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile } = displaySettings;
8
7
  const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
9
- const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, } = orderItem;
10
- const cartCount = orderItem.id ? cartCounts[orderItem.id] : 0;
11
- const isSoldOut = orderItem.id ? soldOut.includes(orderItem.id) : false;
12
- const displayTags = showTags && (tags === null || tags === void 0 ? void 0 : tags.length) ? tags : [];
13
- const displayAllergens = showAllergens && (allergens === null || allergens === void 0 ? void 0 : allergens.length) ? allergens : [];
14
- const contains = allergens === null || allergens === void 0 ? void 0 : allergens.filter((allergen) => allergenAlerts.includes(allergen));
15
- const allergenAlert = (contains === null || contains === void 0 ? void 0 : contains.length) ? `${contains.join(', ')}` : null;
16
- const sizeGroup = groups === null || groups === void 0 ? void 0 : groups.find((i) => i.isSize);
17
- const sizeOnly = sizeGroup && (groups === null || groups === void 0 ? void 0 : groups.length) === 1;
8
+ const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, isSoldOut } = orderItem;
9
+ const cartCount = cartCounts[orderItem.id] || 0;
10
+ const displayTags = showTags && tags.length ? tags : [];
11
+ const displayAllergens = showAllergens && allergens.length ? allergens : [];
12
+ const contains = allergens.filter(allergen => allergenAlerts.includes(allergen));
13
+ const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
14
+ const sizeGroup = groups.find(i => i.isSize);
15
+ const sizeOnly = sizeGroup && groups.length === 1;
18
16
  const defaultOption = !sizeGroup
19
17
  ? null
20
- : ((_a = sizeGroup === null || sizeGroup === void 0 ? void 0 : sizeGroup.options) === null || _a === void 0 ? void 0 : _a.find((i) => i.isDefault)) || sizeGroup.options[0];
18
+ : sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
21
19
  const currentPrice = totalPrice
22
20
  ? totalPrice
23
21
  : defaultOption
24
22
  ? defaultOption.price
25
23
  : price;
26
- const displayPrice = (0, utils_1.formatDollars)(`${currentPrice}`);
24
+ const displayPrice = (0, utils_1.formatDollars)(currentPrice.toString());
27
25
  const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
28
26
  const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
29
- 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;
30
- const isIncomplete = totalPrice === 0 || `${quantity}` === '' || groupsBelowMin;
31
- const nonSizeGroups = groups === null || groups === void 0 ? void 0 : groups.filter((i) => !i.isSize);
27
+ const groupsBelowMin = (0, utils_1.hasGroupsBelowMin)(null, groups);
28
+ const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
29
+ const nonSizeGroups = groups.filter(i => !i.isSize);
32
30
  const currentOptions = (0, utils_1.getItemOptions)({ groups: nonSizeGroups });
33
- const hasSelections = ((_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.length) !== null && _c !== void 0 ? _c : 0) > 0;
31
+ const hasSelections = currentOptions.length > 0;
34
32
  const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
35
33
  const desc = showDesc === 'HIDE'
36
34
  ? ''
@@ -38,11 +36,12 @@ const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts =
38
36
  ? shortDescription
39
37
  : description;
40
38
  const optionNames = favorite
41
- ? (_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) => {
42
- var _a, _b;
43
- const names = (_b = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((o) => o.name)) !== null && _b !== void 0 ? _b : [];
39
+ ? favorite.item.groups
40
+ .reduce((arr, group) => {
41
+ const names = group.options.map(o => o.name);
44
42
  return [...arr, ...names];
45
- }, []).join(', ')
43
+ }, [])
44
+ .join(', ')
46
45
  : null;
47
46
  const displayDesc = optionNames || desc;
48
47
  return Object.assign(Object.assign({}, orderItem), { showImage,
@@ -15,7 +15,7 @@ const useAddressForm = (address, loading, error, update, callback) => {
15
15
  { label: 'Contact Phone', name: 'phone', type: 'phone-pad' },
16
16
  { label: 'Description', name: 'description', type: 'default' },
17
17
  { label: 'Notes', name: 'notes', type: 'default' },
18
- { label: 'Is Default', name: 'is_default', type: 'checkbox' },
18
+ { label: 'Is Default', name: 'is_default', type: 'checkbox' }
19
19
  ];
20
20
  (0, react_1.useEffect)(() => {
21
21
  var _a, _b;
@@ -44,7 +44,7 @@ const useAllergenForm = (allergens, selectedAllergens, isLoading = false, error
44
44
  allergenIds,
45
45
  formError,
46
46
  handleChange,
47
- handleSubmit,
47
+ handleSubmit
48
48
  };
49
49
  };
50
50
  exports.useAllergenForm = useAllergenForm;
@@ -9,7 +9,7 @@ const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
9
9
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
10
10
  const fields = [
11
11
  { label: 'First Name', name: 'first_name', type: 'text', required: true },
12
- { label: 'Last Name', name: 'last_name', type: 'text', required: true },
12
+ { label: 'Last Name', name: 'last_name', type: 'text', required: true }
13
13
  ];
14
14
  (0, react_1.useEffect)(() => {
15
15
  return () => {
@@ -42,7 +42,7 @@ const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
42
42
  data,
43
43
  submitting,
44
44
  handleChange,
45
- handleSubmit,
45
+ handleSubmit
46
46
  };
47
47
  };
48
48
  exports.useCartGuestForm = useCartGuestForm;
@@ -37,7 +37,7 @@ const useLoginForm = (loading, error, login, callback) => {
37
37
  data,
38
38
  submitting,
39
39
  handleChange,
40
- handleSubmit,
40
+ handleSubmit
41
41
  };
42
42
  };
43
43
  exports.useLoginForm = useLoginForm;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CreditCardData } from '@open-tender/types';
3
- declare const useCreditCard: (initState: any, cardErrors?: {}, disabled?: boolean) => {
3
+ export declare const useCreditCard: (initState: any, cardErrors?: {}, disabled?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<null>;
5
5
  data: CreditCardData;
6
6
  cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
@@ -11,4 +11,3 @@ declare const useCreditCard: (initState: any, cardErrors?: {}, disabled?: boolea
11
11
  handleBlur: (evt?: any) => void;
12
12
  isComplete: boolean;
13
13
  };
14
- export default useCreditCard;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCreditCard = void 0;
3
4
  const react_1 = require("react");
4
5
  const __1 = require("../");
5
6
  const defaultState = {
@@ -7,7 +8,7 @@ const defaultState = {
7
8
  exp: '',
8
9
  cvv: '',
9
10
  zip: '',
10
- is_default: false,
11
+ is_default: false
11
12
  };
12
13
  const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
13
14
  const [initCard, initCardType] = (0, __1.formatCard)(initState);
@@ -51,7 +52,7 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
51
52
  setErrors,
52
53
  handleChange,
53
54
  handleBlur,
54
- isComplete,
55
+ isComplete
55
56
  };
56
57
  };
57
- exports.default = useCreditCard;
58
+ exports.useCreditCard = useCreditCard;
@@ -38,7 +38,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
38
38
  if (!token) {
39
39
  setSubmitting(false);
40
40
  setErrors({
41
- form: 'Please complete the recaptcha before submitting',
41
+ form: 'Please complete the recaptcha before submitting'
42
42
  });
43
43
  if (windowRef)
44
44
  windowRef.scrollTo({ top: 0 });
@@ -51,7 +51,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
51
51
  catch (err) {
52
52
  setSubmitting(false);
53
53
  setErrors({
54
- form: 'Please complete the recaptcha before submitting',
54
+ form: 'Please complete the recaptcha before submitting'
55
55
  });
56
56
  if (windowRef)
57
57
  windowRef.scrollTo({ top: 0 });
@@ -69,7 +69,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
69
69
  recaptchaRef,
70
70
  data,
71
71
  submitting,
72
- handleSubmit,
72
+ handleSubmit
73
73
  };
74
74
  };
75
75
  exports.useCreditCardForm = useCreditCardForm;
@@ -33,7 +33,7 @@ const useCurbside = (orderId, fulfillment, loading, error, update, settings, sho
33
33
  errors,
34
34
  submitting,
35
35
  handleChange,
36
- handleSubmit,
36
+ handleSubmit
37
37
  };
38
38
  };
39
39
  exports.useCurbside = useCurbside;
@@ -27,7 +27,7 @@ const useDineInForm = (initialData = {}, submitGuest) => {
27
27
  data,
28
28
  errMsg,
29
29
  handleChange,
30
- handleSubmit,
30
+ handleSubmit
31
31
  };
32
32
  };
33
33
  exports.useDineInForm = useDineInForm;
@@ -43,7 +43,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
43
43
  if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
44
44
  const options = creditCards.map(i => ({
45
45
  label: `${i.card_type_name} ending in ${i.last4}`,
46
- value: i.customer_card_id,
46
+ value: i.customer_card_id
47
47
  }));
48
48
  setCreditCardOptions(options);
49
49
  const defaultCard = creditCards.length
@@ -70,7 +70,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
70
70
  const purchaseWithCaptcha = (credit_card) => {
71
71
  const alert = {
72
72
  type: 'working',
73
- args: { text: 'Submitting your contribution...' },
73
+ args: { text: 'Submitting your contribution...' }
74
74
  };
75
75
  if (recaptchaKey) {
76
76
  try {
@@ -87,7 +87,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
87
87
  amount: amount,
88
88
  email: email,
89
89
  credit_card,
90
- token: token,
90
+ token: token
91
91
  });
92
92
  }
93
93
  }
@@ -104,7 +104,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
104
104
  amount: amount,
105
105
  email: email,
106
106
  credit_card,
107
- token: '',
107
+ token: ''
108
108
  });
109
109
  }
110
110
  };
@@ -165,7 +165,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
165
165
  handleCreditCard,
166
166
  handleSubmit,
167
167
  handleReset,
168
- setErrors,
168
+ setErrors
169
169
  };
170
170
  };
171
171
  exports.useDonationsForm = useDonationsForm;
@@ -42,7 +42,7 @@ const useGiftCardAssignForm = (loading, error, assign, callback) => {
42
42
  errors,
43
43
  submitting,
44
44
  handleChange,
45
- handleSubmit,
45
+ handleSubmit
46
46
  };
47
47
  };
48
48
  exports.useGiftCardAssignForm = useGiftCardAssignForm;
@@ -35,7 +35,7 @@ const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, callback
35
35
  errors,
36
36
  submitting,
37
37
  handleChange,
38
- handleSubmit,
38
+ handleSubmit
39
39
  };
40
40
  };
41
41
  exports.useGiftCardAssignOtherForm = useGiftCardAssignOtherForm;
@@ -6,13 +6,15 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
6
6
  const submitRef = (0, react_1.useRef)(null);
7
7
  const inputRef = (0, react_1.useRef)(null);
8
8
  const customerCardId = creditCards[0].customer_card_id;
9
- const [data, setData] = (0, react_1.useState)({ customer_card_id: customerCardId });
9
+ const [data, setData] = (0, react_1.useState)({
10
+ customer_card_id: customerCardId
11
+ });
10
12
  const [errors, setErrors] = (0, react_1.useState)({});
11
13
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
12
- const options = creditCards.map((i) => {
14
+ const options = creditCards.map(i => {
13
15
  return {
14
16
  name: `${i.card_type_name} ending in ${i.last4}`,
15
- value: i.customer_card_id,
17
+ value: i.customer_card_id
16
18
  };
17
19
  });
18
20
  (0, react_1.useEffect)(() => {
@@ -53,7 +55,7 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
53
55
  data,
54
56
  submitting,
55
57
  handleChange,
56
- handleSubmit,
58
+ handleSubmit
57
59
  };
58
60
  };
59
61
  exports.useGiftCardForm = useGiftCardForm;