@open-tender/utils 0.1.37 → 0.1.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/useCreditCard.js +1 -1
- package/dist/cjs/hooks/useCreditCardForm.d.ts +4 -3
- package/dist/cjs/hooks/useCreditCardForm.js +5 -11
- package/dist/cjs/hooks/useProfileForm.js +0 -3
- package/dist/esm/hooks/useCreditCard.js +1 -1
- package/dist/esm/hooks/useCreditCardForm.d.ts +4 -3
- package/dist/esm/hooks/useCreditCardForm.js +6 -12
- package/dist/esm/hooks/useProfileForm.js +0 -3
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
|
35
35
|
setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
setErrors(
|
|
38
|
+
setErrors({});
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
return {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CardType, CreditCardData, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCardForm: (loading: RequestStatus, error:
|
|
2
|
+
import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData, cardType: CardType, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
6
|
data: CreditCardData;
|
|
7
|
+
errors: CreditCardErrors | Record<string, string>;
|
|
7
8
|
submitting: boolean;
|
|
8
|
-
handleSubmit: (evt
|
|
9
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
9
10
|
};
|
|
@@ -3,22 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useCreditCardForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const __1 = require("../");
|
|
6
|
-
const useCreditCardForm = (loading, error, data, cardType,
|
|
6
|
+
const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
9
9
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
10
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
10
11
|
(0, react_1.useEffect)(() => {
|
|
11
12
|
if (loading === 'idle') {
|
|
12
13
|
setSubmitting(false);
|
|
13
14
|
if (error) {
|
|
15
|
+
setErrors((0, __1.makeFormErrors)(error));
|
|
14
16
|
if (recaptchaRef.current)
|
|
15
17
|
recaptchaRef.current.reset();
|
|
16
|
-
setErrors(error);
|
|
17
|
-
if (windowRef)
|
|
18
|
-
windowRef.scrollTo({ top: 0 });
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
|
-
}, [
|
|
20
|
+
}, [loading, error]);
|
|
22
21
|
const handleSubmit = (evt) => {
|
|
23
22
|
var _a, _b, _c;
|
|
24
23
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
@@ -27,8 +26,6 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
27
26
|
if (cardErrors) {
|
|
28
27
|
setErrors(cardErrors);
|
|
29
28
|
setSubmitting(false);
|
|
30
|
-
if (windowRef)
|
|
31
|
-
windowRef.scrollTo({ top: 0 });
|
|
32
29
|
}
|
|
33
30
|
else {
|
|
34
31
|
const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
|
|
@@ -40,8 +37,6 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
40
37
|
setErrors({
|
|
41
38
|
form: 'Please complete the recaptcha before submitting'
|
|
42
39
|
});
|
|
43
|
-
if (windowRef)
|
|
44
|
-
windowRef.scrollTo({ top: 0 });
|
|
45
40
|
}
|
|
46
41
|
else {
|
|
47
42
|
setSubmitting(true);
|
|
@@ -53,8 +48,6 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
53
48
|
setErrors({
|
|
54
49
|
form: 'Please complete the recaptcha before submitting'
|
|
55
50
|
});
|
|
56
|
-
if (windowRef)
|
|
57
|
-
windowRef.scrollTo({ top: 0 });
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
else {
|
|
@@ -68,6 +61,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
|
|
|
68
61
|
submitRef,
|
|
69
62
|
recaptchaRef,
|
|
70
63
|
data,
|
|
64
|
+
errors,
|
|
71
65
|
submitting,
|
|
72
66
|
handleSubmit
|
|
73
67
|
};
|
|
@@ -32,7 +32,7 @@ export const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
|
32
32
|
setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
setErrors(
|
|
35
|
+
setErrors({});
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
return {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CardType, CreditCardData, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCardForm: (loading: RequestStatus, error:
|
|
2
|
+
import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData, cardType: CardType, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
6
|
data: CreditCardData;
|
|
7
|
+
errors: CreditCardErrors | Record<string, string>;
|
|
7
8
|
submitting: boolean;
|
|
8
|
-
handleSubmit: (evt
|
|
9
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
9
10
|
};
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { validateCreditCard } from '../';
|
|
3
|
-
export const useCreditCardForm = (loading, error, data, cardType,
|
|
2
|
+
import { makeFormErrors, validateCreditCard } from '../';
|
|
3
|
+
export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const recaptchaRef = useRef(null);
|
|
6
6
|
const [submitting, setSubmitting] = useState(false);
|
|
7
|
+
const [errors, setErrors] = useState({});
|
|
7
8
|
useEffect(() => {
|
|
8
9
|
if (loading === 'idle') {
|
|
9
10
|
setSubmitting(false);
|
|
10
11
|
if (error) {
|
|
12
|
+
setErrors(makeFormErrors(error));
|
|
11
13
|
if (recaptchaRef.current)
|
|
12
14
|
recaptchaRef.current.reset();
|
|
13
|
-
setErrors(error);
|
|
14
|
-
if (windowRef)
|
|
15
|
-
windowRef.scrollTo({ top: 0 });
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
}, [
|
|
17
|
+
}, [loading, error]);
|
|
19
18
|
const handleSubmit = (evt) => {
|
|
20
19
|
var _a, _b, _c;
|
|
21
20
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
@@ -24,8 +23,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
24
23
|
if (cardErrors) {
|
|
25
24
|
setErrors(cardErrors);
|
|
26
25
|
setSubmitting(false);
|
|
27
|
-
if (windowRef)
|
|
28
|
-
windowRef.scrollTo({ top: 0 });
|
|
29
26
|
}
|
|
30
27
|
else {
|
|
31
28
|
const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
|
|
@@ -37,8 +34,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
37
34
|
setErrors({
|
|
38
35
|
form: 'Please complete the recaptcha before submitting'
|
|
39
36
|
});
|
|
40
|
-
if (windowRef)
|
|
41
|
-
windowRef.scrollTo({ top: 0 });
|
|
42
37
|
}
|
|
43
38
|
else {
|
|
44
39
|
setSubmitting(true);
|
|
@@ -50,8 +45,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
50
45
|
setErrors({
|
|
51
46
|
form: 'Please complete the recaptcha before submitting'
|
|
52
47
|
});
|
|
53
|
-
if (windowRef)
|
|
54
|
-
windowRef.scrollTo({ top: 0 });
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
else {
|
|
@@ -65,6 +58,7 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
|
|
|
65
58
|
submitRef,
|
|
66
59
|
recaptchaRef,
|
|
67
60
|
data,
|
|
61
|
+
errors,
|
|
68
62
|
submitting,
|
|
69
63
|
handleSubmit
|
|
70
64
|
};
|
package/package.json
CHANGED