@open-tender/utils 0.5.35 → 0.5.37
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,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,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