@open-tender/utils 0.5.38 → 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 +2 -2
- package/dist/cjs/hooks/useSignUpForm.js +27 -5
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +2 -2
- package/dist/cjs/hooks/useSignUpGuestForm.js +27 -5
- 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 +2 -2
- package/dist/esm/hooks/useSignUpForm.js +27 -5
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +2 -2
- package/dist/esm/hooks/useSignUpGuestForm.js +27 -5
- 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,7 +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) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls']) => {
|
|
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>) => {
|
|
10
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
11
|
data: CustomerCreate;
|
|
12
12
|
comms: NotificationChannel[];
|
|
@@ -16,5 +16,5 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
|
|
|
16
16
|
notificationFields: NotificationCheckbox[];
|
|
17
17
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
18
18
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
19
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
19
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
20
20
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSignUpForm = exports.notificationChannelFields = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const initState = {
|
|
@@ -26,7 +27,7 @@ exports.notificationChannelFields = [
|
|
|
26
27
|
type: 'checkbox'
|
|
27
28
|
}
|
|
28
29
|
];
|
|
29
|
-
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls) => {
|
|
30
|
+
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken) => {
|
|
30
31
|
const submitRef = (0, react_1.useRef)(null);
|
|
31
32
|
const [data, setData] = (0, react_1.useState)(initState);
|
|
32
33
|
const [comms, setComms] = (0, react_1.useState)([]);
|
|
@@ -119,18 +120,39 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
119
120
|
const updated = value ? [...other, name] : other;
|
|
120
121
|
setComms(updated);
|
|
121
122
|
};
|
|
122
|
-
const handleSubmit = (evt) => {
|
|
123
|
+
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
123
124
|
var _a, _b;
|
|
124
125
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
125
126
|
setErrors({});
|
|
126
|
-
setSubmitting(true);
|
|
127
127
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
128
128
|
if (values.birth_date) {
|
|
129
129
|
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
if (includeRecaptcha) {
|
|
132
|
+
try {
|
|
133
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
134
|
+
if (!token) {
|
|
135
|
+
setErrors({
|
|
136
|
+
form: 'Please complete the recaptcha before submitting'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
setSubmitting(true);
|
|
141
|
+
signUp(values, callback, token);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
setErrors({
|
|
146
|
+
form: 'Please complete the recaptcha before submitting'
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
setSubmitting(true);
|
|
152
|
+
signUp(values, callback);
|
|
153
|
+
}
|
|
132
154
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
133
|
-
};
|
|
155
|
+
});
|
|
134
156
|
return {
|
|
135
157
|
submitRef,
|
|
136
158
|
data,
|
|
@@ -1,6 +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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[]) => {
|
|
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>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -12,7 +12,7 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
12
12
|
guestDisabled: boolean;
|
|
13
13
|
submitting: boolean;
|
|
14
14
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
15
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
15
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
16
16
|
handleGuest: () => void;
|
|
17
17
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
18
|
resetState: () => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSignUpGuestForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const useSignUpForm_1 = require("./useSignUpForm");
|
|
@@ -11,7 +12,7 @@ const initialData = {
|
|
|
11
12
|
email: '',
|
|
12
13
|
password: ''
|
|
13
14
|
};
|
|
14
|
-
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = []) => {
|
|
15
|
+
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken) => {
|
|
15
16
|
const submitRef = (0, react_1.useRef)(null);
|
|
16
17
|
const inputRef = (0, react_1.useRef)(null);
|
|
17
18
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -77,20 +78,41 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
77
78
|
: value;
|
|
78
79
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
79
80
|
};
|
|
80
|
-
const handleSubmit = (evt) => {
|
|
81
|
+
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
81
82
|
var _a, _b;
|
|
82
83
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
83
84
|
if (!disabled) {
|
|
84
85
|
setErrors({});
|
|
85
|
-
setSubmitting(true);
|
|
86
86
|
const values = Object.assign(Object.assign({}, data), { email, communications: comms });
|
|
87
87
|
if (values.birth_date) {
|
|
88
88
|
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
if (includeRecaptcha) {
|
|
91
|
+
try {
|
|
92
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
93
|
+
if (!token) {
|
|
94
|
+
setErrors({
|
|
95
|
+
form: 'Please complete the recaptcha before submitting'
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
setSubmitting(true);
|
|
100
|
+
signUp(values, token);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
setErrors({
|
|
105
|
+
form: 'Please complete the recaptcha before submitting'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
setSubmitting(true);
|
|
111
|
+
signUp(values);
|
|
112
|
+
}
|
|
91
113
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
92
114
|
}
|
|
93
|
-
};
|
|
115
|
+
});
|
|
94
116
|
const handleGuest = () => {
|
|
95
117
|
if (!guestDisabled) {
|
|
96
118
|
setErrors({});
|
|
@@ -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,7 +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) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls']) => {
|
|
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>) => {
|
|
10
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
11
|
data: CustomerCreate;
|
|
12
12
|
comms: NotificationChannel[];
|
|
@@ -16,5 +16,5 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
|
|
|
16
16
|
notificationFields: NotificationCheckbox[];
|
|
17
17
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
18
18
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
19
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
19
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
20
20
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { useRef, useState, useEffect } from 'react';
|
|
2
3
|
import { makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
4
|
const initState = {
|
|
@@ -23,7 +24,7 @@ export const notificationChannelFields = [
|
|
|
23
24
|
type: 'checkbox'
|
|
24
25
|
}
|
|
25
26
|
];
|
|
26
|
-
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls) => {
|
|
27
|
+
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken) => {
|
|
27
28
|
const submitRef = useRef(null);
|
|
28
29
|
const [data, setData] = useState(initState);
|
|
29
30
|
const [comms, setComms] = useState([]);
|
|
@@ -116,18 +117,39 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
116
117
|
const updated = value ? [...other, name] : other;
|
|
117
118
|
setComms(updated);
|
|
118
119
|
};
|
|
119
|
-
const handleSubmit = (evt) => {
|
|
120
|
+
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
121
|
var _a, _b;
|
|
121
122
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
122
123
|
setErrors({});
|
|
123
|
-
setSubmitting(true);
|
|
124
124
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
125
125
|
if (values.birth_date) {
|
|
126
126
|
values.birth_date = slashesToDashes(values.birth_date);
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
if (includeRecaptcha) {
|
|
129
|
+
try {
|
|
130
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
131
|
+
if (!token) {
|
|
132
|
+
setErrors({
|
|
133
|
+
form: 'Please complete the recaptcha before submitting'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
setSubmitting(true);
|
|
138
|
+
signUp(values, callback, token);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
setErrors({
|
|
143
|
+
form: 'Please complete the recaptcha before submitting'
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
setSubmitting(true);
|
|
149
|
+
signUp(values, callback);
|
|
150
|
+
}
|
|
129
151
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
130
|
-
};
|
|
152
|
+
});
|
|
131
153
|
return {
|
|
132
154
|
submitRef,
|
|
133
155
|
data,
|
|
@@ -1,6 +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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[]) => {
|
|
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>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -12,7 +12,7 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
12
12
|
guestDisabled: boolean;
|
|
13
13
|
submitting: boolean;
|
|
14
14
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
15
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
15
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
16
16
|
handleGuest: () => void;
|
|
17
17
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
18
|
resetState: () => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
3
|
import { checkGuestData, makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
4
|
import { notificationChannelFields } from './useSignUpForm';
|
|
@@ -8,7 +9,7 @@ const initialData = {
|
|
|
8
9
|
email: '',
|
|
9
10
|
password: ''
|
|
10
11
|
};
|
|
11
|
-
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = []) => {
|
|
12
|
+
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken) => {
|
|
12
13
|
const submitRef = useRef(null);
|
|
13
14
|
const inputRef = useRef(null);
|
|
14
15
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -74,20 +75,41 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
74
75
|
: value;
|
|
75
76
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
76
77
|
};
|
|
77
|
-
const handleSubmit = (evt) => {
|
|
78
|
+
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
79
|
var _a, _b;
|
|
79
80
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
80
81
|
if (!disabled) {
|
|
81
82
|
setErrors({});
|
|
82
|
-
setSubmitting(true);
|
|
83
83
|
const values = Object.assign(Object.assign({}, data), { email, communications: comms });
|
|
84
84
|
if (values.birth_date) {
|
|
85
85
|
values.birth_date = slashesToDashes(values.birth_date);
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
if (includeRecaptcha) {
|
|
88
|
+
try {
|
|
89
|
+
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
90
|
+
if (!token) {
|
|
91
|
+
setErrors({
|
|
92
|
+
form: 'Please complete the recaptcha before submitting'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
setSubmitting(true);
|
|
97
|
+
signUp(values, token);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
setErrors({
|
|
102
|
+
form: 'Please complete the recaptcha before submitting'
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
setSubmitting(true);
|
|
108
|
+
signUp(values);
|
|
109
|
+
}
|
|
88
110
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
89
111
|
}
|
|
90
|
-
};
|
|
112
|
+
});
|
|
91
113
|
const handleGuest = () => {
|
|
92
114
|
if (!guestDisabled) {
|
|
93
115
|
setErrors({});
|
|
@@ -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