@open-tender/utils 0.1.15 → 0.1.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,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { Address, FormFieldType, RequestStatus } from '@open-tender/types';
3
- export declare const useAddressForm: (address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
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;
7
7
  submitting: boolean;
8
- handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
8
+ handleChange: (name: string, value: string | number | boolean) => void;
9
9
  handleSubmit: (evt?: any) => void;
10
10
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
11
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
@@ -51,12 +51,8 @@ const useAddressForm = (address, loading, error, update, callback) => {
51
51
  }
52
52
  }
53
53
  }, [loading, error]);
54
- const handleChange = (name, type, value, checked) => {
55
- const inputValue = type === 'checkbox'
56
- ? checked
57
- : name === 'phone'
58
- ? (0, utils_1.makePhone)(value !== null && value !== void 0 ? value : '')
59
- : value;
54
+ const handleChange = (name, value) => {
55
+ const inputValue = name === 'phone' ? (0, utils_1.makePhone)((value !== null && value !== void 0 ? value : '')) : value;
60
56
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
61
57
  };
62
58
  const handleSubmit = (evt) => {
@@ -1,4 +1,4 @@
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';
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 } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => string;
4
4
  export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
@@ -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: (CartItem | CartItemOption | null)[];
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;
@@ -740,7 +740,7 @@ const validateCart = (cart, categories, soldOut) => {
740
740
  if (missingItems.length || invalidItems.length) {
741
741
  errors = { missingItems, invalidItems };
742
742
  }
743
- return { newCart, errors };
743
+ return { newCart: newCart, errors };
744
744
  };
745
745
  exports.validateCart = validateCart;
746
746
  /* 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: any, asMessages?: boolean) => any;
14
+ export declare const handleCheckoutErrors: (errors: RequestError, asMessages?: boolean) => {};
15
15
  export declare const errMessages: {
16
16
  unknown: string;
17
17
  forbidden: string;
@@ -1,8 +1,8 @@
1
- import { ConfigTheme, ConfigThemeLayout } from '@open-tender/types';
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<ConfigThemeLayout & {
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
- export declare const decorateTheme: (theme: ConfigTheme) => ConfigTheme;
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 {};
@@ -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({}, item), { 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) });
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) => {
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { Address, FormFieldType, RequestStatus } from '@open-tender/types';
3
- export declare const useAddressForm: (address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
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;
7
7
  submitting: boolean;
8
- handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
8
+ handleChange: (name: string, value: string | number | boolean) => void;
9
9
  handleSubmit: (evt?: any) => void;
10
10
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
11
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
@@ -48,12 +48,8 @@ export const useAddressForm = (address, loading, error, update, callback) => {
48
48
  }
49
49
  }
50
50
  }, [loading, error]);
51
- const handleChange = (name, type, value, checked) => {
52
- const inputValue = type === 'checkbox'
53
- ? checked
54
- : name === 'phone'
55
- ? makePhone(value !== null && value !== void 0 ? value : '')
56
- : value;
51
+ const handleChange = (name, value) => {
52
+ const inputValue = name === 'phone' ? makePhone((value !== null && value !== void 0 ? value : '')) : value;
57
53
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
58
54
  };
59
55
  const handleSubmit = (evt) => {
@@ -1,4 +1,4 @@
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';
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 } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => string;
4
4
  export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
@@ -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: (CartItem | CartItemOption | null)[];
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;
@@ -708,7 +708,7 @@ export const validateCart = (cart, categories, soldOut) => {
708
708
  if (missingItems.length || invalidItems.length) {
709
709
  errors = { missingItems, invalidItems };
710
710
  }
711
- return { newCart, errors };
711
+ return { newCart: newCart, errors };
712
712
  };
713
713
  /* order submission */
714
714
  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: any, asMessages?: boolean) => any;
14
+ export declare const handleCheckoutErrors: (errors: RequestError, asMessages?: boolean) => {};
15
15
  export declare const errMessages: {
16
16
  unknown: string;
17
17
  forbidden: string;
@@ -1,8 +1,8 @@
1
- import { ConfigTheme, ConfigThemeLayout } from '@open-tender/types';
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<ConfigThemeLayout & {
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
- export declare const decorateTheme: (theme: ConfigTheme) => ConfigTheme;
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 {};
@@ -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({}, item), { padding: remsToPixels(mobile.padding), imagePadding: remsToPixels(mobile.imagePadding), maxWidth: remsToPixels(mobile.maxWidth), imageMinHeight: remsToPixels(mobile.imageMinHeight), imageMaxHeight: remsToPixels(mobile.imageMaxHeight) });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
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",