@open-tender/utils 0.1.148 → 0.1.150

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.
@@ -51,19 +51,24 @@ const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback) => {
51
51
  }
52
52
  }, [loading, error, callback, submitting, otpSent]);
53
53
  const handleChange = (name, value) => {
54
- const inputValue = name === 'identifier' && typeof value === 'string' && (0, utils_1.isPhone)(value)
55
- ? (0, utils_1.makePhone)(value !== null && value !== void 0 ? value : '')
56
- : value;
57
- setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
54
+ if (name !== 'identifier') {
55
+ setData(Object.assign(Object.assign({}, data), { [name]: value }));
56
+ }
57
+ else if (typeof value === 'string') {
58
+ const inputValue = /[a-zA-Z]/g.test(value)
59
+ ? value
60
+ : (0, utils_1.makePhone)(value !== null && value !== void 0 ? value : '');
61
+ setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
62
+ }
58
63
  };
59
64
  const handleSubmit = (evt) => {
60
65
  var _a, _b;
61
66
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
62
67
  setSubmitting(true);
63
68
  const { identifier, one_time_passcode } = data;
64
- const values = (0, utils_1.isPhone)(identifier)
65
- ? { phone: identifier }
66
- : { email: identifier };
69
+ const values = /[a-zA-Z]/g.test(identifier)
70
+ ? { email: identifier }
71
+ : { phone: identifier };
67
72
  otpSent ? submit({ one_time_passcode }) : submit(values);
68
73
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
69
74
  };
