@open-tender/utils 0.5.23 → 0.5.25
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.
|
@@ -27,7 +27,7 @@ const makePayload = (fields, data) => {
|
|
|
27
27
|
const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
|
|
28
28
|
const submitRef = (0, react_1.useRef)(null);
|
|
29
29
|
const [data, setData] = (0, react_1.useState)(profile);
|
|
30
|
-
const
|
|
30
|
+
const isSubmitting = (0, react_1.useRef)(false);
|
|
31
31
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
32
32
|
const toRemove = (0, react_1.useMemo)(() => {
|
|
33
33
|
const removed = [];
|
|
@@ -41,7 +41,7 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
|
|
|
41
41
|
}, [toRemove]);
|
|
42
42
|
(0, react_1.useEffect)(() => {
|
|
43
43
|
if (loading === 'idle') {
|
|
44
|
-
|
|
44
|
+
isSubmitting.current = false;
|
|
45
45
|
if (error) {
|
|
46
46
|
const errs = (0, utils_1.makeFormErrors)(error);
|
|
47
47
|
if (errs.birth_date) {
|
|
@@ -50,13 +50,13 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
|
|
|
50
50
|
}
|
|
51
51
|
setErrors(errs);
|
|
52
52
|
}
|
|
53
|
-
else if (callback &&
|
|
53
|
+
else if (callback && isSubmitting.current) {
|
|
54
54
|
const payload = makePayload(fields, data);
|
|
55
55
|
if (payload)
|
|
56
56
|
callback(payload);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
}, [loading, error, callback,
|
|
59
|
+
}, [loading, error, callback, fields, data]);
|
|
60
60
|
(0, react_1.useEffect)(() => {
|
|
61
61
|
if (profile)
|
|
62
62
|
setData(profile);
|
|
@@ -79,7 +79,7 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
|
|
|
79
79
|
if (!data)
|
|
80
80
|
return;
|
|
81
81
|
setErrors({});
|
|
82
|
-
|
|
82
|
+
isSubmitting.current = true;
|
|
83
83
|
const payload = makePayload(fields, data);
|
|
84
84
|
if (payload)
|
|
85
85
|
update(payload);
|
|
@@ -91,7 +91,7 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
|
|
|
91
91
|
// order_notifications,
|
|
92
92
|
data,
|
|
93
93
|
errors,
|
|
94
|
-
submitting,
|
|
94
|
+
submitting: isSubmitting.current,
|
|
95
95
|
fields,
|
|
96
96
|
handleChange,
|
|
97
97
|
// handleRadio,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
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, recaptcha_token?: string) => void, includeRecaptcha
|
|
3
|
+
export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha?: boolean | null, callback?: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -24,7 +24,7 @@ const makePayload = (fields, data) => {
|
|
|
24
24
|
export const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
|
|
25
25
|
const submitRef = useRef(null);
|
|
26
26
|
const [data, setData] = useState(profile);
|
|
27
|
-
const
|
|
27
|
+
const isSubmitting = useRef(false);
|
|
28
28
|
const [errors, setErrors] = useState({});
|
|
29
29
|
const toRemove = useMemo(() => {
|
|
30
30
|
const removed = [];
|
|
@@ -38,7 +38,7 @@ export const useProfileForm = (profile, loading, error, update, callback, option
|
|
|
38
38
|
}, [toRemove]);
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
if (loading === 'idle') {
|
|
41
|
-
|
|
41
|
+
isSubmitting.current = false;
|
|
42
42
|
if (error) {
|
|
43
43
|
const errs = makeFormErrors(error);
|
|
44
44
|
if (errs.birth_date) {
|
|
@@ -47,13 +47,13 @@ export const useProfileForm = (profile, loading, error, update, callback, option
|
|
|
47
47
|
}
|
|
48
48
|
setErrors(errs);
|
|
49
49
|
}
|
|
50
|
-
else if (callback &&
|
|
50
|
+
else if (callback && isSubmitting.current) {
|
|
51
51
|
const payload = makePayload(fields, data);
|
|
52
52
|
if (payload)
|
|
53
53
|
callback(payload);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
}, [loading, error, callback,
|
|
56
|
+
}, [loading, error, callback, fields, data]);
|
|
57
57
|
useEffect(() => {
|
|
58
58
|
if (profile)
|
|
59
59
|
setData(profile);
|
|
@@ -76,7 +76,7 @@ export const useProfileForm = (profile, loading, error, update, callback, option
|
|
|
76
76
|
if (!data)
|
|
77
77
|
return;
|
|
78
78
|
setErrors({});
|
|
79
|
-
|
|
79
|
+
isSubmitting.current = true;
|
|
80
80
|
const payload = makePayload(fields, data);
|
|
81
81
|
if (payload)
|
|
82
82
|
update(payload);
|
|
@@ -88,7 +88,7 @@ export const useProfileForm = (profile, loading, error, update, callback, option
|
|
|
88
88
|
// order_notifications,
|
|
89
89
|
data,
|
|
90
90
|
errors,
|
|
91
|
-
submitting,
|
|
91
|
+
submitting: isSubmitting.current,
|
|
92
92
|
fields,
|
|
93
93
|
handleChange,
|
|
94
94
|
// handleRadio,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
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, recaptcha_token?: string) => void, includeRecaptcha
|
|
3
|
+
export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha?: boolean | null, callback?: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
package/package.json
CHANGED