@open-tender/utils 0.5.2 → 0.5.3
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,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CustomerSignIn, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
|
|
3
|
+
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, recaptchaKey: string | null, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
7
|
fields: import("@open-tender/types").FormFieldType[];
|
|
7
8
|
data: {
|
|
8
9
|
identifier: string;
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useOneTimePasscodeForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback) => {
|
|
6
|
+
const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, submit, callback) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
|
+
const recaptchaRef = (0, react_1.useRef)(null);
|
|
9
10
|
const [data, setData] = (0, react_1.useState)({
|
|
10
11
|
identifier: '',
|
|
11
12
|
one_time_passcode: ''
|
|
@@ -33,6 +34,8 @@ const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback) => {
|
|
|
33
34
|
if (loading === 'idle' && submitting) {
|
|
34
35
|
setSubmitting(false);
|
|
35
36
|
if (error) {
|
|
37
|
+
if (recaptchaRef.current)
|
|
38
|
+
recaptchaRef.current.reset();
|
|
36
39
|
const errs = (0, utils_1.makeFormErrors)(error);
|
|
37
40
|
if (errs.form.includes('not found')) {
|
|
38
41
|
errs.form =
|
|
@@ -62,19 +65,49 @@ const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback) => {
|
|
|
62
65
|
}
|
|
63
66
|
};
|
|
64
67
|
const handleSubmit = (evt) => {
|
|
65
|
-
var _a, _b;
|
|
68
|
+
var _a, _b, _c;
|
|
66
69
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
67
|
-
setSubmitting(true);
|
|
68
70
|
const { identifier, one_time_passcode } = data;
|
|
69
71
|
const values = /[a-zA-Z]/g.test(identifier)
|
|
70
72
|
? { email: identifier }
|
|
71
73
|
: { phone: identifier };
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
if (!otpSent) {
|
|
75
|
+
if (recaptchaKey) {
|
|
76
|
+
try {
|
|
77
|
+
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
78
|
+
if (!token) {
|
|
79
|
+
setSubmitting(false);
|
|
80
|
+
setErrors({
|
|
81
|
+
form: 'Please complete the recaptcha before submitting'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
submit(Object.assign(Object.assign({}, values), { recaptcha_token: token }));
|
|
86
|
+
setSubmitting(true);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
setSubmitting(false);
|
|
91
|
+
setErrors({
|
|
92
|
+
form: 'Please complete the recaptcha before submitting'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
submit(values);
|
|
98
|
+
setSubmitting(true);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
submit({ one_time_passcode });
|
|
103
|
+
setSubmitting(true);
|
|
104
|
+
}
|
|
105
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
74
106
|
};
|
|
75
107
|
return {
|
|
76
108
|
submitRef,
|
|
77
109
|
inputRef,
|
|
110
|
+
recaptchaRef,
|
|
78
111
|
fields,
|
|
79
112
|
data,
|
|
80
113
|
errors,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CustomerSignIn, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
|
|
3
|
+
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, recaptchaKey: string | null, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
7
|
fields: import("@open-tender/types").FormFieldType[];
|
|
7
8
|
data: {
|
|
8
9
|
identifier: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { makeFormErrors, makePhone } from '../utils';
|
|
3
|
-
export const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback) => {
|
|
3
|
+
export const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, submit, callback) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
|
+
const recaptchaRef = useRef(null);
|
|
6
7
|
const [data, setData] = useState({
|
|
7
8
|
identifier: '',
|
|
8
9
|
one_time_passcode: ''
|
|
@@ -30,6 +31,8 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback
|
|
|
30
31
|
if (loading === 'idle' && submitting) {
|
|
31
32
|
setSubmitting(false);
|
|
32
33
|
if (error) {
|
|
34
|
+
if (recaptchaRef.current)
|
|
35
|
+
recaptchaRef.current.reset();
|
|
33
36
|
const errs = makeFormErrors(error);
|
|
34
37
|
if (errs.form.includes('not found')) {
|
|
35
38
|
errs.form =
|
|
@@ -59,19 +62,49 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, submit, callback
|
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
const handleSubmit = (evt) => {
|
|
62
|
-
var _a, _b;
|
|
65
|
+
var _a, _b, _c;
|
|
63
66
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
64
|
-
setSubmitting(true);
|
|
65
67
|
const { identifier, one_time_passcode } = data;
|
|
66
68
|
const values = /[a-zA-Z]/g.test(identifier)
|
|
67
69
|
? { email: identifier }
|
|
68
70
|
: { phone: identifier };
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
if (!otpSent) {
|
|
72
|
+
if (recaptchaKey) {
|
|
73
|
+
try {
|
|
74
|
+
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
75
|
+
if (!token) {
|
|
76
|
+
setSubmitting(false);
|
|
77
|
+
setErrors({
|
|
78
|
+
form: 'Please complete the recaptcha before submitting'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
submit(Object.assign(Object.assign({}, values), { recaptcha_token: token }));
|
|
83
|
+
setSubmitting(true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
setSubmitting(false);
|
|
88
|
+
setErrors({
|
|
89
|
+
form: 'Please complete the recaptcha before submitting'
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
submit(values);
|
|
95
|
+
setSubmitting(true);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
submit({ one_time_passcode });
|
|
100
|
+
setSubmitting(true);
|
|
101
|
+
}
|
|
102
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
71
103
|
};
|
|
72
104
|
return {
|
|
73
105
|
submitRef,
|
|
74
106
|
inputRef,
|
|
107
|
+
recaptchaRef,
|
|
75
108
|
fields,
|
|
76
109
|
data,
|
|
77
110
|
errors,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.4.
|
|
39
|
+
"@open-tender/types": "^0.4.134",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|