@@ -10,7 +10,6 @@ export declare const serialize: (obj: Record<string | number, string | number |
10
10
  export declare const capitalize: (s: string) => string;
11
11
  export declare const cleanPhone: (phone: string) => string;
12
12
  export declare const makePhone: (phone: string) => string;
13
- export declare const isPhone: (value: string) => boolean;
14
13
  export declare const validatePhone: (phone: string) => boolean;
15
14
  export declare const makeBirthDate: (birthDate: string) => string | null;
16
15
  export declare const slashesToDashes: (birthDate: string) => DateString | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.displayPrice = exports.makeSlides = exports.makeImageUrl = exports.makeImageMap = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.checkNotFound = exports.checkGuestData = exports.checkEmpty = exports.validateEmail = exports.dashesToSlashes = exports.slashesToDashes = exports.makeBirthDate = exports.validatePhone = exports.isPhone = exports.makePhone = exports.cleanPhone = exports.capitalize = exports.serialize = exports.stripTags = exports.slugify = exports.contains = exports.isNum = exports.isEmpty = exports.isObject = exports.isString = void 0;
3
+ exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.displayPrice = exports.makeSlides = exports.makeImageUrl = exports.makeImageMap = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.checkNotFound = exports.checkGuestData = exports.checkEmpty = exports.validateEmail = exports.dashesToSlashes = exports.slashesToDashes = exports.makeBirthDate = exports.validatePhone = exports.makePhone = exports.cleanPhone = exports.capitalize = exports.serialize = exports.stripTags = exports.slugify = exports.contains = exports.isNum = exports.isEmpty = exports.isObject = exports.isString = void 0;
4
4
  const isString = (str) => {
5
5
  return typeof str === 'string';
6
6
  };
@@ -74,10 +74,6 @@ const makePhone = (phone) => {
74
74
  return p;
75
75
  };
76
76
  exports.makePhone = makePhone;
77
- const isPhone = (value) => {
78
- return /^\d+$/.test(value.replace('-', ''));
79
- };
80
- exports.isPhone = isPhone;
81
77
  const validatePhone = (phone) => {
82
78
  var _a;
83
79
  if (!phone)
@@ -1,4 +1,4 @@
1
- import { MenuCategories, MenuDisplayedSections } from '@open-tender/types';
1
+ import { MenuCategories, MenuDisplayedSections, ThemeImagePosition } from '@open-tender/types';
2
2
  export declare const getBinaryArr: <T>(arr: T[]) => T[][];
3
3
  export declare const makeItemChunks: <T extends {
4
4
  id: number;
@@ -104,3 +104,8 @@ export declare const makeFlatCategories: (categories: MenuCategories) => {
104
104
  slug: string;
105
105
  small_image_url: string | null;
106
106
  }[];
107
+ export declare const makeMenuItemLayout: (position: ThemeImagePosition) => {
108
+ hideImage: boolean;
109
+ flexDirection: string;
110
+ alignItems: string;
111
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeFlatCategories = exports.makeOtherMenuSections = exports.makeItemChunks = exports.getBinaryArr = void 0;
3
+ exports.makeMenuItemLayout = exports.makeFlatCategories = exports.makeOtherMenuSections = exports.makeItemChunks = exports.getBinaryArr = void 0;
4
4
  const helpers_1 = require("./helpers");
5
5
  const getBinaryArr = (arr) => {
6
6
  const result = [];
@@ -45,3 +45,38 @@ const makeFlatCategories = (categories) => {
45
45
  .map(c => (Object.assign(Object.assign({}, c), { key: (0, helpers_1.slugify)(c.name), data: c.items.map((i, idx) => (Object.assign(Object.assign({}, i), { key: `${(0, helpers_1.slugify)(c.name)}-${i.id}-${idx}` }))) })));
46
46
  };
47
47
  exports.makeFlatCategories = makeFlatCategories;
48
+ const makeMenuItemLayout = (position) => {
49
+ switch (position) {
50
+ case 'HIDDEN':
51
+ return {
52
+ hideImage: true,
53
+ flexDirection: 'column',
54
+ alignItems: 'stretch'
55
+ };
56
+ case 'LEFT':
57
+ return {
58
+ hideImage: false,
59
+ flexDirection: 'row',
60
+ alignItems: 'flex-start'
61
+ };
62
+ case 'RIGHT':
63
+ return {
64
+ hideImage: false,
65
+ flexDirection: 'row-reverse',
66
+ alignItems: 'flex-start'
67
+ };
68
+ case 'BOTTOM':
69
+ return {
70
+ hideImage: false,
71
+ flexDirection: 'column-reverse',
72
+ alignItems: 'stretch'
73
+ };
74
+ default:
75
+ return {
76
+ hideImage: false,
77
+ flexDirection: 'column',
78
+ alignItems: 'stretch'
79
+ };
80
+ }
81
+ };
82
+ exports.makeMenuItemLayout = makeMenuItemLayout;
@@ -1,5 +1,5 @@
1
1
  import { useState, useEffect, useRef } from 'react';
2
- import { isPhone, makeFormErrors, makePhone } from '../utils';
2
+ import { makeFormErrors, makePhone } from '../utils';
3
3
  export const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback) => {
4
4
  const submitRef = useRef(null);
5
5
  const inputRef = useRef(null);
@@ -48,19 +48,24 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback
48
48
  }
49
49
  }, [loading, error, callback, submitting, otpSent]);
50
50
  const handleChange = (name, value) => {
51
- const inputValue = name === 'identifier' && typeof value === 'string' && isPhone(value)
52
- ? makePhone(value !== null && value !== void 0 ? value : '')
53
- : value;
54
- setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
51
+ if (name !== 'identifier') {
52
+ setData(Object.assign(Object.assign({}, data), { [name]: value }));
53
+ }
54
+ else if (typeof value === 'string') {
55
+ const inputValue = /[a-zA-Z]/g.test(value)
56
+ ? value
57
+ : makePhone(value !== null && value !== void 0 ? value : '');
58
+ setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
59
+ }
55
60
  };
56
61
  const handleSubmit = (evt) => {
57
62
  var _a, _b;
58
63
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
59
64
  setSubmitting(true);
60
65
  const { identifier, one_time_passcode } = data;
61
- const values = isPhone(identifier)
62
- ? { phone: identifier }
63
- : { email: identifier };
66
+ const values = /[a-zA-Z]/g.test(identifier)
67
+ ? { email: identifier }
68
+ : { phone: identifier };
64
69
  otpSent ? submit({ one_time_passcode }) : submit(values);
65
70
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
66
71
  };
@@ -10,7 +10,6 @@ export declare const serialize: (obj: Record<string | number, string | number |
10
10
  export declare const capitalize: (s: string) => string;
11
11
  export declare const cleanPhone: (phone: string) => string;
12
12
  export declare const makePhone: (phone: string) => string;
13
- export declare const isPhone: (value: string) => boolean;
14
13
  export declare const validatePhone: (phone: string) => boolean;
15
14
  export declare const makeBirthDate: (birthDate: string) => string | null;
16
15
  export declare const slashesToDashes: (birthDate: string) => DateString | null;
@@ -60,9 +60,6 @@ export const makePhone = (phone) => {
60
60
  }
61
61
  return p;
62
62
  };
63
- export const isPhone = (value) => {
64
- return /^\d+$/.test(value.replace('-', ''));
65
- };
66
63
  export const validatePhone = (phone) => {
67
64
  var _a;
68
65
  if (!phone)
@@ -1,4 +1,4 @@
1
- import { MenuCategories, MenuDisplayedSections } from '@open-tender/types';
1
+ import { MenuCategories, MenuDisplayedSections, ThemeImagePosition } from '@open-tender/types';
2
2
  export declare const getBinaryArr: <T>(arr: T[]) => T[][];
3
3
  export declare const makeItemChunks: <T extends {
4
4
  id: number;
@@ -104,3 +104,8 @@ export declare const makeFlatCategories: (categories: MenuCategories) => {
104
104
  slug: string;
105
105
  small_image_url: string | null;
106
106
  }[];
107
+ export declare const makeMenuItemLayout: (position: ThemeImagePosition) => {
108
+ hideImage: boolean;
109
+ flexDirection: string;
110
+ alignItems: string;
111
+ };
@@ -38,3 +38,37 @@ export const makeFlatCategories = (categories) => {
38
38
  .filter(c => c.items.length)
39
39
  .map(c => (Object.assign(Object.assign({}, c), { key: slugify(c.name), data: c.items.map((i, idx) => (Object.assign(Object.assign({}, i), { key: `${slugify(c.name)}-${i.id}-${idx}` }))) })));
40
40
  };
41
+ export const makeMenuItemLayout = (position) => {
42
+ switch (position) {
43
+ case 'HIDDEN':
44
+ return {
45
+ hideImage: true,
46
+ flexDirection: 'column',
47
+ alignItems: 'stretch'
48
+ };
49
+ case 'LEFT':
50
+ return {
51
+ hideImage: false,
52
+ flexDirection: 'row',
53
+ alignItems: 'flex-start'
54
+ };
55
+ case 'RIGHT':
56
+ return {
57
+ hideImage: false,
58
+ flexDirection: 'row-reverse',
59
+ alignItems: 'flex-start'
60
+ };
61
+ case 'BOTTOM':
62
+ return {
63
+ hideImage: false,
64
+ flexDirection: 'column-reverse',
65
+ alignItems: 'stretch'
66
+ };
67
+ default:
68
+ return {
69
+ hideImage: false,
70
+ flexDirection: 'column',
71
+ alignItems: 'stretch'
72
+ };
73
+ }
74
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.148",
3
+ "version": "0.1.150",
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",