@open-tender/utils 0.5.39 → 0.5.40
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/useCreditCardForm.d.ts +1 -2
- package/dist/cjs/hooks/useCreditCardForm.js +4 -11
- package/dist/cjs/hooks/useDonationForm.d.ts +1 -2
- package/dist/cjs/hooks/useDonationForm.js +2 -10
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +1 -2
- package/dist/cjs/hooks/useGiftCardsForm.js +2 -10
- package/dist/cjs/hooks/useLoginForm.d.ts +1 -2
- package/dist/cjs/hooks/useLoginForm.js +4 -11
- package/dist/cjs/hooks/useOneTimePasscodeForm.d.ts +1 -2
- package/dist/cjs/hooks/useOneTimePasscodeForm.js +4 -11
- package/dist/cjs/hooks/useSignUpForm.d.ts +1 -2
- package/dist/cjs/hooks/useSignUpForm.js +4 -11
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +1 -2
- package/dist/cjs/hooks/useSignUpGuestForm.js +4 -11
- package/dist/cjs/hooks/useSigninForm.d.ts +1 -2
- package/dist/cjs/hooks/useSigninForm.js +4 -11
- package/dist/esm/hooks/useCreditCardForm.d.ts +1 -2
- package/dist/esm/hooks/useCreditCardForm.js +4 -11
- package/dist/esm/hooks/useDonationForm.d.ts +1 -2
- package/dist/esm/hooks/useDonationForm.js +2 -10
- package/dist/esm/hooks/useGiftCardsForm.d.ts +1 -2
- package/dist/esm/hooks/useGiftCardsForm.js +2 -10
- package/dist/esm/hooks/useLoginForm.d.ts +1 -2
- package/dist/esm/hooks/useLoginForm.js +4 -11
- package/dist/esm/hooks/useOneTimePasscodeForm.d.ts +1 -2
- package/dist/esm/hooks/useOneTimePasscodeForm.js +4 -11
- package/dist/esm/hooks/useSignUpForm.d.ts +1 -2
- package/dist/esm/hooks/useSignUpForm.js +4 -11
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +1 -2
- package/dist/esm/hooks/useSignUpGuestForm.js +4 -11
- package/dist/esm/hooks/useSigninForm.d.ts +1 -2
- package/dist/esm/hooks/useSigninForm.js +4 -11
- package/package.json +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, includeRecaptcha: boolean | undefined, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean) => {
|
|
3
|
+
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, includeRecaptcha: boolean | undefined, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
5
|
data: CreditCardData | null;
|
|
7
6
|
errors: Record<string, string> | CreditCardErrors;
|
|
8
7
|
submitting: boolean;
|
|
@@ -4,9 +4,8 @@ exports.useCreditCardForm = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const __1 = require("../");
|
|
7
|
-
const useCreditCardForm = (loading, error, data, cardType, addCard, callback, includeRecaptcha, revenue_center_id, kountSessionId, requireCardholderName = false) => {
|
|
7
|
+
const useCreditCardForm = (loading, error, data, cardType, addCard, callback, includeRecaptcha, revenue_center_id, kountSessionId, requireCardholderName = false, getRecaptchaToken) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
10
9
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
11
10
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
12
11
|
(0, react_1.useEffect)(() => {
|
|
@@ -14,13 +13,11 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, in
|
|
|
14
13
|
setSubmitting(false);
|
|
15
14
|
if (error) {
|
|
16
15
|
setErrors((0, __1.makeFormErrors)(error));
|
|
17
|
-
if (recaptchaRef.current)
|
|
18
|
-
recaptchaRef.current.reset();
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
}, [loading, error]);
|
|
22
19
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
var _a, _b
|
|
20
|
+
var _a, _b;
|
|
24
21
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
25
22
|
setErrors({});
|
|
26
23
|
if (!data || !cardType)
|
|
@@ -36,10 +33,7 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, in
|
|
|
36
33
|
cardRc.kount_device_session_id = kountSessionId;
|
|
37
34
|
if (includeRecaptcha) {
|
|
38
35
|
try {
|
|
39
|
-
const
|
|
40
|
-
const token = isEnterpriseRecaptcha
|
|
41
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
42
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
36
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
43
37
|
if (!token) {
|
|
44
38
|
setSubmitting(false);
|
|
45
39
|
setErrors({
|
|
@@ -63,11 +57,10 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, in
|
|
|
63
57
|
addCard(cardRc, callback);
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
|
-
((
|
|
60
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
67
61
|
});
|
|
68
62
|
return {
|
|
69
63
|
submitRef,
|
|
70
|
-
recaptchaRef,
|
|
71
64
|
data,
|
|
72
65
|
errors,
|
|
73
66
|
submitting,
|
|
@@ -3,10 +3,9 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, Donat
|
|
|
3
3
|
export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
10
9
|
amount: string | null;
|
|
11
10
|
handleAmount: (value: string) => void;
|
|
12
11
|
email: string | null;
|
|
@@ -4,10 +4,9 @@ exports.useDonationsForm = 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 useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, includeRecaptcha, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
|
|
7
|
+
const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, includeRecaptcha, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false, getRecaptchaToken) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
10
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
11
10
|
const [amount, setAmount] = (0, react_1.useState)('');
|
|
12
11
|
const [email, setEmail] = (0, react_1.useState)('');
|
|
13
12
|
const [isNewCard, setIsNewCard] = (0, react_1.useState)(true);
|
|
@@ -29,8 +28,6 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
29
28
|
setSubmitting(false);
|
|
30
29
|
setAlert({ type: 'close' });
|
|
31
30
|
if (error) {
|
|
32
|
-
if (recaptchaRef.current)
|
|
33
|
-
recaptchaRef.current.reset();
|
|
34
31
|
setErrors((0, utils_1.makeFormErrors)(error));
|
|
35
32
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
36
33
|
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
@@ -69,7 +66,6 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
69
66
|
setCreditCard({ customer_card_id: customerCardId });
|
|
70
67
|
};
|
|
71
68
|
const purchaseWithCaptcha = (credit_card) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
-
var _a, _b, _c;
|
|
73
69
|
const alert = {
|
|
74
70
|
type: 'working',
|
|
75
71
|
args: { text: 'Submitting your contribution...' }
|
|
@@ -84,10 +80,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
84
80
|
formData.kount_device_session_id = kountSessionId;
|
|
85
81
|
if (includeRecaptcha) {
|
|
86
82
|
try {
|
|
87
|
-
const
|
|
88
|
-
const token = isEnterpriseRecaptcha
|
|
89
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
90
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
83
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
91
84
|
if (!token) {
|
|
92
85
|
setSubmitting(false);
|
|
93
86
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
@@ -154,7 +147,6 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
154
147
|
return {
|
|
155
148
|
inputRef,
|
|
156
149
|
submitRef,
|
|
157
|
-
recaptchaRef,
|
|
158
150
|
amount,
|
|
159
151
|
handleAmount,
|
|
160
152
|
email,
|
|
@@ -3,10 +3,9 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftC
|
|
|
3
3
|
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
10
9
|
creditCardOptions: {
|
|
11
10
|
name: string;
|
|
12
11
|
value: unknown;
|
|
@@ -4,10 +4,9 @@ exports.useGiftCardsForm = 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 useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, includeRecaptcha, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
|
|
7
|
+
const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, includeRecaptcha, cardData, cardType, url, kountSessionId, requireCardholderName = false, getRecaptchaToken) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
10
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
11
10
|
const [name, setName] = (0, react_1.useState)(null);
|
|
12
11
|
const [email, setEmail] = (0, react_1.useState)(null);
|
|
13
12
|
const [cards, setCards] = (0, react_1.useState)([initState]);
|
|
@@ -26,8 +25,6 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
26
25
|
setSubmitting(false);
|
|
27
26
|
setAlert({ type: 'close' });
|
|
28
27
|
if (error) {
|
|
29
|
-
if (recaptchaRef.current)
|
|
30
|
-
recaptchaRef.current.reset();
|
|
31
28
|
setErrors((0, utils_1.makeFormErrors)(error));
|
|
32
29
|
}
|
|
33
30
|
}
|
|
@@ -90,7 +87,6 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
90
87
|
setCreditCard({ customer_card_id: customerCardId });
|
|
91
88
|
};
|
|
92
89
|
const purchaseWithCaptcha = (credit_card) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
-
var _a, _b, _c;
|
|
94
90
|
const alert = {
|
|
95
91
|
type: 'working',
|
|
96
92
|
args: { text: 'Submitting your purchase...' }
|
|
@@ -105,10 +101,7 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
105
101
|
formData.kount_device_session_id = kountSessionId;
|
|
106
102
|
if (includeRecaptcha) {
|
|
107
103
|
try {
|
|
108
|
-
const
|
|
109
|
-
const token = isEnterpriseRecaptcha
|
|
110
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
111
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
104
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
112
105
|
if (!token) {
|
|
113
106
|
setSubmitting(false);
|
|
114
107
|
setErrors({
|
|
@@ -171,7 +164,6 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
171
164
|
return {
|
|
172
165
|
inputRef,
|
|
173
166
|
submitRef,
|
|
174
|
-
recaptchaRef,
|
|
175
167
|
creditCardOptions,
|
|
176
168
|
handleName,
|
|
177
169
|
handleEmail,
|
|
@@ -1,9 +1,8 @@
|
|
|
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, requiredEmail?: string) => {
|
|
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, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
7
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
8
7
|
data: LoginData;
|
|
9
8
|
errors: Record<string, string>;
|
|
@@ -4,10 +4,9 @@ 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, requiredEmail) => {
|
|
7
|
+
const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true, requiredEmail, getRecaptchaToken) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
10
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
11
10
|
const [data, setData] = (0, react_1.useState)({
|
|
12
11
|
email: requiredEmail || '',
|
|
13
12
|
password: ''
|
|
@@ -39,8 +38,6 @@ const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPas
|
|
|
39
38
|
if (loading === 'idle' && submitting) {
|
|
40
39
|
setSubmitting(false);
|
|
41
40
|
if (error) {
|
|
42
|
-
if (recaptchaRef.current)
|
|
43
|
-
recaptchaRef.current.reset();
|
|
44
41
|
setErrors((0, utils_1.makeFormErrors)(error));
|
|
45
42
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
46
43
|
}
|
|
@@ -53,15 +50,12 @@ const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPas
|
|
|
53
50
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
54
51
|
};
|
|
55
52
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
var _a, _b
|
|
53
|
+
var _a, _b;
|
|
57
54
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
58
55
|
const { email, password } = data;
|
|
59
56
|
if (includeRecaptcha) {
|
|
60
57
|
try {
|
|
61
|
-
const
|
|
62
|
-
const token = isEnterpriseRecaptcha
|
|
63
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
64
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
58
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
65
59
|
if (!token) {
|
|
66
60
|
setSubmitting(false);
|
|
67
61
|
setErrors({
|
|
@@ -86,12 +80,11 @@ const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPas
|
|
|
86
80
|
login(email, password);
|
|
87
81
|
setSubmitting(true);
|
|
88
82
|
}
|
|
89
|
-
((
|
|
83
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
90
84
|
});
|
|
91
85
|
return {
|
|
92
86
|
submitRef,
|
|
93
87
|
inputRef,
|
|
94
|
-
recaptchaRef,
|
|
95
88
|
fields,
|
|
96
89
|
data,
|
|
97
90
|
errors,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CustomerSignIn, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, includeRecaptcha: boolean | undefined, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
|
|
3
|
+
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, includeRecaptcha: boolean | undefined, submit: (data: CustomerSignIn) => void, callback?: () => void, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
7
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
8
7
|
data: {
|
|
9
8
|
identifier: string;
|
|
@@ -4,10 +4,9 @@ exports.useOneTimePasscodeForm = 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 useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submit, callback) => {
|
|
7
|
+
const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submit, callback, getRecaptchaToken) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
10
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
11
10
|
const [data, setData] = (0, react_1.useState)({
|
|
12
11
|
identifier: '',
|
|
13
12
|
one_time_passcode: ''
|
|
@@ -35,8 +34,6 @@ const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submi
|
|
|
35
34
|
if (loading === 'idle' && submitting) {
|
|
36
35
|
setSubmitting(false);
|
|
37
36
|
if (error) {
|
|
38
|
-
if (recaptchaRef.current)
|
|
39
|
-
recaptchaRef.current.reset();
|
|
40
37
|
const errs = (0, utils_1.makeFormErrors)(error);
|
|
41
38
|
if (errs.form.includes('not found')) {
|
|
42
39
|
errs.form =
|
|
@@ -66,7 +63,7 @@ const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submi
|
|
|
66
63
|
}
|
|
67
64
|
};
|
|
68
65
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
-
var _a, _b
|
|
66
|
+
var _a, _b;
|
|
70
67
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
71
68
|
const { identifier, one_time_passcode } = data;
|
|
72
69
|
const values = /[a-zA-Z]/g.test(identifier)
|
|
@@ -74,10 +71,7 @@ const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submi
|
|
|
74
71
|
: { phone: identifier };
|
|
75
72
|
if (includeRecaptcha) {
|
|
76
73
|
try {
|
|
77
|
-
const
|
|
78
|
-
const token = isEnterpriseRecaptcha
|
|
79
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
80
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
74
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
81
75
|
if (!token) {
|
|
82
76
|
setSubmitting(false);
|
|
83
77
|
setErrors({
|
|
@@ -102,12 +96,11 @@ const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submi
|
|
|
102
96
|
otpSent ? submit({ one_time_passcode }) : submit(values);
|
|
103
97
|
setSubmitting(true);
|
|
104
98
|
}
|
|
105
|
-
((
|
|
99
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
106
100
|
});
|
|
107
101
|
return {
|
|
108
102
|
submitRef,
|
|
109
103
|
inputRef,
|
|
110
|
-
recaptchaRef,
|
|
111
104
|
fields,
|
|
112
105
|
data,
|
|
113
106
|
errors,
|
|
@@ -6,8 +6,7 @@ export interface NotificationCheckbox {
|
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const notificationChannelFields: NotificationCheckbox[];
|
|
9
|
-
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean) => {
|
|
10
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
9
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
11
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
12
11
|
data: CustomerCreate;
|
|
13
12
|
comms: NotificationChannel[];
|
|
@@ -27,8 +27,7 @@ exports.notificationChannelFields = [
|
|
|
27
27
|
type: 'checkbox'
|
|
28
28
|
}
|
|
29
29
|
];
|
|
30
|
-
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha) => {
|
|
31
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
30
|
+
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken) => {
|
|
32
31
|
const submitRef = (0, react_1.useRef)(null);
|
|
33
32
|
const [data, setData] = (0, react_1.useState)(initState);
|
|
34
33
|
const [comms, setComms] = (0, react_1.useState)([]);
|
|
@@ -104,8 +103,6 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
104
103
|
errs.birth_date =
|
|
105
104
|
'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
|
|
106
105
|
}
|
|
107
|
-
if (recaptchaRef.current)
|
|
108
|
-
recaptchaRef.current.reset();
|
|
109
106
|
setErrors(errs);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
@@ -124,7 +121,7 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
124
121
|
setComms(updated);
|
|
125
122
|
};
|
|
126
123
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
-
var _a, _b
|
|
124
|
+
var _a, _b;
|
|
128
125
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
129
126
|
setErrors({});
|
|
130
127
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
@@ -133,10 +130,7 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
133
130
|
}
|
|
134
131
|
if (includeRecaptcha) {
|
|
135
132
|
try {
|
|
136
|
-
const
|
|
137
|
-
const token = isEnterpriseRecaptcha
|
|
138
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
139
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
133
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
140
134
|
if (!token) {
|
|
141
135
|
setErrors({
|
|
142
136
|
form: 'Please complete the recaptcha before submitting'
|
|
@@ -157,10 +151,9 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
157
151
|
setSubmitting(true);
|
|
158
152
|
signUp(values, callback);
|
|
159
153
|
}
|
|
160
|
-
((
|
|
154
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
161
155
|
});
|
|
162
156
|
return {
|
|
163
|
-
recaptchaRef,
|
|
164
157
|
submitRef,
|
|
165
158
|
data,
|
|
166
159
|
comms,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean) => {
|
|
4
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
3
|
+
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
5
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
6
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
7
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -12,8 +12,7 @@ const initialData = {
|
|
|
12
12
|
email: '',
|
|
13
13
|
password: ''
|
|
14
14
|
};
|
|
15
|
-
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha) => {
|
|
16
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
15
|
+
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken) => {
|
|
17
16
|
const submitRef = (0, react_1.useRef)(null);
|
|
18
17
|
const inputRef = (0, react_1.useRef)(null);
|
|
19
18
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -80,7 +79,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
80
79
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
81
80
|
};
|
|
82
81
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
var _a, _b
|
|
82
|
+
var _a, _b;
|
|
84
83
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
85
84
|
if (!disabled) {
|
|
86
85
|
setErrors({});
|
|
@@ -90,10 +89,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
90
89
|
}
|
|
91
90
|
if (includeRecaptcha) {
|
|
92
91
|
try {
|
|
93
|
-
const
|
|
94
|
-
const token = isEnterpriseRecaptcha
|
|
95
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
96
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
92
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
97
93
|
if (!token) {
|
|
98
94
|
setErrors({
|
|
99
95
|
form: 'Please complete the recaptcha before submitting'
|
|
@@ -114,7 +110,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
114
110
|
setSubmitting(true);
|
|
115
111
|
signUp(values);
|
|
116
112
|
}
|
|
117
|
-
((
|
|
113
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
118
114
|
}
|
|
119
115
|
});
|
|
120
116
|
const handleGuest = () => {
|
|
@@ -139,8 +135,6 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
139
135
|
errs.form = 'There are one or more errors below';
|
|
140
136
|
}
|
|
141
137
|
setErrors(errs);
|
|
142
|
-
if (recaptchaRef.current)
|
|
143
|
-
recaptchaRef.current.reset();
|
|
144
138
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
145
139
|
}
|
|
146
140
|
else if (guestErrors) {
|
|
@@ -159,7 +153,6 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
159
153
|
};
|
|
160
154
|
}, []);
|
|
161
155
|
return {
|
|
162
|
-
recaptchaRef,
|
|
163
156
|
submitRef,
|
|
164
157
|
inputRef,
|
|
165
158
|
fields,
|
|
@@ -1,9 +1,8 @@
|
|
|
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?: boolean | null, callback?: () => void) => {
|
|
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, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
7
6
|
fields: FormFields;
|
|
8
7
|
data: LoginData;
|
|
9
8
|
errors: Record<string, string>;
|
|
@@ -4,10 +4,9 @@ exports.useSignInForm = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
-
const useSignInForm = (email, loading, error, login, includeRecaptcha, callback) => {
|
|
7
|
+
const useSignInForm = (email, loading, error, login, includeRecaptcha, callback, getRecaptchaToken) => {
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
10
|
-
const recaptchaRef = (0, react_1.useRef)(null);
|
|
11
10
|
const [data, setData] = (0, react_1.useState)({ email, password: '' });
|
|
12
11
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
13
12
|
const isSubmitting = (0, react_1.useRef)(false);
|
|
@@ -36,8 +35,6 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
36
35
|
if (loading === 'idle' && isSubmitting.current) {
|
|
37
36
|
isSubmitting.current = false;
|
|
38
37
|
if (error) {
|
|
39
|
-
if (recaptchaRef.current)
|
|
40
|
-
recaptchaRef.current.reset();
|
|
41
38
|
setErrors((0, utils_1.makeFormErrors)(error));
|
|
42
39
|
}
|
|
43
40
|
else if (callback) {
|
|
@@ -49,15 +46,12 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
49
46
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
50
47
|
};
|
|
51
48
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
var _a, _b
|
|
49
|
+
var _a, _b;
|
|
53
50
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
54
51
|
const { password } = data;
|
|
55
52
|
if (includeRecaptcha) {
|
|
56
53
|
try {
|
|
57
|
-
const
|
|
58
|
-
const token = isEnterpriseRecaptcha
|
|
59
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
60
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
54
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
61
55
|
if (!token) {
|
|
62
56
|
isSubmitting.current = false;
|
|
63
57
|
setErrors({
|
|
@@ -80,12 +74,11 @@ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback)
|
|
|
80
74
|
login(data.email || email, password);
|
|
81
75
|
isSubmitting.current = true;
|
|
82
76
|
}
|
|
83
|
-
((
|
|
77
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
84
78
|
});
|
|
85
79
|
return {
|
|
86
80
|
submitRef,
|
|
87
81
|
inputRef,
|
|
88
|
-
recaptchaRef,
|
|
89
82
|
fields,
|
|
90
83
|
data,
|
|
91
84
|
errors,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, includeRecaptcha: boolean | undefined, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean) => {
|
|
3
|
+
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, includeRecaptcha: boolean | undefined, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
5
|
data: CreditCardData | null;
|
|
7
6
|
errors: Record<string, string> | CreditCardErrors;
|
|
8
7
|
submitting: boolean;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { useState, useEffect, useRef } from 'react';
|
|
3
3
|
import { makeFormErrors, validateCreditCard } from '../';
|
|
4
|
-
export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, includeRecaptcha, revenue_center_id, kountSessionId, requireCardholderName = false) => {
|
|
4
|
+
export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, includeRecaptcha, revenue_center_id, kountSessionId, requireCardholderName = false, getRecaptchaToken) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
|
-
const recaptchaRef = useRef(null);
|
|
7
6
|
const [submitting, setSubmitting] = useState(false);
|
|
8
7
|
const [errors, setErrors] = useState({});
|
|
9
8
|
useEffect(() => {
|
|
@@ -11,13 +10,11 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
|
|
|
11
10
|
setSubmitting(false);
|
|
12
11
|
if (error) {
|
|
13
12
|
setErrors(makeFormErrors(error));
|
|
14
|
-
if (recaptchaRef.current)
|
|
15
|
-
recaptchaRef.current.reset();
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
15
|
}, [loading, error]);
|
|
19
16
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
var _a, _b
|
|
17
|
+
var _a, _b;
|
|
21
18
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
22
19
|
setErrors({});
|
|
23
20
|
if (!data || !cardType)
|
|
@@ -33,10 +30,7 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
|
|
|
33
30
|
cardRc.kount_device_session_id = kountSessionId;
|
|
34
31
|
if (includeRecaptcha) {
|
|
35
32
|
try {
|
|
36
|
-
const
|
|
37
|
-
const token = isEnterpriseRecaptcha
|
|
38
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
39
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
33
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
40
34
|
if (!token) {
|
|
41
35
|
setSubmitting(false);
|
|
42
36
|
setErrors({
|
|
@@ -60,11 +54,10 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
|
|
|
60
54
|
addCard(cardRc, callback);
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
|
-
((
|
|
57
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
64
58
|
});
|
|
65
59
|
return {
|
|
66
60
|
submitRef,
|
|
67
|
-
recaptchaRef,
|
|
68
61
|
data,
|
|
69
62
|
errors,
|
|
70
63
|
submitting,
|
|
@@ -3,10 +3,9 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, Donat
|
|
|
3
3
|
export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
10
9
|
amount: string | null;
|
|
11
10
|
handleAmount: (value: string) => void;
|
|
12
11
|
email: string | null;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { useMemo, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { makeFormErrors, makeNumeric, validateCreditCard } from '../utils';
|
|
4
|
-
export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, includeRecaptcha, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
|
|
4
|
+
export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, includeRecaptcha, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false, getRecaptchaToken) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
|
-
const recaptchaRef = useRef(null);
|
|
8
7
|
const [amount, setAmount] = useState('');
|
|
9
8
|
const [email, setEmail] = useState('');
|
|
10
9
|
const [isNewCard, setIsNewCard] = useState(true);
|
|
@@ -26,8 +25,6 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
26
25
|
setSubmitting(false);
|
|
27
26
|
setAlert({ type: 'close' });
|
|
28
27
|
if (error) {
|
|
29
|
-
if (recaptchaRef.current)
|
|
30
|
-
recaptchaRef.current.reset();
|
|
31
28
|
setErrors(makeFormErrors(error));
|
|
32
29
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
33
30
|
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
@@ -66,7 +63,6 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
66
63
|
setCreditCard({ customer_card_id: customerCardId });
|
|
67
64
|
};
|
|
68
65
|
const purchaseWithCaptcha = (credit_card) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
-
var _a, _b, _c;
|
|
70
66
|
const alert = {
|
|
71
67
|
type: 'working',
|
|
72
68
|
args: { text: 'Submitting your contribution...' }
|
|
@@ -81,10 +77,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
81
77
|
formData.kount_device_session_id = kountSessionId;
|
|
82
78
|
if (includeRecaptcha) {
|
|
83
79
|
try {
|
|
84
|
-
const
|
|
85
|
-
const token = isEnterpriseRecaptcha
|
|
86
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
87
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
80
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
88
81
|
if (!token) {
|
|
89
82
|
setSubmitting(false);
|
|
90
83
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
@@ -151,7 +144,6 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
151
144
|
return {
|
|
152
145
|
inputRef,
|
|
153
146
|
submitRef,
|
|
154
|
-
recaptchaRef,
|
|
155
147
|
amount,
|
|
156
148
|
handleAmount,
|
|
157
149
|
email,
|
|
@@ -3,10 +3,9 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftC
|
|
|
3
3
|
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
10
9
|
creditCardOptions: {
|
|
11
10
|
name: string;
|
|
12
11
|
value: unknown;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { useMemo, useRef, useState, useEffect } from 'react';
|
|
3
3
|
import { makeFormErrors, validateCreditCard } from '../utils';
|
|
4
|
-
export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, includeRecaptcha, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
|
|
4
|
+
export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, includeRecaptcha, cardData, cardType, url, kountSessionId, requireCardholderName = false, getRecaptchaToken) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
|
-
const recaptchaRef = useRef(null);
|
|
8
7
|
const [name, setName] = useState(null);
|
|
9
8
|
const [email, setEmail] = useState(null);
|
|
10
9
|
const [cards, setCards] = useState([initState]);
|
|
@@ -23,8 +22,6 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
23
22
|
setSubmitting(false);
|
|
24
23
|
setAlert({ type: 'close' });
|
|
25
24
|
if (error) {
|
|
26
|
-
if (recaptchaRef.current)
|
|
27
|
-
recaptchaRef.current.reset();
|
|
28
25
|
setErrors(makeFormErrors(error));
|
|
29
26
|
}
|
|
30
27
|
}
|
|
@@ -87,7 +84,6 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
87
84
|
setCreditCard({ customer_card_id: customerCardId });
|
|
88
85
|
};
|
|
89
86
|
const purchaseWithCaptcha = (credit_card) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
-
var _a, _b, _c;
|
|
91
87
|
const alert = {
|
|
92
88
|
type: 'working',
|
|
93
89
|
args: { text: 'Submitting your purchase...' }
|
|
@@ -102,10 +98,7 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
102
98
|
formData.kount_device_session_id = kountSessionId;
|
|
103
99
|
if (includeRecaptcha) {
|
|
104
100
|
try {
|
|
105
|
-
const
|
|
106
|
-
const token = isEnterpriseRecaptcha
|
|
107
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
108
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
101
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
109
102
|
if (!token) {
|
|
110
103
|
setSubmitting(false);
|
|
111
104
|
setErrors({
|
|
@@ -168,7 +161,6 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
168
161
|
return {
|
|
169
162
|
inputRef,
|
|
170
163
|
submitRef,
|
|
171
|
-
recaptchaRef,
|
|
172
164
|
creditCardOptions,
|
|
173
165
|
handleName,
|
|
174
166
|
handleEmail,
|
|
@@ -1,9 +1,8 @@
|
|
|
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, requiredEmail?: string) => {
|
|
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, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
7
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
8
7
|
data: LoginData;
|
|
9
8
|
errors: Record<string, string>;
|
|
@@ -1,10 +1,9 @@
|
|
|
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, requiredEmail) => {
|
|
4
|
+
export const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true, requiredEmail, getRecaptchaToken) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
|
-
const recaptchaRef = useRef(null);
|
|
8
7
|
const [data, setData] = useState({
|
|
9
8
|
email: requiredEmail || '',
|
|
10
9
|
password: ''
|
|
@@ -36,8 +35,6 @@ export const useLoginForm = (loading, error, login, includeRecaptcha, callback,
|
|
|
36
35
|
if (loading === 'idle' && submitting) {
|
|
37
36
|
setSubmitting(false);
|
|
38
37
|
if (error) {
|
|
39
|
-
if (recaptchaRef.current)
|
|
40
|
-
recaptchaRef.current.reset();
|
|
41
38
|
setErrors(makeFormErrors(error));
|
|
42
39
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
43
40
|
}
|
|
@@ -50,15 +47,12 @@ export const useLoginForm = (loading, error, login, includeRecaptcha, callback,
|
|
|
50
47
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
51
48
|
};
|
|
52
49
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
var _a, _b
|
|
50
|
+
var _a, _b;
|
|
54
51
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
55
52
|
const { email, password } = data;
|
|
56
53
|
if (includeRecaptcha) {
|
|
57
54
|
try {
|
|
58
|
-
const
|
|
59
|
-
const token = isEnterpriseRecaptcha
|
|
60
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
61
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
55
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
62
56
|
if (!token) {
|
|
63
57
|
setSubmitting(false);
|
|
64
58
|
setErrors({
|
|
@@ -83,12 +77,11 @@ export const useLoginForm = (loading, error, login, includeRecaptcha, callback,
|
|
|
83
77
|
login(email, password);
|
|
84
78
|
setSubmitting(true);
|
|
85
79
|
}
|
|
86
|
-
((
|
|
80
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
87
81
|
});
|
|
88
82
|
return {
|
|
89
83
|
submitRef,
|
|
90
84
|
inputRef,
|
|
91
|
-
recaptchaRef,
|
|
92
85
|
fields,
|
|
93
86
|
data,
|
|
94
87
|
errors,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CustomerSignIn, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, includeRecaptcha: boolean | undefined, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
|
|
3
|
+
export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, includeRecaptcha: boolean | undefined, submit: (data: CustomerSignIn) => void, callback?: () => void, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
7
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
8
7
|
data: {
|
|
9
8
|
identifier: string;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { useState, useEffect, useRef } from 'react';
|
|
3
3
|
import { makeFormErrors, makePhone } from '../utils';
|
|
4
|
-
export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submit, callback) => {
|
|
4
|
+
export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submit, callback, getRecaptchaToken) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
|
-
const recaptchaRef = useRef(null);
|
|
8
7
|
const [data, setData] = useState({
|
|
9
8
|
identifier: '',
|
|
10
9
|
one_time_passcode: ''
|
|
@@ -32,8 +31,6 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha
|
|
|
32
31
|
if (loading === 'idle' && submitting) {
|
|
33
32
|
setSubmitting(false);
|
|
34
33
|
if (error) {
|
|
35
|
-
if (recaptchaRef.current)
|
|
36
|
-
recaptchaRef.current.reset();
|
|
37
34
|
const errs = makeFormErrors(error);
|
|
38
35
|
if (errs.form.includes('not found')) {
|
|
39
36
|
errs.form =
|
|
@@ -63,7 +60,7 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha
|
|
|
63
60
|
}
|
|
64
61
|
};
|
|
65
62
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
var _a, _b
|
|
63
|
+
var _a, _b;
|
|
67
64
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
68
65
|
const { identifier, one_time_passcode } = data;
|
|
69
66
|
const values = /[a-zA-Z]/g.test(identifier)
|
|
@@ -71,10 +68,7 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha
|
|
|
71
68
|
: { phone: identifier };
|
|
72
69
|
if (includeRecaptcha) {
|
|
73
70
|
try {
|
|
74
|
-
const
|
|
75
|
-
const token = isEnterpriseRecaptcha
|
|
76
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
77
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
71
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
78
72
|
if (!token) {
|
|
79
73
|
setSubmitting(false);
|
|
80
74
|
setErrors({
|
|
@@ -99,12 +93,11 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha
|
|
|
99
93
|
otpSent ? submit({ one_time_passcode }) : submit(values);
|
|
100
94
|
setSubmitting(true);
|
|
101
95
|
}
|
|
102
|
-
((
|
|
96
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
103
97
|
});
|
|
104
98
|
return {
|
|
105
99
|
submitRef,
|
|
106
100
|
inputRef,
|
|
107
|
-
recaptchaRef,
|
|
108
101
|
fields,
|
|
109
102
|
data,
|
|
110
103
|
errors,
|
|
@@ -6,8 +6,7 @@ export interface NotificationCheckbox {
|
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const notificationChannelFields: NotificationCheckbox[];
|
|
9
|
-
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean) => {
|
|
10
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
9
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
11
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
12
11
|
data: CustomerCreate;
|
|
13
12
|
comms: NotificationChannel[];
|
|
@@ -24,8 +24,7 @@ export const notificationChannelFields = [
|
|
|
24
24
|
type: 'checkbox'
|
|
25
25
|
}
|
|
26
26
|
];
|
|
27
|
-
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha) => {
|
|
28
|
-
const recaptchaRef = useRef(null);
|
|
27
|
+
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken) => {
|
|
29
28
|
const submitRef = useRef(null);
|
|
30
29
|
const [data, setData] = useState(initState);
|
|
31
30
|
const [comms, setComms] = useState([]);
|
|
@@ -101,8 +100,6 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
101
100
|
errs.birth_date =
|
|
102
101
|
'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
|
|
103
102
|
}
|
|
104
|
-
if (recaptchaRef.current)
|
|
105
|
-
recaptchaRef.current.reset();
|
|
106
103
|
setErrors(errs);
|
|
107
104
|
}
|
|
108
105
|
}
|
|
@@ -121,7 +118,7 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
121
118
|
setComms(updated);
|
|
122
119
|
};
|
|
123
120
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
var _a, _b
|
|
121
|
+
var _a, _b;
|
|
125
122
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
126
123
|
setErrors({});
|
|
127
124
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
@@ -130,10 +127,7 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
130
127
|
}
|
|
131
128
|
if (includeRecaptcha) {
|
|
132
129
|
try {
|
|
133
|
-
const
|
|
134
|
-
const token = isEnterpriseRecaptcha
|
|
135
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
136
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
130
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
137
131
|
if (!token) {
|
|
138
132
|
setErrors({
|
|
139
133
|
form: 'Please complete the recaptcha before submitting'
|
|
@@ -154,10 +148,9 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
154
148
|
setSubmitting(true);
|
|
155
149
|
signUp(values, callback);
|
|
156
150
|
}
|
|
157
|
-
((
|
|
151
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
158
152
|
});
|
|
159
153
|
return {
|
|
160
|
-
recaptchaRef,
|
|
161
154
|
submitRef,
|
|
162
155
|
data,
|
|
163
156
|
comms,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean) => {
|
|
4
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
3
|
+
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
5
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
6
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
7
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -9,8 +9,7 @@ const initialData = {
|
|
|
9
9
|
email: '',
|
|
10
10
|
password: ''
|
|
11
11
|
};
|
|
12
|
-
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha) => {
|
|
13
|
-
const recaptchaRef = useRef(null);
|
|
12
|
+
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken) => {
|
|
14
13
|
const submitRef = useRef(null);
|
|
15
14
|
const inputRef = useRef(null);
|
|
16
15
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -77,7 +76,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
77
76
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
78
77
|
};
|
|
79
78
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
var _a, _b
|
|
79
|
+
var _a, _b;
|
|
81
80
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
82
81
|
if (!disabled) {
|
|
83
82
|
setErrors({});
|
|
@@ -87,10 +86,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
87
86
|
}
|
|
88
87
|
if (includeRecaptcha) {
|
|
89
88
|
try {
|
|
90
|
-
const
|
|
91
|
-
const token = isEnterpriseRecaptcha
|
|
92
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
93
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
89
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
94
90
|
if (!token) {
|
|
95
91
|
setErrors({
|
|
96
92
|
form: 'Please complete the recaptcha before submitting'
|
|
@@ -111,7 +107,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
111
107
|
setSubmitting(true);
|
|
112
108
|
signUp(values);
|
|
113
109
|
}
|
|
114
|
-
((
|
|
110
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
115
111
|
}
|
|
116
112
|
});
|
|
117
113
|
const handleGuest = () => {
|
|
@@ -136,8 +132,6 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
136
132
|
errs.form = 'There are one or more errors below';
|
|
137
133
|
}
|
|
138
134
|
setErrors(errs);
|
|
139
|
-
if (recaptchaRef.current)
|
|
140
|
-
recaptchaRef.current.reset();
|
|
141
135
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
142
136
|
}
|
|
143
137
|
else if (guestErrors) {
|
|
@@ -156,7 +150,6 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
156
150
|
};
|
|
157
151
|
}, []);
|
|
158
152
|
return {
|
|
159
|
-
recaptchaRef,
|
|
160
153
|
submitRef,
|
|
161
154
|
inputRef,
|
|
162
155
|
fields,
|
|
@@ -1,9 +1,8 @@
|
|
|
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?: boolean | null, callback?: () => void) => {
|
|
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, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
recaptchaRef: import("react").MutableRefObject<any>;
|
|
7
6
|
fields: FormFields;
|
|
8
7
|
data: LoginData;
|
|
9
8
|
errors: Record<string, string>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { makeFormErrors } from '../utils';
|
|
3
3
|
import { useState, useEffect, useRef } from 'react';
|
|
4
|
-
export const useSignInForm = (email, loading, error, login, includeRecaptcha, callback) => {
|
|
4
|
+
export const useSignInForm = (email, loading, error, login, includeRecaptcha, callback, getRecaptchaToken) => {
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
|
-
const recaptchaRef = useRef(null);
|
|
8
7
|
const [data, setData] = useState({ email, password: '' });
|
|
9
8
|
const [errors, setErrors] = useState({});
|
|
10
9
|
const isSubmitting = useRef(false);
|
|
@@ -33,8 +32,6 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
33
32
|
if (loading === 'idle' && isSubmitting.current) {
|
|
34
33
|
isSubmitting.current = false;
|
|
35
34
|
if (error) {
|
|
36
|
-
if (recaptchaRef.current)
|
|
37
|
-
recaptchaRef.current.reset();
|
|
38
35
|
setErrors(makeFormErrors(error));
|
|
39
36
|
}
|
|
40
37
|
else if (callback) {
|
|
@@ -46,15 +43,12 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
46
43
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
47
44
|
};
|
|
48
45
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
var _a, _b
|
|
46
|
+
var _a, _b;
|
|
50
47
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
51
48
|
const { password } = data;
|
|
52
49
|
if (includeRecaptcha) {
|
|
53
50
|
try {
|
|
54
|
-
const
|
|
55
|
-
const token = isEnterpriseRecaptcha
|
|
56
|
-
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
57
|
-
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
51
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
58
52
|
if (!token) {
|
|
59
53
|
isSubmitting.current = false;
|
|
60
54
|
setErrors({
|
|
@@ -77,12 +71,11 @@ export const useSignInForm = (email, loading, error, login, includeRecaptcha, ca
|
|
|
77
71
|
login(data.email || email, password);
|
|
78
72
|
isSubmitting.current = true;
|
|
79
73
|
}
|
|
80
|
-
((
|
|
74
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
81
75
|
});
|
|
82
76
|
return {
|
|
83
77
|
submitRef,
|
|
84
78
|
inputRef,
|
|
85
|
-
recaptchaRef,
|
|
86
79
|
fields,
|
|
87
80
|
data,
|
|
88
81
|
errors,
|
package/package.json
CHANGED