@open-tender/utils 0.1.118 → 0.1.120

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 (34) hide show
  1. package/dist/.DS_Store +0 -0
  2. package/dist/cjs/hooks/index.d.ts +6 -1
  3. package/dist/cjs/hooks/index.js +6 -1
  4. package/dist/cjs/hooks/useAccordion.d.ts +22 -0
  5. package/dist/cjs/hooks/useAccordion.js +56 -0
  6. package/dist/cjs/hooks/{menu/useBuilder.js → useBuilder.js} +1 -1
  7. package/dist/cjs/hooks/useMenuItem.d.ts +53 -0
  8. package/dist/cjs/hooks/useMenuItem.js +66 -0
  9. package/dist/cjs/hooks/useModifier.d.ts +49 -0
  10. package/dist/cjs/hooks/useModifier.js +72 -0
  11. package/dist/cjs/hooks/useModifierGroup.d.ts +15 -0
  12. package/dist/cjs/hooks/useModifierGroup.js +17 -0
  13. package/dist/cjs/hooks/{menu/useOrderItem.js → useOrderItem.js} +1 -1
  14. package/dist/esm/hooks/index.d.ts +6 -1
  15. package/dist/esm/hooks/index.js +6 -1
  16. package/dist/esm/hooks/useAccordion.d.ts +22 -0
  17. package/dist/esm/hooks/useAccordion.js +52 -0
  18. package/dist/esm/hooks/{menu/useBuilder.js → useBuilder.js} +1 -1
  19. package/dist/esm/hooks/useMenuItem.d.ts +53 -0
  20. package/dist/esm/hooks/useMenuItem.js +62 -0
  21. package/dist/esm/hooks/useModifier.d.ts +49 -0
  22. package/dist/esm/hooks/useModifier.js +68 -0
  23. package/dist/esm/hooks/useModifierGroup.d.ts +15 -0
  24. package/dist/esm/hooks/useModifierGroup.js +13 -0
  25. package/dist/esm/hooks/{menu/useOrderItem.js → useOrderItem.js} +1 -1
  26. package/package.json +1 -1
  27. package/dist/cjs/hooks/menu/index.d.ts +0 -2
  28. package/dist/cjs/hooks/menu/index.js +0 -5
  29. package/dist/esm/hooks/menu/index.d.ts +0 -2
  30. package/dist/esm/hooks/menu/index.js +0 -2
  31. /package/dist/cjs/hooks/{menu/useBuilder.d.ts → useBuilder.d.ts} +0 -0
  32. /package/dist/cjs/hooks/{menu/useOrderItem.d.ts → useOrderItem.d.ts} +0 -0
  33. /package/dist/esm/hooks/{menu/useBuilder.d.ts → useBuilder.d.ts} +0 -0
  34. /package/dist/esm/hooks/{menu/useOrderItem.d.ts → useOrderItem.d.ts} +0 -0
package/dist/.DS_Store ADDED
Binary file
@@ -1,7 +1,8 @@
1
- export * from './menu';
2
1
  export * from './types';
2
+ export * from './useAccordion';
3
3
  export * from './useAddressForm';
4
4
  export * from './useAllergenForm';
5
+ export * from './useBuilder';
5
6
  export * from './useCartGuestForm';
6
7
  export * from './useLoginForm';
7
8
  export * from './useCreditCard';
@@ -16,7 +17,11 @@ export * from './useGiftCardForm';
16
17
  export * from './useGiftCardsForm';
17
18
  export * from './useGuestForm';
18
19
  export * from './useImage';
20
+ export * from './useMenuItem';
21
+ export * from './useModifier';
22
+ export * from './useModifierGroup';
19
23
  export * from './useOrderFulfillmentForm';
24
+ export * from './useOrderItem';
20
25
  export * from './useOrderRating';
21
26
  export * from './useOrderRatingForm';
22
27
  export * from './useProfileForm';
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./menu"), exports);
5
4
  tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./useAccordion"), exports);
6
6
  tslib_1.__exportStar(require("./useAddressForm"), exports);
7
7
  tslib_1.__exportStar(require("./useAllergenForm"), exports);
8
+ tslib_1.__exportStar(require("./useBuilder"), exports);
8
9
  tslib_1.__exportStar(require("./useCartGuestForm"), exports);
9
10
  tslib_1.__exportStar(require("./useLoginForm"), exports);
10
11
  tslib_1.__exportStar(require("./useCreditCard"), exports);
@@ -19,7 +20,11 @@ tslib_1.__exportStar(require("./useGiftCardForm"), exports);
19
20
  tslib_1.__exportStar(require("./useGiftCardsForm"), exports);
20
21
  tslib_1.__exportStar(require("./useGuestForm"), exports);
21
22
  tslib_1.__exportStar(require("./useImage"), exports);
23
+ tslib_1.__exportStar(require("./useMenuItem"), exports);
24
+ tslib_1.__exportStar(require("./useModifier"), exports);
25
+ tslib_1.__exportStar(require("./useModifierGroup"), exports);
22
26
  tslib_1.__exportStar(require("./useOrderFulfillmentForm"), exports);
