@open-tender/utils 0.1.61 → 0.1.63
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.
- package/dist/cjs/hooks/useCheckoutLoginForm.d.ts +2 -2
- package/dist/cjs/hooks/useGuestForm.js +1 -0
- package/dist/cjs/hooks/useSendResetForm.d.ts +10 -6
- package/dist/cjs/hooks/useSendResetForm.js +30 -13
- package/dist/esm/hooks/useCheckoutLoginForm.d.ts +2 -2
- package/dist/esm/hooks/useGuestForm.js +1 -0
- package/dist/esm/hooks/useSendResetForm.d.ts +10 -6
- package/dist/esm/hooks/useSendResetForm.js +30 -13
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { FormFields, LoginData, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error:
|
|
2
|
+
import { FormFields, LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: FormFields;
|
|
@@ -41,6 +41,7 @@ const useGuestForm = (email, loading, error, checkGuest) => {
|
|
|
41
41
|
const handleSubmit = (evt) => {
|
|
42
42
|
var _a, _b;
|
|
43
43
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
44
|
+
setSubmitting(true);
|
|
44
45
|
if (data.email)
|
|
45
46
|
checkGuest(data.email);
|
|
46
47
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useSendResetForm: (loading: RequestStatus, error:
|
|
2
|
+
import { FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useSendResetForm: (loading: RequestStatus, error: RequestError, sendReset: (email: string, linkUrl: string) => void, callback?: () => void, windowRef?: Window, linkUrlVal?: string) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: {
|
|
8
|
+
email: string;
|
|
9
|
+
};
|
|
10
|
+
errors: Record<string, string>;
|
|
11
|
+
submitting: boolean;
|
|
12
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
13
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
10
14
|
};
|
|
@@ -2,37 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSendResetForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const useSendResetForm = (loading, error, sendReset, callback, windowRef, linkUrlVal) => {
|
|
6
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
7
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [data, setData] = (0, react_1.useState)({});
|
|
9
|
-
const
|
|
9
|
+
const [data, setData] = (0, react_1.useState)({ email: '' });
|
|
10
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
+
const fields = [
|
|
13
|
+
{
|
|
14
|
+
label: 'Email',
|
|
15
|
+
name: 'email',
|
|
16
|
+
type: 'email',
|
|
17
|
+
required: true
|
|
18
|
+
}
|
|
19
|
+
];
|
|
10
20
|
(0, react_1.useEffect)(() => {
|
|
11
21
|
var _a, _b;
|
|
12
|
-
if (loading === 'idle'
|
|
13
|
-
(
|
|
22
|
+
if (loading === 'idle') {
|
|
23
|
+
setSubmitting(false);
|
|
24
|
+
if (error) {
|
|
25
|
+
const errs = (0, utils_1.makeFormErrors)(error);
|
|
26
|
+
setErrors(errs);
|
|
27
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
28
|
+
}
|
|
29
|
+
else if (callback) {
|
|
30
|
+
callback();
|
|
31
|
+
}
|
|
14
32
|
}
|
|
15
|
-
}, [loading, error]);
|
|
33
|
+
}, [loading, error, callback]);
|
|
16
34
|
const handleChange = (name, value) => {
|
|
17
35
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
18
36
|
};
|
|
19
37
|
const handleSubmit = (evt) => {
|
|
20
38
|
var _a, _b;
|
|
21
39
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
22
|
-
const linkUrl =
|
|
23
|
-
? `${
|
|
40
|
+
const linkUrl = windowRef
|
|
41
|
+
? `${windowRef.location.origin}/reset-password`
|
|
24
42
|
: `${linkUrlVal}`;
|
|
25
|
-
sendReset(data.email, linkUrl)
|
|
26
|
-
if (callback)
|
|
27
|
-
callback();
|
|
28
|
-
});
|
|
43
|
+
sendReset(data.email, linkUrl);
|
|
29
44
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
30
45
|
};
|
|
31
46
|
return {
|
|
32
47
|
submitRef,
|
|
33
48
|
inputRef,
|
|
49
|
+
fields,
|
|
34
50
|
data,
|
|
35
|
-
|
|
51
|
+
errors,
|
|
52
|
+
submitting,
|
|
36
53
|
handleChange,
|
|
37
54
|
handleSubmit
|
|
38
55
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { FormFields, LoginData, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error:
|
|
2
|
+
import { FormFields, LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: FormFields;
|
|
@@ -38,6 +38,7 @@ export const useGuestForm = (email, loading, error, checkGuest) => {
|
|
|
38
38
|
const handleSubmit = (evt) => {
|
|
39
39
|
var _a, _b;
|
|
40
40
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
41
|
+
setSubmitting(true);
|
|
41
42
|
if (data.email)
|
|
42
43
|
checkGuest(data.email);
|
|
43
44
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useSendResetForm: (loading: RequestStatus, error:
|
|
2
|
+
import { FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useSendResetForm: (loading: RequestStatus, error: RequestError, sendReset: (email: string, linkUrl: string) => void, callback?: () => void, windowRef?: Window, linkUrlVal?: string) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: {
|
|
8
|
+
email: string;
|
|
9
|
+
};
|
|
10
|
+
errors: Record<string, string>;
|
|
11
|
+
submitting: boolean;
|
|
12
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
13
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
10
14
|
};
|
|
@@ -1,35 +1,52 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
|
|
2
|
+
import { makeFormErrors } from '../utils';
|
|
3
|
+
export const useSendResetForm = (loading, error, sendReset, callback, windowRef, linkUrlVal) => {
|
|
3
4
|
const submitRef = useRef(null);
|
|
4
5
|
const inputRef = useRef(null);
|
|
5
|
-
const [data, setData] = useState({});
|
|
6
|
-
const
|
|
6
|
+
const [data, setData] = useState({ email: '' });
|
|
7
|
+
const [errors, setErrors] = useState({});
|
|
8
|
+
const [submitting, setSubmitting] = useState(false);
|
|
9
|
+
const fields = [
|
|
10
|
+
{
|
|
11
|
+
label: 'Email',
|
|
12
|
+
name: 'email',
|
|
13
|
+
type: 'email',
|
|
14
|
+
required: true
|
|
15
|
+
}
|
|
16
|
+
];
|
|
7
17
|
useEffect(() => {
|
|
8
18
|
var _a, _b;
|
|
9
|
-
if (loading === 'idle'
|
|
10
|
-
(
|
|
19
|
+
if (loading === 'idle') {
|
|
20
|
+
setSubmitting(false);
|
|
21
|
+
if (error) {
|
|
22
|
+
const errs = makeFormErrors(error);
|
|
23
|
+
setErrors(errs);
|
|
24
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
25
|
+
}
|
|
26
|
+
else if (callback) {
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
11
29
|
}
|
|
12
|
-
}, [loading, error]);
|
|
30
|
+
}, [loading, error, callback]);
|
|
13
31
|
const handleChange = (name, value) => {
|
|
14
32
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
15
33
|
};
|
|
16
34
|
const handleSubmit = (evt) => {
|
|
17
35
|
var _a, _b;
|
|
18
36
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
19
|
-
const linkUrl =
|
|
20
|
-
? `${
|
|
37
|
+
const linkUrl = windowRef
|
|
38
|
+
? `${windowRef.location.origin}/reset-password`
|
|
21
39
|
: `${linkUrlVal}`;
|
|
22
|
-
sendReset(data.email, linkUrl)
|
|
23
|
-
if (callback)
|
|
24
|
-
callback();
|
|
25
|
-
});
|
|
40
|
+
sendReset(data.email, linkUrl);
|
|
26
41
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
27
42
|
};
|
|
28
43
|
return {
|
|
29
44
|
submitRef,
|
|
30
45
|
inputRef,
|
|
46
|
+
fields,
|
|
31
47
|
data,
|
|
32
|
-
|
|
48
|
+
errors,
|
|
49
|
+
submitting,
|
|
33
50
|
handleChange,
|
|
34
51
|
handleSubmit
|
|
35
52
|
};
|
package/package.json
CHANGED