@open-tender/utils 0.5.18 → 0.5.19
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,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void,
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -9,5 +9,5 @@ export declare const useLoginForm: (loading: RequestStatus, error: RequestError,
|
|
|
9
9
|
errors: Record<string, string>;
|
|
10
10
|
submitting: boolean;
|
|
11
11
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
12
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
12
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
13
13
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLoginForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
|
-
const useLoginForm = (loading, error, login,
|
|
7
|
+
const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
|
|
7
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
10
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
@@ -47,13 +48,16 @@ const useLoginForm = (loading, error, login, recaptchaKey, callback, showPasswor
|
|
|
47
48
|
const handleChange = (name, value) => {
|
|
48
49
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
49
50
|
};
|
|
50
|
-
const handleSubmit = (evt) => {
|
|
51
|
-
var _a, _b, _c;
|
|
51
|
+
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
var _a, _b, _c, _d, _e;
|
|
52
53
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
53
54
|
const { email, password } = data;
|
|
54
|
-
if (
|
|
55
|
+
if (includeRecaptcha) {
|
|
55
56
|
try {
|
|
56
|
-
const
|
|
57
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
58
|
+
const token = isEnterpriseRecaptcha
|
|
59
|
+
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
60
|
+
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
57
61
|
if (!token) {
|
|
58
62
|
setSubmitting(false);
|
|
59
63
|
setErrors({
|
|
@@ -78,8 +82,8 @@ const useLoginForm = (loading, error, login, recaptchaKey, callback, showPasswor
|
|
|
78
82
|
login(email, password);
|
|
79
83
|
setSubmitting(true);
|
|
80
84
|
}
|
|
81
|
-
((
|
|
82
|
-
};
|
|
85
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
86
|
+
});
|
|
83
87
|
return {
|
|
84
88
|
submitRef,
|
|
85
89
|
inputRef,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void,
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -9,5 +9,5 @@ export declare const useLoginForm: (loading: RequestStatus, error: RequestError,
|
|
|
9
9
|
errors: Record<string, string>;
|
|
10
10
|
submitting: boolean;
|
|
11
11
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
12
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
12
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
13
13
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { useState, useEffect, useRef } from 'react';
|
|
2
3
|
import { makeFormErrors } from '../utils';
|
|
3
|
-
export const useLoginForm = (loading, error, login,
|
|
4
|
+
export const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
|
|
4
5
|
const submitRef = useRef(null);
|
|
5
6
|
const inputRef = useRef(null);
|
|
6
7
|
const recaptchaRef = useRef(null);
|
|
@@ -44,13 +45,16 @@ export const useLoginForm = (loading, error, login, recaptchaKey, callback, show
|
|
|
44
45
|
const handleChange = (name, value) => {
|
|
45
46
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
46
47
|
};
|
|
47
|
-
const handleSubmit = (evt) => {
|
|
48
|
-
var _a, _b, _c;
|
|
48
|
+
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
var _a, _b, _c, _d, _e;
|
|
49
50
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
50
51
|
const { email, password } = data;
|
|
51
|
-
if (
|
|
52
|
+
if (includeRecaptcha) {
|
|
52
53
|
try {
|
|
53
|
-
const
|
|
54
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
55
|
+
const token = isEnterpriseRecaptcha
|
|
56
|
+
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
57
|
+
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
54
58
|
if (!token) {
|
|
55
59
|
setSubmitting(false);
|
|
56
60
|
setErrors({
|
|
@@ -75,8 +79,8 @@ export const useLoginForm = (loading, error, login, recaptchaKey, callback, show
|
|
|
75
79
|
login(email, password);
|
|
76
80
|
setSubmitting(true);
|
|
77
81
|
}
|
|
78
|
-
((
|
|
79
|
-
};
|
|
82
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
83
|
+
});
|
|
80
84
|
return {
|
|
81
85
|
submitRef,
|
|
82
86
|
inputRef,
|
package/package.json
CHANGED