27
+ tslib_1.__exportStar(require("./useOrderItem"), exports);
23
28
  tslib_1.__exportStar(require("./useOrderRating"), exports);
24
29
  tslib_1.__exportStar(require("./useOrderRatingForm"), exports);
25
30
  tslib_1.__exportStar(require("./useProfileForm"), exports);
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ import { CartItem, CartLevels, ConfigDisplaySetting } from '@open-tender/types';
3
+ export declare const useAccordion: (builtItem: CartItem, toggleOption: (levels: CartLevels) => void, cartId: number | null, displaySettings?: ConfigDisplaySetting, hasCustomize?: boolean) => {
4
+ open: string | null;
5
+ setOpen: import("react").Dispatch<import("react").SetStateAction<string | null>>;
6
+ groups: import("@open-tender/types").CartItemGroups;
7
+ ingredients: string | null;
8
+ totalCals: number | null;
9
+ madeFor: string | null;
10
+ notes: string | null;
11
+ hasMadeFor: boolean;
12
+ hasNotes: boolean;
13
+ hasInstructions: boolean;
14
+ hasCals: boolean;
15
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
16
+ hasIngredients: boolean;
17
+ instructionsTitle: string;
18
+ sizeGroup: import("@open-tender/types").CartItemGroup | null | undefined;
19
+ selectedSize: import("@open-tender/types").CartItemOption | null | undefined;
20
+ showAccordion: boolean | import("@open-tender/types").CartItemGroup;
21
+ toggleSize: (optionId: number) => void;
22
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAccordion = void 0;
4
+ const react_1 = require("react");
5
+ const utils_1 = require("../utils");
6
+ const useAccordion = (builtItem, toggleOption, cartId, displaySettings, hasCustomize) => {
7
+ var _a;
8
+ const { calories: showCals = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
9
+ const [open, setOpen] = (0, react_1.useState)(null);
10
+ const { groups, ingredients, totalCals, madeFor, notes } = builtItem;
11
+ const hasMadeFor = showMadeFor && !cartId ? true : false;
12
+ const hasNotes = showNotes ? true : false;
13
+ const hasInstructions = hasMadeFor || hasNotes;
14
+ const hasCals = showCals && totalCals ? true : false;
15
+ const nutritionalInfo = hasCals ? (0, utils_1.calcNutritionalInfo)(builtItem) : null;
16
+ const hasIngredients = ingredients && ingredients.length > 0 ? true : false;
17
+ const instructionsTitle = hasMadeFor && hasNotes
18
+ ? 'Name / Special Instructions'
19
+ : hasMadeFor
20
+ ? 'Name'
21
+ : hasNotes
22
+ ? 'Special Instructions'
23
+ : '';
24
+ const sizeGroup = groups ? groups.find(i => i.isSize) : null;
25
+ const selectedSize = sizeGroup
26
+ ? (_a = sizeGroup === null || sizeGroup === void 0 ? void 0 : sizeGroup.options) === null || _a === void 0 ? void 0 : _a.find(i => { var _a; return ((_a = i.quantity) !== null && _a !== void 0 ? _a : 0) >= 1; })
27
+ : null;
28
+ const showAccordion = sizeGroup || hasCustomize || hasInstructions || hasIngredients || hasCals;
29
+ const toggleSize = (optionId) => {
30
+ if (sizeGroup) {
31
+ toggleOption([[sizeGroup.id, optionId]]);
32
+ setOpen(null);
33
+ }
34
+ };
35
+ return {
36
+ open,
37
+ setOpen,
38
+ groups,
39
+ ingredients,
40
+ totalCals,
41
+ madeFor,
42
+ notes,
43
+ hasMadeFor,
44
+ hasNotes,
45
+ hasInstructions,
46
+ hasCals,
47
+ nutritionalInfo,
48
+ hasIngredients,
49
+ instructionsTitle,
50
+ sizeGroup,
51
+ selectedSize,
52
+ showAccordion,
53
+ toggleSize
54
+ };
55
+ };
56
+ exports.useAccordion = useAccordion;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBuilder = void 0;
4
4
  const react_1 = require("react");
5
- const utils_1 = require("../../utils");
5
+ const utils_1 = require("../utils");
6
6
  const useBuilder = (orderItem) => {
7
7
  const [item, setItem] = (0, react_1.useState)(orderItem);
8
8
  const increment = () => {
@@ -0,0 +1,53 @@
1
+ import { Auth, CartItem, ConfigDisplaySetting, FavoritesLookup } from '@open-tender/types';
2
+ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, lookup: FavoritesLookup, cartId: number | null, displaySettings?: ConfigDisplaySetting) => {
3
+ description: string | null;
4
+ tags: string[];
5
+ allergens: string[];
6
+ displayPrice: string;
7
+ displayCals: number | null;
8
+ totalPoints: number | null;
9
+ auth: Auth | null;
10
+ favoriteId: number | null;
11
+ isIncomplete: boolean;
12
+ hasTagsAllergens: boolean;
13
+ hasTags: boolean;
14
+ hasAllergens: boolean;
15
+ hasGroups: boolean;
16
+ sizeGroup: import("@open-tender/types").CartItemGroup | null | undefined;
17
+ sizeSelected: boolean;
18
+ nonSizeGroups: import("@open-tender/types").CartItemGroup[] | null;
19
+ requiresCustomization: boolean;
20
+ hasCals: boolean;
21
+ hasIngredients: boolean | "" | null;
22
+ hasInfo: boolean | "" | null;
23
+ hasMadeFor: boolean;
24
+ hasNotes: boolean;
25
+ hasSelections: boolean;
26
+ cartGuestId: number | null;
27
+ customerId: number | null;
28
+ index?: number | undefined;
29
+ madeFor: string | null;
30
+ notes: string | null;
31
+ signature?: string | undefined;
32
+ similarItems: number[];
33
+ upsellItems: number[];
34
+ cals: number | null;
35
+ groups: import("@open-tender/types").CartItemGroups;
36
+ id: number;
37
+ imageUrl: string | null;
38
+ increment: number;
39
+ ingredients: string | null;
40
+ isSoldOut: boolean;
41
+ max: number;
42
+ min: number;
43
+ name: string;
44
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
45
+ points: number | null;
46
+ price: number;
47
+ quantity: number;
48
+ shortDescription: string | null;
49
+ shortName: string;
50
+ slug: string;
51
+ totalCals: number | null;
52
+ totalPrice: number | null;
53
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMenuItem = void 0;
4
+ const utils_1 = require("../utils");
5
+ const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) => {
6
+ const signature = (0, utils_1.makeItemSignature)(builtItem);
7
+ const favoriteId = lookup && signature ? lookup[signature] : null;
8
+ const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
9
+ const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients } = builtItem;
10
+ const hasTags = showTags && Array.isArray(tags) && tags.length ? true : false;
11
+ const hasAllergens = showAllergens && Array.isArray(allergens) && allergens.length ? true : false;
12
+ const hasTagsAllergens = hasTags || hasAllergens ? true : false;
13
+ const sizeGroup = groups ? groups.find(i => i.isSize) : null;
14
+ const sizeSelected = !sizeGroup || sizeGroup.options.filter(o => o.quantity > 0).length > 0;
15
+ const defaultOption = !sizeGroup
16
+ ? null
17
+ : sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
18
+ const currentPrice = totalPrice
19
+ ? totalPrice
20
+ : defaultOption
21
+ ? defaultOption.price
22
+ : price;
23
+ const displayPrice = (0, utils_1.formatDollars)(currentPrice.toString());
24
+ const displayCals = showCals ? (totalPrice ? totalCals : cals) : null;
25
+ const missingSize = sizeGroup
26
+ ? !sizeGroup.options.find(i => i.quantity >= 1)
27
+ : false;
28
+ const hasGroups = groups ? groups.filter(g => !g.isSize).length > 0 : false;
29
+ const groupsBelowMin = (0, utils_1.hasGroupsBelowMin)(null, groups);
30
+ const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
31
+ const requiresCustomization = isIncomplete && !missingSize;
32
+ const nonSizeGroups = groups ? groups.filter(i => !i.isSize) : null;
33
+ const currentOptions = nonSizeGroups
34
+ ? (0, utils_1.getItemOptions)(Object.assign(Object.assign({}, builtItem), { groups: nonSizeGroups }))
35
+ : [];
36
+ const hasSelections = currentOptions.length > 0;
37
+ const hasMadeFor = showMadeFor && !cartId ? true : false;
38
+ const hasNotes = showNotes ? true : false;
39
+ const hasIngredients = ingredients && ingredients.length > 0;
40
+ const hasCals = displayCals !== null;
41
+ const hasInfo = hasCals || hasIngredients;
42
+ return Object.assign(Object.assign({}, builtItem), { description,
43
+ tags,
44
+ allergens,
45
+ displayPrice,
46
+ displayCals,
47
+ totalPoints,
48
+ auth,
49
+ favoriteId,
50
+ isIncomplete,
51
+ hasTagsAllergens,
52
+ hasTags,
53
+ hasAllergens,
54
+ hasGroups,
55
+ sizeGroup,
56
+ sizeSelected,
57
+ nonSizeGroups,
58
+ requiresCustomization,
59
+ hasCals,
60
+ hasIngredients,
61
+ hasInfo,
62
+ hasMadeFor,
63
+ hasNotes,
64
+ hasSelections });
65
+ };
66
+ exports.useMenuItem = useMenuItem;
@@ -0,0 +1,49 @@
1
+ import { CartItemGroup, CartItemOption, CartItemOptions, CartLevels, ConfigDisplaySetting } from '@open-tender/types';
2
+ export declare const useModifier: (group: CartItemGroup, option: CartItemOption, levels: CartLevels | undefined, toggleOption: (levels: CartLevels) => void, incrementOption: (levels: CartLevels) => void, decrementOption: (levels: CartLevels) => void, setOptionQuantity: (levels: CartLevels, quantity: number, nested?: CartItemOptions) => void, allergenAlerts: string[], displaySettings?: ConfigDisplaySetting) => {
3
+ price: string | null;
4
+ cals: number | null;
5
+ tags: string[];
6
+ allergens: string[];
7
+ optionGroups: import("@open-tender/types").CartItemGroups | null;
8
+ showImage: boolean;
9
+ showDescription: boolean;
10
+ hasCals: boolean;
11
+ hasIngredients: boolean | "" | null;
12
+ hasInfo: boolean | "" | null;
13
+ allergenAlert: boolean;
14
+ bgStyle: {
15
+ backgroundImage: string;
16
+ } | undefined;
17
+ isCheckbox: boolean;
18
+ isRadio: boolean;
19
+ showGroups: boolean;
20
+ toggle: () => void;
21
+ adjust: (quantity: number) => void;
22
+ increment: () => void;
23
+ decrement: () => void;
24
+ incrementDisabled: boolean;
25
+ decrementDisabled: boolean;
26
+ updatedLevels: CartLevels;
27
+ optionAtMax: boolean;
28
+ groupAtMax: boolean;
29
+ oneOnly: boolean;
30
+ description: string | null;
31
+ groups: import("@open-tender/types").CartItemGroups;
32
+ id: number;
33
+ imageUrl: string | null;
34
+ ingredients: string | null;
35
+ isDefault: boolean;
36
+ isSoldOut: boolean;
37
+ max: number;
38
+ min: number;
39
+ name: string;
40
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
41
+ points: number | null;
42
+ quantity: number;
43
+ shortDescription: string | null;
44
+ shortName: string;
45
+ slug: string;
46
+ totalCals: number | null;
47
+ totalPoints: number | null;
48
+ totalPrice: number | null;
49
+ };
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useModifier = void 0;
4
+ const utils_1 = require("../utils");
5
+ const useModifier = (group, option, levels = [], toggleOption, incrementOption, decrementOption, setOptionQuantity, allergenAlerts, displaySettings) => {
6
+ const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, modifierImage: showImage = true, modifierDescription: showDescription = true } = displaySettings || {};
7
+ const { imageUrl } = option;
8
+ const bgStyle = imageUrl ? { backgroundImage: `url(${imageUrl}` } : undefined;
9
+ const isRadio = group.min === 1 && group.max === 1;
10
+ const isCheckbox = group.options.filter(i => i.max !== 1).length === 0 ||
11
+ (group.max === 1 && !isRadio);
12
+ const groupAtMax = group.max !== 0 && group.quantity === group.max;
13
+ const optionAtMax = option.max !== 0 && option.quantity === option.max;
14
+ const oneOnly = group.max === 1 || option.max === 1;
15
+ const incrementDisabled = groupAtMax || optionAtMax || option.isSoldOut;
16
+ const decrementDisabled = option.quantity === option.min;
17
+ const hidePrice = !option.price ||
18
+ (group.included !== 0 &&
19
+ (group.included === group.max || group.quantity < group.included));
20
+ const price = hidePrice ? null : (0, utils_1.formatDollars)(option.price.toString());
21
+ const cals = showCals ? option.cals : null;
22
+ const allergens = showAllergens ? option.allergens : [];
23
+ const tags = showTags ? option.tags : [];
24
+ const hasIngredients = option.ingredients && option.ingredients.length > 0;
25
+ const hasCals = cals !== null;
26
+ const itemAllergens = allergens && allergens.length
27
+ ? allergens.filter(allergen => allergenAlerts.includes(allergen))
28
+ : [];
29
+ const allergenAlert = itemAllergens.length > 0;
30
+ const optionGroups = option.groups && option.groups.length ? option.groups : null;
31
+ const showGroups = option.quantity >= 1 && optionGroups && !group.isPizza ? true : false;
32
+ const hasInfo = hasCals || hasIngredients;
33
+ const updatedLevels = [...levels, [group.id, option.id]];
34
+ const toggle = () => {
35
+ toggleOption(updatedLevels);
36
+ };
37
+ const increment = () => {
38
+ incrementOption(updatedLevels);
39
+ };
40
+ const decrement = () => {
41
+ decrementOption(updatedLevels);
42
+ };
43
+ const adjust = (quantity) => {
44
+ setOptionQuantity(updatedLevels, quantity);
45
+ };
46
+ return Object.assign(Object.assign({}, option), { price,
47
+ cals,
48
+ tags,
49
+ allergens,
50
+ optionGroups,
51
+ showImage,
52
+ showDescription,
53
+ hasCals,
54
+ hasIngredients,
55
+ hasInfo,
56
+ allergenAlert,
57
+ bgStyle,
58
+ isCheckbox,
59
+ isRadio,
60
+ showGroups,
61
+ toggle,
62
+ adjust,
63
+ increment,
64
+ decrement,
65
+ incrementDisabled,
66
+ decrementDisabled,
67
+ updatedLevels,
68
+ optionAtMax,
69
+ groupAtMax,
70
+ oneOnly });
71
+ };
72
+ exports.useModifier = useModifier;
@@ -0,0 +1,15 @@
1
+ import { CartItemGroup, ConfigDisplaySetting } from '@open-tender/types';
2
+ export declare const useModifierGroup: (group: CartItemGroup, displaySettings?: ConfigDisplaySetting) => {
3
+ description: string | null;
4
+ count: string;
5
+ id: number;
6
+ imageUrl: string | null;
7
+ included: number;
8
+ isPizza: boolean;
9
+ isSize: boolean;
10
+ max: number;
11
+ min: number;
12
+ name: string;
13
+ options: import("@open-tender/types").CartItemOptions;
14
+ quantity: number;
15
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useModifierGroup = void 0;
4
+ const useModifierGroup = (group, displaySettings) => {
5
+ const { modifierGroupDescription = true } = displaySettings || {};
6
+ const description = modifierGroupDescription && group.description ? group.description : null;
7
+ const { quantity, min, max, included } = group;
8
+ const belowMin = quantity < min;
9
+ const suffix = min && belowMin
10
+ ? `, ${min} required`
11
+ : included && quantity < included
12
+ ? `, ${included} included`
13
+ : '';
14
+ const count = `${quantity}${max ? `/${max}` : ' selected'}${suffix}`;
15
+ return Object.assign(Object.assign({}, group), { description, count });
16
+ };
17
+ exports.useModifierGroup = useModifierGroup;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOrderItem = void 0;
4
- const utils_1 = require("../../utils");
4
+ const utils_1 = require("../utils");
5
5
  const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySettings = null, cartCounts = {}, isMobile = true) => {
6
6
  const { menuImages: showImage = true, calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, quickAdd = false, quickAddMobile = false, menuItemDescription = 'SHOW', menuItemDescriptionMobile = 'SHOW' } = displaySettings || {};
7
7
  const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
@@ -1,7 +1,8 @@
1
- export * from './menu';
2
1
  export * from './types';
2
+ export * from './useAccordion';
3
3
  export * from './useAddressForm';
4
4
  export * from './useAllergenForm';
5
+ export * from './useBuilder';
5
6
  export * from './useCartGuestForm';
6
7
  export * from './useLoginForm';
7
8
  export * from './useCreditCard';
@@ -16,7 +17,11 @@ export * from './useGiftCardForm';
16
17
  export * from './useGiftCardsForm';
17
18
  export * from './useGuestForm';
18
19
  export * from './useImage';
20
+ export * from './useMenuItem';
21
+ export * from './useModifier';
22
+ export * from './useModifierGroup';
19
23
  export * from './useOrderFulfillmentForm';
24
+ export * from './useOrderItem';
20
25
  export * from './useOrderRating';
21
26
  export * from './useOrderRatingForm';
22
27
  export * from './useProfileForm';
@@ -1,7 +1,8 @@
1
- export * from './menu';
2
1
  export * from './types';
2
+ export * from './useAccordion';
3
3
  export * from './useAddressForm';
4
4
  export * from './useAllergenForm';
5
+ export * from './useBuilder';
5
6
  export * from './useCartGuestForm';
6
7
  export * from './useLoginForm';
7
8
  export * from './useCreditCard';
@@ -16,7 +17,11 @@ export * from './useGiftCardForm';
16
17
  export * from './useGiftCardsForm';
17
18
  export * from './useGuestForm';
18
19
  export * from './useImage';
20
+ export * from './useMenuItem';
21
+ export * from './useModifier';
22
+ export * from './useModifierGroup';
19
23
  export * from './useOrderFulfillmentForm';
24
+ export * from './useOrderItem';
20
25
  export * from './useOrderRating';
21
26
  export * from './useOrderRatingForm';
22
27
  export * from './useProfileForm';
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ import { CartItem, CartLevels, ConfigDisplaySetting } from '@open-tender/types';
3
+ export declare const useAccordion: (builtItem: CartItem, toggleOption: (levels: CartLevels) => void, cartId: number | null, displaySettings?: ConfigDisplaySetting, hasCustomize?: boolean) => {
4
+ open: string | null;
5
+ setOpen: import("react").Dispatch<import("react").SetStateAction<string | null>>;
6
+ groups: import("@open-tender/types").CartItemGroups;
7
+ ingredients: string | null;
8
+ totalCals: number | null;
9
+ madeFor: string | null;
10
+ notes: string | null;
11
+ hasMadeFor: boolean;
12
+ hasNotes: boolean;
13
+ hasInstructions: boolean;
14
+ hasCals: boolean;
15
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
16
+ hasIngredients: boolean;
17
+ instructionsTitle: string;
18
+ sizeGroup: import("@open-tender/types").CartItemGroup | null | undefined;
19
+ selectedSize: import("@open-tender/types").CartItemOption | null | undefined;
20
+ showAccordion: boolean | import("@open-tender/types").CartItemGroup;
21
+ toggleSize: (optionId: number) => void;
22
+ };
@@ -0,0 +1,52 @@
1
+ import { useState } from 'react';
2
+ import { calcNutritionalInfo } from '../utils';
3
+ export const useAccordion = (builtItem, toggleOption, cartId, displaySettings, hasCustomize) => {
4
+ var _a;
5
+ const { calories: showCals = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
6
+ const [open, setOpen] = useState(null);
7
+ const { groups, ingredients, totalCals, madeFor, notes } = builtItem;
8
+ const hasMadeFor = showMadeFor && !cartId ? true : false;
9
+ const hasNotes = showNotes ? true : false;
10
+ const hasInstructions = hasMadeFor || hasNotes;
11
+ const hasCals = showCals && totalCals ? true : false;
12
+ const nutritionalInfo = hasCals ? calcNutritionalInfo(builtItem) : null;
13
+ const hasIngredients = ingredients && ingredients.length > 0 ? true : false;
14
+ const instructionsTitle = hasMadeFor && hasNotes
15
+ ? 'Name / Special Instructions'
16
+ : hasMadeFor
17
+ ? 'Name'
18
+ : hasNotes
19
+ ? 'Special Instructions'
20
+ : '';
21
+ const sizeGroup = groups ? groups.find(i => i.isSize) : null;
22
+ const selectedSize = sizeGroup
23
+ ? (_a = sizeGroup === null || sizeGroup === void 0 ? void 0 : sizeGroup.options) === null || _a === void 0 ? void 0 : _a.find(i => { var _a; return ((_a = i.quantity) !== null && _a !== void 0 ? _a : 0) >= 1; })
24
+ : null;
25
+ const showAccordion = sizeGroup || hasCustomize || hasInstructions || hasIngredients || hasCals;
26
+ const toggleSize = (optionId) => {
27
+ if (sizeGroup) {
28
+ toggleOption([[sizeGroup.id, optionId]]);
29
+ setOpen(null);
30
+ }
31
+ };
32
+ return {
33
+ open,
34
+ setOpen,
35
+ groups,
36
+ ingredients,
37
+ totalCals,
38
+ madeFor,
39
+ notes,
40
+ hasMadeFor,
41
+ hasNotes,
42
+ hasInstructions,
43
+ hasCals,
44
+ nutritionalInfo,
45
+ hasIngredients,
46
+ instructionsTitle,
47
+ sizeGroup,
48
+ selectedSize,
49
+ showAccordion,
50
+ toggleSize
51
+ };
52
+ };
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react';
2
- import { calcPrices } from '../../utils';
2
+ import { calcPrices } from '../utils';
3
3
  export const useBuilder = (orderItem) => {
4
4
  const [item, setItem] = useState(orderItem);
5
5
  const increment = () => {
@@ -0,0 +1,53 @@
1
+ import { Auth, CartItem, ConfigDisplaySetting, FavoritesLookup } from '@open-tender/types';
2
+ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, lookup: FavoritesLookup, cartId: number | null, displaySettings?: ConfigDisplaySetting) => {
3
+ description: string | null;
4
+ tags: string[];
5
+ allergens: string[];
6
+ displayPrice: string;
7
+ displayCals: number | null;
8
+ totalPoints: number | null;
9
+ auth: Auth | null;
10
+ favoriteId: number | null;
11
+ isIncomplete: boolean;
12
+ hasTagsAllergens: boolean;
13
+ hasTags: boolean;
14
+ hasAllergens: boolean;
15
+ hasGroups: boolean;
16
+ sizeGroup: import("@open-tender/types").CartItemGroup | null | undefined;
17
+ sizeSelected: boolean;
18
+ nonSizeGroups: import("@open-tender/types").CartItemGroup[] | null;
19
+ requiresCustomization: boolean;
20
+ hasCals: boolean;
21
+ hasIngredients: boolean | "" | null;
22
+ hasInfo: boolean | "" | null;
23
+ hasMadeFor: boolean;
24
+ hasNotes: boolean;
25
+ hasSelections: boolean;
26
+ cartGuestId: number | null;
27
+ customerId: number | null;
28
+ index?: number | undefined;
29
+ madeFor: string | null;
30
+ notes: string | null;
31
+ signature?: string | undefined;
32
+ similarItems: number[];
33
+ upsellItems: number[];
34
+ cals: number | null;
35
+ groups: import("@open-tender/types").CartItemGroups;
36
+ id: number;
37
+ imageUrl: string | null;
38
+ increment: number;
39
+ ingredients: string | null;
40
+ isSoldOut: boolean;
41
+ max: number;
42
+ min: number;
43
+ name: string;
44
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
45
+ points: number | null;
46
+ price: number;
47
+ quantity: number;
48
+ shortDescription: string | null;
49
+ shortName: string;
50
+ slug: string;
51
+ totalCals: number | null;
52
+ totalPrice: number | null;
53
+ };
@@ -0,0 +1,62 @@
1
+ import { formatDollars, getItemOptions, hasGroupsBelowMin, makeItemSignature } from '../utils';
2
+ export const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) => {
3
+ const signature = makeItemSignature(builtItem);
4
+ const favoriteId = lookup && signature ? lookup[signature] : null;
5
+ const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
6
+ const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients } = builtItem;
7
+ const hasTags = showTags && Array.isArray(tags) && tags.length ? true : false;
8
+ const hasAllergens = showAllergens && Array.isArray(allergens) && allergens.length ? true : false;
9
+ const hasTagsAllergens = hasTags || hasAllergens ? true : false;
10
+ const sizeGroup = groups ? groups.find(i => i.isSize) : null;
11
+ const sizeSelected = !sizeGroup || sizeGroup.options.filter(o => o.quantity > 0).length > 0;
12
+ const defaultOption = !sizeGroup
13
+ ? null
14
+ : sizeGroup.options.find(i => i.isDefault) || sizeGroup.options[0];
15
+ const currentPrice = totalPrice
16
+ ? totalPrice
17
+ : defaultOption
18
+ ? defaultOption.price
19
+ : price;
20
+ const displayPrice = formatDollars(currentPrice.toString());
21
+ const displayCals = showCals ? (totalPrice ? totalCals : cals) : null;
22
+ const missingSize = sizeGroup
23
+ ? !sizeGroup.options.find(i => i.quantity >= 1)
24
+ : false;
25
+ const hasGroups = groups ? groups.filter(g => !g.isSize).length > 0 : false;
26
+ const groupsBelowMin = hasGroupsBelowMin(null, groups);
27
+ const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
28
+ const requiresCustomization = isIncomplete && !missingSize;
29
+ const nonSizeGroups = groups ? groups.filter(i => !i.isSize) : null;
30
+ const currentOptions = nonSizeGroups
31
+ ? getItemOptions(Object.assign(Object.assign({}, builtItem), { groups: nonSizeGroups }))
32
+ : [];
33
+ const hasSelections = currentOptions.length > 0;
34
+ const hasMadeFor = showMadeFor && !cartId ? true : false;
35
+ const hasNotes = showNotes ? true : false;
36
+ const hasIngredients = ingredients && ingredients.length > 0;
37
+ const hasCals = displayCals !== null;
38
+ const hasInfo = hasCals || hasIngredients;
39
+ return Object.assign(Object.assign({}, builtItem), { description,
40
+ tags,
41
+ allergens,
42
+ displayPrice,
43
+ displayCals,
44
+ totalPoints,
45
+ auth,
46
+ favoriteId,
47
+ isIncomplete,
48
+ hasTagsAllergens,
49
+ hasTags,
50
+ hasAllergens,
51
+ hasGroups,
52
+ sizeGroup,
53
+ sizeSelected,
54
+ nonSizeGroups,
55
+ requiresCustomization,
56
+ hasCals,
57
+ hasIngredients,
58
+ hasInfo,
59
+ hasMadeFor,
60
+ hasNotes,
61
+ hasSelections });
62
+ };
@@ -0,0 +1,49 @@
1
+ import { CartItemGroup, CartItemOption, CartItemOptions, CartLevels, ConfigDisplaySetting } from '@open-tender/types';
2
+ export declare const useModifier: (group: CartItemGroup, option: CartItemOption, levels: CartLevels | undefined, toggleOption: (levels: CartLevels) => void, incrementOption: (levels: CartLevels) => void, decrementOption: (levels: CartLevels) => void, setOptionQuantity: (levels: CartLevels, quantity: number, nested?: CartItemOptions) => void, allergenAlerts: string[], displaySettings?: ConfigDisplaySetting) => {
3
+ price: string | null;
4
+ cals: number | null;
5
+ tags: string[];
6
+ allergens: string[];
7
+ optionGroups: import("@open-tender/types").CartItemGroups | null;
8
+ showImage: boolean;
9
+ showDescription: boolean;
10
+ hasCals: boolean;
11
+ hasIngredients: boolean | "" | null;
12
+ hasInfo: boolean | "" | null;
13
+ allergenAlert: boolean;
14
+ bgStyle: {
15
+ backgroundImage: string;
16
+ } | undefined;
17
+ isCheckbox: boolean;
18
+ isRadio: boolean;
19
+ showGroups: boolean;
20
+ toggle: () => void;
21
+ adjust: (quantity: number) => void;
22
+ increment: () => void;
23
+ decrement: () => void;
24
+ incrementDisabled: boolean;
25
+ decrementDisabled: boolean;
26
+ updatedLevels: CartLevels;
27
+ optionAtMax: boolean;
28
+ groupAtMax: boolean;
29
+ oneOnly: boolean;
30
+ description: string | null;
31
+ groups: import("@open-tender/types").CartItemGroups;
32
+ id: number;
33
+ imageUrl: string | null;
34
+ ingredients: string | null;
35
+ isDefault: boolean;
36
+ isSoldOut: boolean;
37
+ max: number;
38
+ min: number;
39
+ name: string;
40
+ nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
41
+ points: number | null;
42
+ quantity: number;
43
+ shortDescription: string | null;
44
+ shortName: string;
45
+ slug: string;
46
+ totalCals: number | null;
47
+ totalPoints: number | null;
48
+ totalPrice: number | null;
49
+ };
@@ -0,0 +1,68 @@
1
+ import { formatDollars } from '../utils';
2
+ export const useModifier = (group, option, levels = [], toggleOption, incrementOption, decrementOption, setOptionQuantity, allergenAlerts, displaySettings) => {
3
+ const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, modifierImage: showImage = true, modifierDescription: showDescription = true } = displaySettings || {};
4
+ const { imageUrl } = option;
5
+ const bgStyle = imageUrl ? { backgroundImage: `url(${imageUrl}` } : undefined;
6
+ const isRadio = group.min === 1 && group.max === 1;
7
+ const isCheckbox = group.options.filter(i => i.max !== 1).length === 0 ||
8
+ (group.max === 1 && !isRadio);
9
+ const groupAtMax = group.max !== 0 && group.quantity === group.max;
10
+ const optionAtMax = option.max !== 0 && option.quantity === option.max;
11
+ const oneOnly = group.max === 1 || option.max === 1;
12
+ const incrementDisabled = groupAtMax || optionAtMax || option.isSoldOut;
13
+ const decrementDisabled = option.quantity === option.min;
14
+ const hidePrice = !option.price ||
15
+ (group.included !== 0 &&
16
+ (group.included === group.max || group.quantity < group.included));
17
+ const price = hidePrice ? null : formatDollars(option.price.toString());
18
+ const cals = showCals ? option.cals : null;
19
+ const allergens = showAllergens ? option.allergens : [];
20
+ const tags = showTags ? option.tags : [];
21
+ const hasIngredients = option.ingredients && option.ingredients.length > 0;
22
+ const hasCals = cals !== null;
23
+ const itemAllergens = allergens && allergens.length
24
+ ? allergens.filter(allergen => allergenAlerts.includes(allergen))
25
+ : [];
26
+ const allergenAlert = itemAllergens.length > 0;
27
+ const optionGroups = option.groups && option.groups.length ? option.groups : null;
28
+ const showGroups = option.quantity >= 1 && optionGroups && !group.isPizza ? true : false;
29
+ const hasInfo = hasCals || hasIngredients;
30
+ const updatedLevels = [...levels, [group.id, option.id]];
31
+ const toggle = () => {
32
+ toggleOption(updatedLevels);
33
+ };
34
+ const increment = () => {
35
+ incrementOption(updatedLevels);
36
+ };
37
+ const decrement = () => {
38
+ decrementOption(updatedLevels);
39
+ };
40
+ const adjust = (quantity) => {
41
+ setOptionQuantity(updatedLevels, quantity);
42
+ };
43
+ return Object.assign(Object.assign({}, option), { price,
44
+ cals,
45
+ tags,
46
+ allergens,
47
+ optionGroups,
48
+ showImage,
49
+ showDescription,
50
+ hasCals,
51
+ hasIngredients,
52
+ hasInfo,
53
+ allergenAlert,
54
+ bgStyle,
55
+ isCheckbox,
56
+ isRadio,
57
+ showGroups,
58
+ toggle,
59
+ adjust,
60
+ increment,
61
+ decrement,
62
+ incrementDisabled,
63
+ decrementDisabled,
64
+ updatedLevels,
65
+ optionAtMax,
66
+ groupAtMax,
67
+ oneOnly });
68
+ };
@@ -0,0 +1,15 @@
1
+ import { CartItemGroup, ConfigDisplaySetting } from '@open-tender/types';
2
+ export declare const useModifierGroup: (group: CartItemGroup, displaySettings?: ConfigDisplaySetting) => {
3
+ description: string | null;
4
+ count: string;
5
+ id: number;
6
+ imageUrl: string | null;
7
+ included: number;
8
+ isPizza: boolean;
9
+ isSize: boolean;
10
+ max: number;
11
+ min: number;
12
+ name: string;
13
+ options: import("@open-tender/types").CartItemOptions;
14
+ quantity: number;
15
+ };
@@ -0,0 +1,13 @@
1
+ export const useModifierGroup = (group, displaySettings) => {
2
+ const { modifierGroupDescription = true } = displaySettings || {};
3
+ const description = modifierGroupDescription && group.description ? group.description : null;
4
+ const { quantity, min, max, included } = group;
5
+ const belowMin = quantity < min;
6
+ const suffix = min && belowMin
7
+ ? `, ${min} required`
8
+ : included && quantity < included
9
+ ? `, ${included} included`
10
+ : '';
11
+ const count = `${quantity}${max ? `/${max}` : ' selected'}${suffix}`;
12
+ return Object.assign(Object.assign({}, group), { description, count });
13
+ };
@@ -1,4 +1,4 @@
1
- import { formatDollars, getItemOptions, hasGroupsBelowMin } from '../../utils';
1
+ import { formatDollars, getItemOptions, hasGroupsBelowMin } from '../utils';
2
2
  export const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySettings = null, cartCounts = {}, isMobile = true) => {
3
3
  const { menuImages: showImage = true, calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, quickAdd = false, quickAddMobile = false, menuItemDescription = 'SHOW', menuItemDescriptionMobile = 'SHOW' } = displaySettings || {};
4
4
  const showQuickAdd = isMobile ? quickAddMobile : quickAdd;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.118",
3
+ "version": "0.1.120",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -1,2 +0,0 @@
1
- export * from './useBuilder';
2
- export * from './useOrderItem';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./useBuilder"), exports);
5
- tslib_1.__exportStar(require("./useOrderItem"), exports);
@@ -1,2 +0,0 @@
1
- export * from './useBuilder';
2
- export * from './useOrderItem';
@@ -1,2 +0,0 @@
1
- export * from './useBuilder';
2
- export * from './useOrderItem';