@open-tender/utils 0.1.147 → 0.1.149

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
  };
@@ -75,8 +75,7 @@ const makePhone = (phone) => {
75
75
  };
76
76
  exports.makePhone = makePhone;
77
77
  const isPhone = (value) => {
78
- const testValue = value;
79
- return /^\d+$/.test(testValue.replace(/\D/g, ''));
78
+ return /^\d+$/.test(value.replace('-', ''));
80
79
  };
81
80
  exports.isPhone = isPhone;
82
81
  const validatePhone = (phone) => {
@@ -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
  };
@@ -61,8 +61,7 @@ export const makePhone = (phone) => {
61
61
  return p;
62
62
  };
63
63
  export const isPhone = (value) => {
64
- const testValue = value;
65
- return /^\d+$/.test(testValue.replace(/\D/g, ''));
64
+ return /^\d+$/.test(value.replace('-', ''));
66
65
  };
67
66
  export const validatePhone = (phone) => {
68
67
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.147",
3
+ "version": "0.1.149",
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",