@open-tender/utils 0.0.15 → 0.0.17
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CartCounts, Favorite, CartItem, SoldOut } from "@open-tender/types";
|
|
2
|
-
export declare const useOrderItem: (orderItem: CartItem
|
|
3
|
-
showImage:
|
|
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
4
|
displayDesc: any;
|
|
5
5
|
displayTags: string[];
|
|
6
6
|
displayAllergens: string[];
|
|
@@ -10,7 +10,7 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: Favorite | n
|
|
|
10
10
|
isSoldOut: boolean;
|
|
11
11
|
allergenAlert: string | null;
|
|
12
12
|
hasSelections: boolean;
|
|
13
|
-
showQuickAdd:
|
|
13
|
+
showQuickAdd: boolean | undefined;
|
|
14
14
|
sizeOnly: boolean | undefined;
|
|
15
15
|
cartCount: number;
|
|
16
16
|
index?: number | undefined;
|
|
@@ -18,32 +18,32 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: Favorite | n
|
|
|
18
18
|
name?: string | undefined;
|
|
19
19
|
shortName?: string | undefined;
|
|
20
20
|
cart_guest_id?: number | null | undefined;
|
|
21
|
-
category
|
|
21
|
+
category?: string | null | undefined;
|
|
22
22
|
customer_id?: number | null | undefined;
|
|
23
|
-
description
|
|
24
|
-
imageUrl
|
|
25
|
-
slug
|
|
26
|
-
allergens
|
|
27
|
-
tags
|
|
28
|
-
ingredients
|
|
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
29
|
madeFor?: string | null | undefined;
|
|
30
30
|
notes?: string | null | undefined;
|
|
31
|
-
nutritionalInfo
|
|
32
|
-
cals
|
|
33
|
-
groups
|
|
34
|
-
quantity
|
|
35
|
-
price
|
|
36
|
-
increment
|
|
37
|
-
max
|
|
38
|
-
min
|
|
39
|
-
points
|
|
40
|
-
upsellItems
|
|
41
|
-
similarItems
|
|
42
|
-
totalPrice
|
|
43
|
-
totalPoints
|
|
44
|
-
totalCals
|
|
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?: number | null | undefined;
|
|
40
|
+
upsellItems?: number[] | undefined;
|
|
41
|
+
similarItems?: number[] | undefined;
|
|
42
|
+
totalPrice?: number | undefined;
|
|
43
|
+
totalPoints?: number | null | undefined;
|
|
44
|
+
totalCals?: number | null | undefined;
|
|
45
45
|
item_no?: number | undefined;
|
|
46
|
-
nutritional_info
|
|
46
|
+
nutritional_info?: import("@open-tender/types").NutritionalInfo | null | undefined;
|
|
47
47
|
price_total?: number | undefined;
|
|
48
48
|
favorite_id?: number | undefined;
|
|
49
49
|
images?: import("@open-tender/types").OrderItemImages | undefined;
|
|
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useOrderItem = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts = [], displaySettings = {}, cartCounts = {}, isMobile = true) => {
|
|
6
|
-
var _a, _b, _c, _d;
|
|
6
|
+
var _a, _b, _c, _d, _e;
|
|
7
7
|
const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile, } = displaySettings;
|
|
8
8
|
const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
|
|
9
9
|
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, } = orderItem;
|
|
10
10
|
const cartCount = orderItem.id ? cartCounts[orderItem.id] : 0;
|
|
11
11
|
const isSoldOut = orderItem.id ? soldOut.includes(orderItem.id) : false;
|
|
12
|
-
const displayTags = showTags && tags.length ? tags : [];
|
|
13
|
-
const displayAllergens = showAllergens && allergens.length ? allergens : [];
|
|
14
|
-
const contains = allergens.filter((allergen) => allergenAlerts.includes(allergen));
|
|
15
|
-
const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
|
|
16
|
-
const sizeGroup = groups.find((i) => i.isSize);
|
|
17
|
-
const sizeOnly = sizeGroup && groups.length === 1;
|
|
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;
|
|
18
18
|
const defaultOption = !sizeGroup
|
|
19
19
|
? null
|
|
20
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];
|
|
@@ -26,11 +26,11 @@ const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts =
|
|
|
26
26
|
const displayPrice = (0, utils_1.formatDollars)(`${currentPrice}`);
|
|
27
27
|
const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
|
|
28
28
|
const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
|
|
29
|
-
const groupsBelowMin = 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 > 0;
|
|
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
30
|
const isIncomplete = totalPrice === 0 || `${quantity}` === '' || groupsBelowMin;
|
|
31
|
-
const nonSizeGroups = groups.filter((i) => !i.isSize);
|
|
31
|
+
const nonSizeGroups = groups === null || groups === void 0 ? void 0 : groups.filter((i) => !i.isSize);
|
|
32
32
|
const currentOptions = (0, utils_1.getItemOptions)({ groups: nonSizeGroups });
|
|
33
|
-
const hasSelections = ((
|
|
33
|
+
const hasSelections = ((_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.length) !== null && _c !== void 0 ? _c : 0) > 0;
|
|
34
34
|
const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
|
|
35
35
|
const desc = showDesc === 'HIDE'
|
|
36
36
|
? ''
|
|
@@ -38,7 +38,7 @@ const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts =
|
|
|
38
38
|
? shortDescription
|
|
39
39
|
: description;
|
|
40
40
|
const optionNames = favorite
|
|
41
|
-
? (
|
|
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
42
|
const names = group.options.map((o) => o.name);
|
|
43
43
|
return [...arr, ...names];
|
|
44
44
|
}, []).join(', ')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CartCounts, Favorite, CartItem, SoldOut } from "@open-tender/types";
|
|
2
|
-
export declare const useOrderItem: (orderItem: CartItem
|
|
3
|
-
showImage:
|
|
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
4
|
displayDesc: any;
|
|
5
5
|
displayTags: string[];
|
|
6
6
|
displayAllergens: string[];
|
|
@@ -10,7 +10,7 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: Favorite | n
|
|
|
10
10
|
isSoldOut: boolean;
|
|
11
11
|
allergenAlert: string | null;
|
|
12
12
|
hasSelections: boolean;
|
|
13
|
-
showQuickAdd:
|
|
13
|
+
showQuickAdd: boolean | undefined;
|
|
14
14
|
sizeOnly: boolean | undefined;
|
|
15
15
|
cartCount: number;
|
|
16
16
|
index?: number | undefined;
|
|
@@ -18,32 +18,32 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: Favorite | n
|
|
|
18
18
|
name?: string | undefined;
|
|
19
19
|
shortName?: string | undefined;
|
|
20
20
|
cart_guest_id?: number | null | undefined;
|
|
21
|
-
category
|
|
21
|
+
category?: string | null | undefined;
|
|
22
22
|
customer_id?: number | null | undefined;
|
|
23
|
-
description
|
|
24
|
-
imageUrl
|
|
25
|
-
slug
|
|
26
|
-
allergens
|
|
27
|
-
tags
|
|
28
|
-
ingredients
|
|
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
29
|
madeFor?: string | null | undefined;
|
|
30
30
|
notes?: string | null | undefined;
|
|
31
|
-
nutritionalInfo
|
|
32
|
-
cals
|
|
33
|
-
groups
|
|
34
|
-
quantity
|
|
35
|
-
price
|
|
36
|
-
increment
|
|
37
|
-
max
|
|
38
|
-
min
|
|
39
|
-
points
|
|
40
|
-
upsellItems
|
|
41
|
-
similarItems
|
|
42
|
-
totalPrice
|
|
43
|
-
totalPoints
|
|
44
|
-
totalCals
|
|
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?: number | null | undefined;
|
|
40
|
+
upsellItems?: number[] | undefined;
|
|
41
|
+
similarItems?: number[] | undefined;
|
|
42
|
+
totalPrice?: number | undefined;
|
|
43
|
+
totalPoints?: number | null | undefined;
|
|
44
|
+
totalCals?: number | null | undefined;
|
|
45
45
|
item_no?: number | undefined;
|
|
46
|
-
nutritional_info
|
|
46
|
+
nutritional_info?: import("@open-tender/types").NutritionalInfo | null | undefined;
|
|
47
47
|
price_total?: number | undefined;
|
|
48
48
|
favorite_id?: number | undefined;
|
|
49
49
|
images?: import("@open-tender/types").OrderItemImages | undefined;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { formatDollars, getItemOptions } from "../../utils";
|
|
2
2
|
export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts = [], displaySettings = {}, cartCounts = {}, isMobile = true) => {
|
|
3
|
-
var _a, _b, _c, _d;
|
|
3
|
+
var _a, _b, _c, _d, _e;
|
|
4
4
|
const { menuImages: showImage, calories: showCals, tags: showTags, allergens: showAllergens, quickAdd, quickAddMobile, menuItemDescription, menuItemDescriptionMobile, } = displaySettings;
|
|
5
5
|
const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
|
|
6
6
|
const { description, shortDescription, quantity, price, totalPrice, cals, totalCals, tags, allergens, groups, } = orderItem;
|
|
7
7
|
const cartCount = orderItem.id ? cartCounts[orderItem.id] : 0;
|
|
8
8
|
const isSoldOut = orderItem.id ? soldOut.includes(orderItem.id) : false;
|
|
9
|
-
const displayTags = showTags && tags.length ? tags : [];
|
|
10
|
-
const displayAllergens = showAllergens && allergens.length ? allergens : [];
|
|
11
|
-
const contains = allergens.filter((allergen) => allergenAlerts.includes(allergen));
|
|
12
|
-
const allergenAlert = contains.length ? `${contains.join(', ')}` : null;
|
|
13
|
-
const sizeGroup = groups.find((i) => i.isSize);
|
|
14
|
-
const sizeOnly = sizeGroup && groups.length === 1;
|
|
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;
|
|
15
15
|
const defaultOption = !sizeGroup
|
|
16
16
|
? null
|
|
17
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];
|
|
@@ -23,11 +23,11 @@ export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenA
|
|
|
23
23
|
const displayPrice = formatDollars(`${currentPrice}`);
|
|
24
24
|
const itemCals = showCals ? (totalPrice ? totalCals : cals) : null;
|
|
25
25
|
const displayCals = itemCals ? `${itemCals.toFixed(0)}` : null;
|
|
26
|
-
const groupsBelowMin = 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 > 0;
|
|
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
27
|
const isIncomplete = totalPrice === 0 || `${quantity}` === '' || groupsBelowMin;
|
|
28
|
-
const nonSizeGroups = groups.filter((i) => !i.isSize);
|
|
28
|
+
const nonSizeGroups = groups === null || groups === void 0 ? void 0 : groups.filter((i) => !i.isSize);
|
|
29
29
|
const currentOptions = getItemOptions({ groups: nonSizeGroups });
|
|
30
|
-
const hasSelections = ((
|
|
30
|
+
const hasSelections = ((_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.length) !== null && _c !== void 0 ? _c : 0) > 0;
|
|
31
31
|
const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
|
|
32
32
|
const desc = showDesc === 'HIDE'
|
|
33
33
|
? ''
|
|
@@ -35,7 +35,7 @@ export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenA
|
|
|
35
35
|
? shortDescription
|
|
36
36
|
: description;
|
|
37
37
|
const optionNames = favorite
|
|
38
|
-
? (
|
|
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
39
|
const names = group.options.map((o) => o.name);
|
|
40
40
|
return [...arr, ...names];
|
|
41
41
|
}, []).join(', ')
|
package/package.json
CHANGED