@open-tender/utils 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/menu/useOrderItem.js +1 -1
- package/dist/cjs/hooks/useAddressForm.d.ts +2 -2
- package/dist/cjs/utils/cart.d.ts +7 -10
- package/dist/cjs/utils/cart.js +20 -9
- package/dist/cjs/utils/errors.d.ts +1 -1
- package/dist/cjs/utils/theme.d.ts +12 -3
- package/dist/cjs/utils/theme.js +4 -4
- package/dist/esm/hooks/menu/useOrderItem.js +1 -1
- package/dist/esm/hooks/useAddressForm.d.ts +2 -2
- package/dist/esm/utils/cart.d.ts +7 -10
- package/dist/esm/utils/cart.js +20 -9
- package/dist/esm/utils/errors.d.ts +1 -1
- package/dist/esm/utils/theme.d.ts +12 -3
- package/dist/esm/utils/theme.js +4 -4
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], displaySe
|
|
|
27
27
|
const groupsBelowMin = (0, utils_1.hasGroupsBelowMin)(null, groups);
|
|
28
28
|
const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
|
|
29
29
|
const nonSizeGroups = groups.filter(i => !i.isSize);
|
|
30
|
-
const currentOptions = (0, utils_1.getItemOptions)({ groups: nonSizeGroups });
|
|
30
|
+
const currentOptions = (0, utils_1.getItemOptions)(Object.assign(Object.assign({}, orderItem), { groups: nonSizeGroups }));
|
|
31
31
|
const hasSelections = currentOptions.length > 0;
|
|
32
32
|
const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
|
|
33
33
|
const desc = showDesc === 'HIDE'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Address, FormFieldType, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useAddressForm: (address: Address, loading: RequestStatus, error:
|
|
2
|
+
import { Address, FormFieldType, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useAddressForm: (address: Address, loading: RequestStatus, error: RequestError, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
fields: FormFieldType[];
|
|
5
5
|
data: Address;
|
|
6
6
|
errors: any;
|
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images } from '@open-tender/types';
|
|
2
|
-
export declare const getItemOptions: (item:
|
|
3
|
-
export declare const makeModifierNames: (item:
|
|
1
|
+
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem } from '@open-tender/types';
|
|
2
|
+
export declare const getItemOptions: <T extends BaseItem>(item: T) => BaseItem[];
|
|
3
|
+
export declare const makeModifierNames: <T extends BaseItem>(item: T) => string;
|
|
4
4
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
5
5
|
export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
|
|
6
|
-
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (
|
|
6
|
+
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItemOption | CartItem)[];
|
|
7
7
|
export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
|
|
8
8
|
export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
|
|
9
9
|
export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
|
|
10
10
|
export declare const checkSoldOut: (id: number, suspendUntil: number | null, soldOut?: number[]) => boolean;
|
|
11
|
-
export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) =>
|
|
11
|
+
export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) => CartItemOption | CartItem;
|
|
12
12
|
export declare const calcCartCounts: (cart: Cart) => Record<string, number>;
|
|
13
13
|
export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: SimpleCartItem, soldOut?: number[]) => CartItem;
|
|
14
14
|
export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: SimpleCart, soldOut?: number[]) => {
|
|
@@ -179,11 +179,8 @@ export declare const makeSimpleCart: <C extends {
|
|
|
179
179
|
notes: string;
|
|
180
180
|
}[];
|
|
181
181
|
export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
|
|
182
|
-
newCart:
|
|
183
|
-
errors:
|
|
184
|
-
missingItems: Cart;
|
|
185
|
-
invalidItems: Cart;
|
|
186
|
-
} | null;
|
|
182
|
+
newCart: Cart;
|
|
183
|
+
errors: CartErrors | null;
|
|
187
184
|
};
|
|
188
185
|
export declare const getDefaultTip: (config: CheckoutConfig) => string | null;
|
|
189
186
|
export declare const prepareOrder: (data: OrderData) => OrderCreate;
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -3,20 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
|
|
4
4
|
const types_1 = require("@open-tender/types");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
|
-
// TODO: refactor for nested mods
|
|
6
|
+
// TODO: refactor for nested mods (if needed)
|
|
7
7
|
const getItemOptions = (item) => {
|
|
8
|
-
if (!item.groups
|
|
8
|
+
if (!item.groups.length)
|
|
9
9
|
return [];
|
|
10
10
|
const options = item.groups
|
|
11
|
-
.map(group =>
|
|
12
|
-
.reduce((arr, i) => [...
|
|
11
|
+
.map(group => group.options.filter(option => option.quantity > 0))
|
|
12
|
+
.reduce((arr, i) => [...arr, ...i], []);
|
|
13
13
|
return options;
|
|
14
14
|
};
|
|
15
15
|
exports.getItemOptions = getItemOptions;
|
|
16
|
-
// TODO: refactor for nested mods
|
|
17
16
|
const makeModifierNames = (item) => {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return item.groups
|
|
18
|
+
.map(group => group.options.filter(option => option.quantity > 0))
|
|
19
|
+
.reduce((arr, i) => [...arr, ...i], [])
|
|
20
|
+
.map(i => {
|
|
21
|
+
const optionNames = (0, exports.makeModifierNames)(i);
|
|
22
|
+
const name = optionNames ? `${i.name} (${optionNames})` : i.name;
|
|
23
|
+
return Object.assign(Object.assign({}, i), { name });
|
|
24
|
+
})
|
|
25
|
+
.map(option => option.name)
|
|
26
|
+
.join(', ');
|
|
20
27
|
};
|
|
21
28
|
exports.makeModifierNames = makeModifierNames;
|
|
22
29
|
const hasGroupsBelowMin = (option, groups) => {
|
|
@@ -724,7 +731,11 @@ const validateCart = (cart, categories, soldOut) => {
|
|
|
724
731
|
// above the max from the current menu
|
|
725
732
|
if ((newItem.max && ((_c = oldItem.quantity) !== null && _c !== void 0 ? _c : 0) > newItem.max) ||
|
|
726
733
|
(newItem.min && ((_d = oldItem.quantity) !== null && _d !== void 0 ? _d : 0) < newItem.min)) {
|
|
727
|
-
|
|
734
|
+
const invalidItem = Object.assign(Object.assign({}, oldItem), { missingGroups,
|
|
735
|
+
invalidGroups,
|
|
736
|
+
missingOptions,
|
|
737
|
+
invalidOptions });
|
|
738
|
+
invalidItems.push(invalidItem);
|
|
728
739
|
return null;
|
|
729
740
|
}
|
|
730
741
|
const nonNullGroups = updatedGroups === null || updatedGroups === void 0 ? void 0 : updatedGroups.filter(i => i !== null);
|
|
@@ -740,7 +751,7 @@ const validateCart = (cart, categories, soldOut) => {
|
|
|
740
751
|
if (missingItems.length || invalidItems.length) {
|
|
741
752
|
errors = { missingItems, invalidItems };
|
|
742
753
|
}
|
|
743
|
-
return { newCart, errors };
|
|
754
|
+
return { newCart: newCart, errors };
|
|
744
755
|
};
|
|
745
756
|
exports.validateCart = validateCart;
|
|
746
757
|
/* order submission */
|
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const handleCheckoutErrors: (errors:
|
|
14
|
+
export declare const handleCheckoutErrors: (errors: RequestError, asMessages?: boolean) => Record<string, unknown>;
|
|
15
15
|
export declare const errMessages: {
|
|
16
16
|
unknown: string;
|
|
17
17
|
forbidden: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThemeLayout, Theme, ThemeWelcomeStyles, ThemeItemStyles } from '@open-tender/types';
|
|
2
2
|
export declare const makeLineHeight: (lineHeight?: string, fontSize?: string) => string;
|
|
3
3
|
export declare const remsToPixels: (rems?: string, responsive?: boolean) => string;
|
|
4
4
|
export declare const remsToNumber: (rems: string) => number;
|
|
5
|
-
export declare const objRemsToPixels: <T extends Partial<
|
|
5
|
+
export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
6
6
|
big: string;
|
|
7
7
|
giga: string;
|
|
8
8
|
h1: string;
|
|
@@ -22,5 +22,14 @@ export declare const objRemsToPixels: <T extends Partial<ConfigThemeLayout & {
|
|
|
22
22
|
}>>(object: T, responsive?: boolean) => Partial<T>;
|
|
23
23
|
export declare const pixelsToInt: (pixels: string) => string | number;
|
|
24
24
|
export declare const pixelsToFloat: (pixels: string) => string | number;
|
|
25
|
-
|
|
25
|
+
interface ThemeWelcomeStylesApp extends Omit<ThemeWelcomeStyles, 'titleLineHeight' | 'subtitleLineHeight'> {
|
|
26
|
+
titleLineHeight: string;
|
|
27
|
+
subtitleLineHeight: string;
|
|
28
|
+
}
|
|
29
|
+
interface AppTheme extends Omit<Theme, 'welcome' | 'item'> {
|
|
30
|
+
welcome: ThemeWelcomeStylesApp;
|
|
31
|
+
item: ThemeItemStyles;
|
|
32
|
+
}
|
|
33
|
+
export declare const decorateTheme: (theme: Theme) => AppTheme;
|
|
26
34
|
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
35
|
+
export {};
|
package/dist/cjs/utils/theme.js
CHANGED
|
@@ -139,15 +139,15 @@ const makeWelcome = (welcome) => {
|
|
|
139
139
|
marginBottom: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.marginBottom),
|
|
140
140
|
titleMarginLeft: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.titleMarginLeft),
|
|
141
141
|
titleSize,
|
|
142
|
-
titleLineHeight: (0, exports.makeLineHeight)(mobile === null || mobile === void 0 ? void 0 : mobile.titleLineHeight, titleSize),
|
|
142
|
+
titleLineHeight: (0, exports.makeLineHeight)(mobile === null || mobile === void 0 ? void 0 : mobile.titleLineHeight.toFixed(5), titleSize),
|
|
143
143
|
subtitleSize,
|
|
144
|
-
subtitleLineHeight: (0, exports.makeLineHeight)(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleLineHeight, subtitleSize),
|
|
144
|
+
subtitleLineHeight: (0, exports.makeLineHeight)(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleLineHeight.toFixed(5), subtitleSize),
|
|
145
145
|
subtitleMarginTop: (0, exports.remsToPixels)(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleMarginTop)
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
148
|
const makeItem = (item) => {
|
|
149
149
|
const { mobile } = item;
|
|
150
|
-
return Object.assign(Object.assign({},
|
|
150
|
+
return Object.assign(Object.assign({}, mobile), { padding: (0, exports.remsToPixels)(mobile.padding), imagePadding: (0, exports.remsToPixels)(mobile.imagePadding), maxWidth: (0, exports.remsToPixels)(mobile.maxWidth), imageMinHeight: (0, exports.remsToPixels)(mobile.imageMinHeight), imageMaxHeight: (0, exports.remsToPixels)(mobile.imageMaxHeight) });
|
|
151
151
|
};
|
|
152
152
|
const decorateTheme = (theme) => {
|
|
153
153
|
const fonts = makeFonts(theme.fonts, theme.lineHeight);
|
|
@@ -161,7 +161,7 @@ const decorateTheme = (theme) => {
|
|
|
161
161
|
const welcome = makeWelcome(theme.welcome);
|
|
162
162
|
const item = makeItem(theme.item);
|
|
163
163
|
return Object.assign(Object.assign({}, theme), { fonts: fonts, lineHeight, layout: layout, buttons: buttons, border, inputs: inputs, counts,
|
|
164
|
-
cards, welcome: welcome, item });
|
|
164
|
+
cards, welcome: welcome, item: item });
|
|
165
165
|
};
|
|
166
166
|
exports.decorateTheme = decorateTheme;
|
|
167
167
|
const hexToRgbA = (hex, opacity) => {
|
|
@@ -24,7 +24,7 @@ export const useOrderItem = (orderItem, favorite = null, allergenAlerts = [], di
|
|
|
24
24
|
const groupsBelowMin = hasGroupsBelowMin(null, groups);
|
|
25
25
|
const isIncomplete = totalPrice === 0 || quantity === 0 || groupsBelowMin;
|
|
26
26
|
const nonSizeGroups = groups.filter(i => !i.isSize);
|
|
27
|
-
const currentOptions = getItemOptions({ groups: nonSizeGroups });
|
|
27
|
+
const currentOptions = getItemOptions(Object.assign(Object.assign({}, orderItem), { groups: nonSizeGroups }));
|
|
28
28
|
const hasSelections = currentOptions.length > 0;
|
|
29
29
|
const showDesc = isMobile ? menuItemDescriptionMobile : menuItemDescription;
|
|
30
30
|
const desc = showDesc === 'HIDE'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Address, FormFieldType, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useAddressForm: (address: Address, loading: RequestStatus, error:
|
|
2
|
+
import { Address, FormFieldType, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useAddressForm: (address: Address, loading: RequestStatus, error: RequestError, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
fields: FormFieldType[];
|
|
5
5
|
data: Address;
|
|
6
6
|
errors: any;
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images } from '@open-tender/types';
|
|
2
|
-
export declare const getItemOptions: (item:
|
|
3
|
-
export declare const makeModifierNames: (item:
|
|
1
|
+
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem } from '@open-tender/types';
|
|
2
|
+
export declare const getItemOptions: <T extends BaseItem>(item: T) => BaseItem[];
|
|
3
|
+
export declare const makeModifierNames: <T extends BaseItem>(item: T) => string;
|
|
4
4
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
5
5
|
export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
|
|
6
|
-
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (
|
|
6
|
+
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItemOption | CartItem)[];
|
|
7
7
|
export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
|
|
8
8
|
export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
|
|
9
9
|
export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
|
|
10
10
|
export declare const checkSoldOut: (id: number, suspendUntil: number | null, soldOut?: number[]) => boolean;
|
|
11
|
-
export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) =>
|
|
11
|
+
export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) => CartItemOption | CartItem;
|
|
12
12
|
export declare const calcCartCounts: (cart: Cart) => Record<string, number>;
|
|
13
13
|
export declare const rehydrateOrderItem: (menuItem: MenuItem, simpleCartItem: SimpleCartItem, soldOut?: number[]) => CartItem;
|
|
14
14
|
export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: SimpleCart, soldOut?: number[]) => {
|
|
@@ -179,11 +179,8 @@ export declare const makeSimpleCart: <C extends {
|
|
|
179
179
|
notes: string;
|
|
180
180
|
}[];
|
|
181
181
|
export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
|
|
182
|
-
newCart:
|
|
183
|
-
errors:
|
|
184
|
-
missingItems: Cart;
|
|
185
|
-
invalidItems: Cart;
|
|
186
|
-
} | null;
|
|
182
|
+
newCart: Cart;
|
|
183
|
+
errors: CartErrors | null;
|
|
187
184
|
};
|
|
188
185
|
export declare const getDefaultTip: (config: CheckoutConfig) => string | null;
|
|
189
186
|
export declare const prepareOrder: (data: OrderData) => OrderCreate;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { isCreditTender, isHouseAccountTender, isOrderCustomer } from '@open-tender/types';
|
|
2
2
|
import { convertStringToArray } from './helpers';
|
|
3
|
-
// TODO: refactor for nested mods
|
|
3
|
+
// TODO: refactor for nested mods (if needed)
|
|
4
4
|
export const getItemOptions = (item) => {
|
|
5
|
-
if (!item.groups
|
|
5
|
+
if (!item.groups.length)
|
|
6
6
|
return [];
|
|
7
7
|
const options = item.groups
|
|
8
|
-
.map(group =>
|
|
9
|
-
.reduce((arr, i) => [...
|
|
8
|
+
.map(group => group.options.filter(option => option.quantity > 0))
|
|
9
|
+
.reduce((arr, i) => [...arr, ...i], []);
|
|
10
10
|
return options;
|
|
11
11
|
};
|
|
12
|
-
// TODO: refactor for nested mods
|
|
13
12
|
export const makeModifierNames = (item) => {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
return item.groups
|
|
14
|
+
.map(group => group.options.filter(option => option.quantity > 0))
|
|
15
|
+
.reduce((arr, i) => [...arr, ...i], [])
|
|
16
|
+
.map(i => {
|
|
17
|
+
const optionNames = makeModifierNames(i);
|
|
18
|
+
const name = optionNames ? `${i.name} (${optionNames})` : i.name;
|
|
19
|
+
return Object.assign(Object.assign({}, i), { name });
|
|
20
|
+
})
|
|
21
|
+
.map(option => option.name)
|
|
22
|
+
.join(', ');
|
|
16
23
|
};
|
|
17
24
|
export const hasGroupsBelowMin = (option, groups) => {
|
|
18
25
|
if (!groups || !groups.length)
|
|
@@ -692,7 +699,11 @@ export const validateCart = (cart, categories, soldOut) => {
|
|
|
692
699
|
// above the max from the current menu
|
|
693
700
|
if ((newItem.max && ((_c = oldItem.quantity) !== null && _c !== void 0 ? _c : 0) > newItem.max) ||
|
|
694
701
|
(newItem.min && ((_d = oldItem.quantity) !== null && _d !== void 0 ? _d : 0) < newItem.min)) {
|
|
695
|
-
|
|
702
|
+
const invalidItem = Object.assign(Object.assign({}, oldItem), { missingGroups,
|
|
703
|
+
invalidGroups,
|
|
704
|
+
missingOptions,
|
|
705
|
+
invalidOptions });
|
|
706
|
+
invalidItems.push(invalidItem);
|
|
696
707
|
return null;
|
|
697
708
|
}
|
|
698
709
|
const nonNullGroups = updatedGroups === null || updatedGroups === void 0 ? void 0 : updatedGroups.filter(i => i !== null);
|
|
@@ -708,7 +719,7 @@ export const validateCart = (cart, categories, soldOut) => {
|
|
|
708
719
|
if (missingItems.length || invalidItems.length) {
|
|
709
720
|
errors = { missingItems, invalidItems };
|
|
710
721
|
}
|
|
711
|
-
return { newCart, errors };
|
|
722
|
+
return { newCart: newCart, errors };
|
|
712
723
|
};
|
|
713
724
|
/* order submission */
|
|
714
725
|
export const getDefaultTip = (config) => {
|
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const handleCheckoutErrors: (errors:
|
|
14
|
+
export declare const handleCheckoutErrors: (errors: RequestError, asMessages?: boolean) => Record<string, unknown>;
|
|
15
15
|
export declare const errMessages: {
|
|
16
16
|
unknown: string;
|
|
17
17
|
forbidden: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThemeLayout, Theme, ThemeWelcomeStyles, ThemeItemStyles } from '@open-tender/types';
|
|
2
2
|
export declare const makeLineHeight: (lineHeight?: string, fontSize?: string) => string;
|
|
3
3
|
export declare const remsToPixels: (rems?: string, responsive?: boolean) => string;
|
|
4
4
|
export declare const remsToNumber: (rems: string) => number;
|
|
5
|
-
export declare const objRemsToPixels: <T extends Partial<
|
|
5
|
+
export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
6
6
|
big: string;
|
|
7
7
|
giga: string;
|
|
8
8
|
h1: string;
|
|
@@ -22,5 +22,14 @@ export declare const objRemsToPixels: <T extends Partial<ConfigThemeLayout & {
|
|
|
22
22
|
}>>(object: T, responsive?: boolean) => Partial<T>;
|
|
23
23
|
export declare const pixelsToInt: (pixels: string) => string | number;
|
|
24
24
|
export declare const pixelsToFloat: (pixels: string) => string | number;
|
|
25
|
-
|
|
25
|
+
interface ThemeWelcomeStylesApp extends Omit<ThemeWelcomeStyles, 'titleLineHeight' | 'subtitleLineHeight'> {
|
|
26
|
+
titleLineHeight: string;
|
|
27
|
+
subtitleLineHeight: string;
|
|
28
|
+
}
|
|
29
|
+
interface AppTheme extends Omit<Theme, 'welcome' | 'item'> {
|
|
30
|
+
welcome: ThemeWelcomeStylesApp;
|
|
31
|
+
item: ThemeItemStyles;
|
|
32
|
+
}
|
|
33
|
+
export declare const decorateTheme: (theme: Theme) => AppTheme;
|
|
26
34
|
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
35
|
+
export {};
|
package/dist/esm/utils/theme.js
CHANGED
|
@@ -130,15 +130,15 @@ const makeWelcome = (welcome) => {
|
|
|
130
130
|
marginBottom: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.marginBottom),
|
|
131
131
|
titleMarginLeft: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.titleMarginLeft),
|
|
132
132
|
titleSize,
|
|
133
|
-
titleLineHeight: makeLineHeight(mobile === null || mobile === void 0 ? void 0 : mobile.titleLineHeight, titleSize),
|
|
133
|
+
titleLineHeight: makeLineHeight(mobile === null || mobile === void 0 ? void 0 : mobile.titleLineHeight.toFixed(5), titleSize),
|
|
134
134
|
subtitleSize,
|
|
135
|
-
subtitleLineHeight: makeLineHeight(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleLineHeight, subtitleSize),
|
|
135
|
+
subtitleLineHeight: makeLineHeight(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleLineHeight.toFixed(5), subtitleSize),
|
|
136
136
|
subtitleMarginTop: remsToPixels(mobile === null || mobile === void 0 ? void 0 : mobile.subtitleMarginTop)
|
|
137
137
|
};
|
|
138
138
|
};
|
|
139
139
|
const makeItem = (item) => {
|
|
140
140
|
const { mobile } = item;
|
|
141
|
-
return Object.assign(Object.assign({},
|
|
141
|
+
return Object.assign(Object.assign({}, mobile), { padding: remsToPixels(mobile.padding), imagePadding: remsToPixels(mobile.imagePadding), maxWidth: remsToPixels(mobile.maxWidth), imageMinHeight: remsToPixels(mobile.imageMinHeight), imageMaxHeight: remsToPixels(mobile.imageMaxHeight) });
|
|
142
142
|
};
|
|
143
143
|
export const decorateTheme = (theme) => {
|
|
144
144
|
const fonts = makeFonts(theme.fonts, theme.lineHeight);
|
|
@@ -152,7 +152,7 @@ export const decorateTheme = (theme) => {
|
|
|
152
152
|
const welcome = makeWelcome(theme.welcome);
|
|
153
153
|
const item = makeItem(theme.item);
|
|
154
154
|
return Object.assign(Object.assign({}, theme), { fonts: fonts, lineHeight, layout: layout, buttons: buttons, border, inputs: inputs, counts,
|
|
155
|
-
cards, welcome: welcome, item });
|
|
155
|
+
cards, welcome: welcome, item: item });
|
|
156
156
|
};
|
|
157
157
|
export const hexToRgbA = (hex, opacity) => {
|
|
158
158
|
let c;
|
package/package.json
CHANGED