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