@open-tender/utils 0.5.36 → 0.5.38
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/useLoginForm.d.ts +1 -1
- package/dist/cjs/hooks/useLoginForm.js +7 -3
- package/dist/cjs/hooks/useProfileForm.d.ts +72 -3
- package/dist/cjs/hooks/useProfileForm.js +5 -3
- package/dist/esm/hooks/useLoginForm.d.ts +1 -1
- package/dist/esm/hooks/useLoginForm.js +7 -3
- package/dist/esm/hooks/useProfileForm.d.ts +72 -3
- package/dist/esm/hooks/useProfileForm.js +5 -3
- package/package.json +1 -1
|
@@ -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, includeRecaptcha: boolean | undefined, callback?: () => void, showPassword?: boolean) => {
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean | undefined, callback?: () => void, showPassword?: boolean, requiredEmail?: string) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -4,11 +4,14 @@ exports.useLoginForm = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
|
|
7
|
+
const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true, requiredEmail) => {
|
|
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
|
-
const [data, setData] = (0, react_1.useState)({
|
|
11
|
+
const [data, setData] = (0, react_1.useState)({
|
|
12
|
+
email: requiredEmail || '',
|
|
13
|
+
password: ''
|
|
14
|
+
});
|
|
12
15
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
13
16
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
14
17
|
const toRemove = [];
|
|
@@ -19,7 +22,8 @@ const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPas
|
|
|
19
22
|
label: 'Email',
|
|
20
23
|
name: 'email',
|
|
21
24
|
type: 'email',
|
|
22
|
-
required: true
|
|
25
|
+
required: true,
|
|
26
|
+
disabled: !!requiredEmail
|
|
23
27
|
},
|
|
24
28
|
{
|
|
25
29
|
label: 'Password',
|
|
@@ -1,11 +1,80 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Customer, CustomerCreate,
|
|
3
|
-
export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[]) => {
|
|
2
|
+
import { Customer, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[], disabledFields?: string[]) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
data: Customer | null;
|
|
6
6
|
errors: Record<string, string>;
|
|
7
7
|
submitting: boolean;
|
|
8
|
-
fields:
|
|
8
|
+
fields: ({
|
|
9
|
+
disabled: boolean | undefined;
|
|
10
|
+
description?: string | undefined;
|
|
11
|
+
id?: string | undefined;
|
|
12
|
+
label?: string | undefined;
|
|
13
|
+
name: string;
|
|
14
|
+
on?: boolean | undefined;
|
|
15
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
16
|
+
required?: boolean | undefined;
|
|
17
|
+
showLabel?: boolean | undefined;
|
|
18
|
+
type: string;
|
|
19
|
+
} | {
|
|
20
|
+
disabled: boolean | undefined;
|
|
21
|
+
autoComplete?: string | undefined;
|
|
22
|
+
children?: JSX.Element | undefined;
|
|
23
|
+
error?: string | null | undefined;
|
|
24
|
+
icon?: JSX.Element | undefined;
|
|
25
|
+
label?: string | undefined;
|
|
26
|
+
max?: number | undefined;
|
|
27
|
+
min?: number | undefined;
|
|
28
|
+
name: string;
|
|
29
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
30
|
+
onBlur?: ((evt: any) => void) | undefined;
|
|
31
|
+
pattern?: string | undefined;
|
|
32
|
+
placeholder?: string | undefined;
|
|
33
|
+
readOnly?: boolean | undefined;
|
|
34
|
+
required?: boolean | undefined;
|
|
35
|
+
showLabel?: boolean | undefined;
|
|
36
|
+
style?: import("react").CSSProperties | undefined;
|
|
37
|
+
type: string;
|
|
38
|
+
value?: string | number | undefined;
|
|
39
|
+
maxLength?: number | undefined;
|
|
40
|
+
} | {
|
|
41
|
+
disabled: boolean | undefined;
|
|
42
|
+
error?: string | null | undefined;
|
|
43
|
+
label: string;
|
|
44
|
+
name: string;
|
|
45
|
+
onChange?: import("react").ChangeEventHandler<HTMLSelectElement> | undefined;
|
|
46
|
+
options: {
|
|
47
|
+
name: string;
|
|
48
|
+
value: string;
|
|
49
|
+
disabled?: boolean | undefined;
|
|
50
|
+
}[];
|
|
51
|
+
required?: boolean | undefined;
|
|
52
|
+
showLabel?: boolean | undefined;
|
|
53
|
+
type: string;
|
|
54
|
+
value?: string | number | undefined;
|
|
55
|
+
} | {
|
|
56
|
+
disabled: boolean | undefined;
|
|
57
|
+
id?: string | undefined;
|
|
58
|
+
label: string;
|
|
59
|
+
name: string;
|
|
60
|
+
on?: boolean | undefined;
|
|
61
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
62
|
+
type: string;
|
|
63
|
+
} | {
|
|
64
|
+
disabled: boolean | undefined;
|
|
65
|
+
error?: string | null | undefined;
|
|
66
|
+
icon?: JSX.Element | undefined;
|
|
67
|
+
label: string;
|
|
68
|
+
name: string;
|
|
69
|
+
onChange?: import("react").ChangeEventHandler<HTMLTextAreaElement> | undefined;
|
|
70
|
+
placeholder?: string | undefined;
|
|
71
|
+
readOnly?: boolean | undefined;
|
|
72
|
+
required?: boolean | undefined;
|
|
73
|
+
showLabel?: boolean | undefined;
|
|
74
|
+
style?: import("react").CSSProperties | undefined;
|
|
75
|
+
type: string;
|
|
76
|
+
value?: string | undefined;
|
|
77
|
+
})[];
|
|
9
78
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
10
79
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
11
80
|
};
|
|
@@ -24,7 +24,7 @@ const makePayload = (fields, data) => {
|
|
|
24
24
|
rest.birth_date = data.birth_date ? (0, utils_1.slashesToDashes)(data.birth_date) : null;
|
|
25
25
|
return rest;
|
|
26
26
|
};
|
|
27
|
-
const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
|
|
27
|
+
const useProfileForm = (profile, loading, error, update, callback, optionalFields, disabledFields) => {
|
|
28
28
|
const submitRef = (0, react_1.useRef)(null);
|
|
29
29
|
const [data, setData] = (0, react_1.useState)(profile);
|
|
30
30
|
const isSubmitting = (0, react_1.useRef)(false);
|
|
@@ -37,8 +37,10 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
|
|
|
37
37
|
}, [optionalFields]);
|
|
38
38
|
// const fields = allFields.filter((i) => !toRemove.includes(i.name))
|
|
39
39
|
const fields = (0, react_1.useMemo)(() => {
|
|
40
|
-
return allFields
|
|
41
|
-
|
|
40
|
+
return allFields
|
|
41
|
+
.filter(i => !toRemove.includes(i.name))
|
|
42
|
+
.map(i => (Object.assign(Object.assign({}, i), { disabled: disabledFields === null || disabledFields === void 0 ? void 0 : disabledFields.includes(i.name) })));
|
|
43
|
+
}, [toRemove, disabledFields]);
|
|
42
44
|
(0, react_1.useEffect)(() => {
|
|
43
45
|
if (loading === 'idle' && isSubmitting.current) {
|
|
44
46
|
if (error) {
|
|
@@ -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, includeRecaptcha: boolean | undefined, callback?: () => void, showPassword?: boolean) => {
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean | undefined, callback?: () => void, showPassword?: boolean, requiredEmail?: string) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { useState, useEffect, useRef } from 'react';
|
|
3
3
|
import { makeFormErrors } from '../utils';
|
|
4
|
-
export const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
|
|
4
|
+
export const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true, requiredEmail) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
7
|
const recaptchaRef = useRef(null);
|
|
8
|
-
const [data, setData] = useState({
|
|
8
|
+
const [data, setData] = useState({
|
|
9
|
+
email: requiredEmail || '',
|
|
10
|
+
password: ''
|
|
11
|
+
});
|
|
9
12
|
const [errors, setErrors] = useState({});
|
|
10
13
|
const [submitting, setSubmitting] = useState(false);
|
|
11
14
|
const toRemove = [];
|
|
@@ -16,7 +19,8 @@ export const useLoginForm = (loading, error, login, includeRecaptcha, callback,
|
|
|
16
19
|
label: 'Email',
|
|
17
20
|
name: 'email',
|
|
18
21
|
type: 'email',
|
|
19
|
-
required: true
|
|
22
|
+
required: true,
|
|
23
|
+
disabled: !!requiredEmail
|
|
20
24
|
},
|
|
21
25
|
{
|
|
22
26
|
label: 'Password',
|
|
@@ -1,11 +1,80 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Customer, CustomerCreate,
|
|
3
|
-
export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[]) => {
|
|
2
|
+
import { Customer, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[], disabledFields?: string[]) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
data: Customer | null;
|
|
6
6
|
errors: Record<string, string>;
|
|
7
7
|
submitting: boolean;
|
|
8
|
-
fields:
|
|
8
|
+
fields: ({
|
|
9
|
+
disabled: boolean | undefined;
|
|
10
|
+
description?: string | undefined;
|
|
11
|
+
id?: string | undefined;
|
|
12
|
+
label?: string | undefined;
|
|
13
|
+
name: string;
|
|
14
|
+
on?: boolean | undefined;
|
|
15
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
16
|
+
required?: boolean | undefined;
|
|
17
|
+
showLabel?: boolean | undefined;
|
|
18
|
+
type: string;
|
|
19
|
+
} | {
|
|
20
|
+
disabled: boolean | undefined;
|
|
21
|
+
autoComplete?: string | undefined;
|
|
22
|
+
children?: JSX.Element | undefined;
|
|
23
|
+
error?: string | null | undefined;
|
|
24
|
+
icon?: JSX.Element | undefined;
|
|
25
|
+
label?: string | undefined;
|
|
26
|
+
max?: number | undefined;
|
|
27
|
+
min?: number | undefined;
|
|
28
|
+
name: string;
|
|
29
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
30
|
+
onBlur?: ((evt: any) => void) | undefined;
|
|
31
|
+
pattern?: string | undefined;
|
|
32
|
+
placeholder?: string | undefined;
|
|
33
|
+
readOnly?: boolean | undefined;
|
|
34
|
+
required?: boolean | undefined;
|
|
35
|
+
showLabel?: boolean | undefined;
|
|
36
|
+
style?: import("react").CSSProperties | undefined;
|
|
37
|
+
type: string;
|
|
38
|
+
value?: string | number | undefined;
|
|
39
|
+
maxLength?: number | undefined;
|
|
40
|
+
} | {
|
|
41
|
+
disabled: boolean | undefined;
|
|
42
|
+
error?: string | null | undefined;
|
|
43
|
+
label: string;
|
|
44
|
+
name: string;
|
|
45
|
+
onChange?: import("react").ChangeEventHandler<HTMLSelectElement> | undefined;
|
|
46
|
+
options: {
|
|
47
|
+
name: string;
|
|
48
|
+
value: string;
|
|
49
|
+
disabled?: boolean | undefined;
|
|
50
|
+
}[];
|
|
51
|
+
required?: boolean | undefined;
|
|
52
|
+
showLabel?: boolean | undefined;
|
|
53
|
+
type: string;
|
|
54
|
+
value?: string | number | undefined;
|
|
55
|
+
} | {
|
|
56
|
+
disabled: boolean | undefined;
|
|
57
|
+
id?: string | undefined;
|
|
58
|
+
label: string;
|
|
59
|
+
name: string;
|
|
60
|
+
on?: boolean | undefined;
|
|
61
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
62
|
+
type: string;
|
|
63
|
+
} | {
|
|
64
|
+
disabled: boolean | undefined;
|
|
65
|
+
error?: string | null | undefined;
|
|
66
|
+
icon?: JSX.Element | undefined;
|
|
67
|
+
label: string;
|
|
68
|
+
name: string;
|
|
69
|
+
onChange?: import("react").ChangeEventHandler<HTMLTextAreaElement> | undefined;
|
|
70
|
+
placeholder?: string | undefined;
|
|
71
|
+
readOnly?: boolean | undefined;
|
|
72
|
+
required?: boolean | undefined;
|
|
73
|
+
showLabel?: boolean | undefined;
|
|
74
|
+
style?: import("react").CSSProperties | undefined;
|
|
75
|
+
type: string;
|
|
76
|
+
value?: string | undefined;
|
|
77
|
+
})[];
|
|
9
78
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
10
79
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
11
80
|
};
|
|
@@ -21,7 +21,7 @@ const makePayload = (fields, data) => {
|
|
|
21
21
|
rest.birth_date = data.birth_date ? slashesToDashes(data.birth_date) : null;
|
|
22
22
|
return rest;
|
|
23
23
|
};
|
|
24
|
-
export const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
|
|
24
|
+
export const useProfileForm = (profile, loading, error, update, callback, optionalFields, disabledFields) => {
|
|
25
25
|
const submitRef = useRef(null);
|
|
26
26
|
const [data, setData] = useState(profile);
|
|
27
27
|
const isSubmitting = useRef(false);
|
|
@@ -34,8 +34,10 @@ export const useProfileForm = (profile, loading, error, update, callback, option
|
|
|
34
34
|
}, [optionalFields]);
|
|
35
35
|
// const fields = allFields.filter((i) => !toRemove.includes(i.name))
|
|
36
36
|
const fields = useMemo(() => {
|
|
37
|
-
return allFields
|
|
38
|
-
|
|
37
|
+
return allFields
|
|
38
|
+
.filter(i => !toRemove.includes(i.name))
|
|
39
|
+
.map(i => (Object.assign(Object.assign({}, i), { disabled: disabledFields === null || disabledFields === void 0 ? void 0 : disabledFields.includes(i.name) })));
|
|
40
|
+
}, [toRemove, disabledFields]);
|
|
39
41
|
useEffect(() => {
|
|
40
42
|
if (loading === 'idle' && isSubmitting.current) {
|
|
41
43
|
if (error) {
|
package/package.json
CHANGED