@open-tender/utils 0.5.25 → 0.5.26
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.
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSignInForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const react_1 = require("react");
|
|
6
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const react_1 = require("react");
|
|
7
7
|
const useSignInForm = (email, loading, error, login, includeRecaptcha, callback) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
10
10
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
11
11
|
const [data, setData] = (0, react_1.useState)({ email, password: '' });
|
|
12
12
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
13
|
-
const
|
|
13
|
+
const isSubmitting = (0, react_1.useRef)(false);
|
|
14
14
|
const fields = [
|
|
15
15
|
{
|
|
16
16
|
label: 'Email',
|
|
@@ -28,13 +28,13 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
28
28
|
}
|
|
29
29
|
];
|
|
30
30
|
(0, react_1.useEffect)(() => {
|
|
31
|
-
if (
|
|
32
|
-
setData({
|
|
31
|
+
if (email) {
|
|
32
|
+
setData(d => (Object.assign(Object.assign({}, d), { email })));
|
|
33
33
|
}
|
|
34
|
-
}, [email
|
|
34
|
+
}, [email]);
|
|
35
35
|
(0, react_1.useEffect)(() => {
|
|
36
|
-
if (loading === 'idle' &&
|
|
37
|
-
|
|
36
|
+
if (loading === 'idle' && isSubmitting.current) {
|
|
37
|
+
isSubmitting.current = false;
|
|
38
38
|
if (error) {
|
|
39
39
|
if (recaptchaRef.current)
|
|
40
40
|
recaptchaRef.current.reset();
|
|
@@ -44,14 +44,14 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
44
44
|
callback();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
}, [loading, error, callback
|
|
47
|
+
}, [loading, error, callback]);
|
|
48
48
|
const handleChange = (name, value) => {
|
|
49
49
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
50
50
|
};
|
|
51
51
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
52
|
var _a, _b, _c, _d, _e;
|
|
53
53
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
54
|
-
const {
|
|
54
|
+
const { password } = data;
|
|
55
55
|
if (includeRecaptcha) {
|
|
56
56
|
try {
|
|
57
57
|
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
@@ -59,26 +59,26 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
59
59
|
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
60
60
|
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
61
61
|
if (!token) {
|
|
62
|
-
|
|
62
|
+
isSubmitting.current = false;
|
|
63
63
|
setErrors({
|
|
64
64
|
form: 'Please complete the recaptcha before submitting'
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
-
login(email, password, token);
|
|
69
|
-
|
|
68
|
+
login(data.email || email, password, token);
|
|
69
|
+
isSubmitting.current = true;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
catch (err) {
|
|
73
|
-
|
|
73
|
+
isSubmitting.current = false;
|
|
74
74
|
setErrors({
|
|
75
75
|
form: 'Please complete the recaptcha before submitting'
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
|
-
login(email, password);
|
|
81
|
-
|
|
80
|
+
login(data.email || email, password);
|
|
81
|
+
isSubmitting.current = true;
|
|
82
82
|
}
|
|
83
83
|
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
84
84
|
});
|
|
@@ -89,7 +89,7 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
89
89
|
fields,
|
|
90
90
|
data,
|
|
91
91
|
errors,
|
|
92
|
-
submitting,
|
|
92
|
+
submitting: isSubmitting.current,
|
|
93
93
|
handleChange,
|
|
94
94
|
handleSubmit
|
|
95
95
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { useState, useEffect, useRef } from 'react';
|
|
3
2
|
import { makeFormErrors } from '../utils';
|
|
3
|
+
import { useState, useEffect, useRef } from 'react';
|
|
4
4
|
export const useSignInForm = (email, loading, error, login, includeRecaptcha, callback) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
7
|
const recaptchaRef = useRef(null);
|
|
8
8
|
const [data, setData] = useState({ email, password: '' });
|
|
9
9
|
const [errors, setErrors] = useState({});
|
|
10
|
-
const
|
|
10
|
+
const isSubmitting = useRef(false);
|
|
11
11
|
const fields = [
|
|
12
12
|
{
|
|
13
13
|
label: 'Email',
|
|
@@ -25,13 +25,13 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
25
25
|
}
|
|
26
26
|
];
|
|
27
27
|
useEffect(() => {
|
|
28
|
-
if (
|
|
29
|
-
setData({
|
|
28
|
+
if (email) {
|
|
29
|
+
setData(d => (Object.assign(Object.assign({}, d), { email })));
|
|
30
30
|
}
|
|
31
|
-
}, [email
|
|
31
|
+
}, [email]);
|
|
32
32
|
useEffect(() => {
|
|
33
|
-
if (loading === 'idle' &&
|
|
34
|
-
|
|
33
|
+
if (loading === 'idle' && isSubmitting.current) {
|
|
34
|
+
isSubmitting.current = false;
|
|
35
35
|
if (error) {
|
|
36
36
|
if (recaptchaRef.current)
|
|
37
37
|
recaptchaRef.current.reset();
|
|
@@ -41,14 +41,14 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
41
41
|
callback();
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
}, [loading, error, callback
|
|
44
|
+
}, [loading, error, callback]);
|
|
45
45
|
const handleChange = (name, value) => {
|
|
46
46
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
47
47
|
};
|
|
48
48
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
49
|
var _a, _b, _c, _d, _e;
|
|
50
50
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
51
|
-
const {
|
|
51
|
+
const { password } = data;
|
|
52
52
|
if (includeRecaptcha) {
|
|
53
53
|
try {
|
|
54
54
|
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
@@ -56,26 +56,26 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
56
56
|
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
57
57
|
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
58
58
|
if (!token) {
|
|
59
|
-
|
|
59
|
+
isSubmitting.current = false;
|
|
60
60
|
setErrors({
|
|
61
61
|
form: 'Please complete the recaptcha before submitting'
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
login(email, password, token);
|
|
66
|
-
|
|
65
|
+
login(data.email || email, password, token);
|
|
66
|
+
isSubmitting.current = true;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
catch (err) {
|
|
70
|
-
|
|
70
|
+
isSubmitting.current = false;
|
|
71
71
|
setErrors({
|
|
72
72
|
form: 'Please complete the recaptcha before submitting'
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
login(email, password);
|
|
78
|
-
|
|
77
|
+
login(data.email || email, password);
|
|
78
|
+
isSubmitting.current = true;
|
|
79
79
|
}
|
|
80
80
|
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
81
81
|
});
|
|
@@ -86,7 +86,7 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
86
86
|
fields,
|
|
87
87
|
data,
|
|
88
88
|
errors,
|
|
89
|
-
submitting,
|
|
89
|
+
submitting: isSubmitting.current,
|
|
90
90
|
handleChange,
|
|
91
91
|
handleSubmit
|
|
92
92
|
};
|
package/package.json
CHANGED