@open-tender/utils 0.5.38 → 0.5.39
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/useSignUpForm.d.ts +3 -2
- package/dist/cjs/hooks/useSignUpForm.js +36 -7
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +3 -2
- package/dist/cjs/hooks/useSignUpGuestForm.js +36 -7
- package/dist/esm/hooks/useSignUpForm.d.ts +3 -2
- package/dist/esm/hooks/useSignUpForm.js +36 -7
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +3 -2
- package/dist/esm/hooks/useSignUpGuestForm.js +36 -7
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ 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) => {
|
|
10
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
10
11
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
12
|
data: CustomerCreate;
|
|
12
13
|
comms: NotificationChannel[];
|
|
@@ -16,5 +17,5 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
|
|
|
16
17
|
notificationFields: NotificationCheckbox[];
|
|
17
18
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
18
19
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
19
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
20
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
20
21
|
};
|
|
@@ -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,8 @@ 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) => {
|
|
31
|
+
const recaptchaRef = (0, react_1.useRef)(null);
|
|
30
32
|
const submitRef = (0, react_1.useRef)(null);
|
|
31
33
|
const [data, setData] = (0, react_1.useState)(initState);
|
|
32
34
|
const [comms, setComms] = (0, react_1.useState)([]);
|
|
@@ -102,6 +104,8 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
102
104
|
errs.birth_date =
|
|
103
105
|
'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
|
|
104
106
|
}
|
|
107
|
+
if (recaptchaRef.current)
|
|
108
|
+
recaptchaRef.current.reset();
|
|
105
109
|
setErrors(errs);
|
|
106
110
|
}
|
|
107
111
|
}
|
|
@@ -119,19 +123,44 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
119
123
|
const updated = value ? [...other, name] : other;
|
|
120
124
|
setComms(updated);
|
|
121
125
|
};
|
|
122
|
-
const handleSubmit = (evt) => {
|
|
123
|
-
var _a, _b;
|
|
126
|
+
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
var _a, _b, _c, _d, _e;
|
|
124
128
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
125
129
|
setErrors({});
|
|
126
|
-
setSubmitting(true);
|
|
127
130
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
128
131
|
if (values.birth_date) {
|
|
129
132
|
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
if (includeRecaptcha) {
|
|
135
|
+
try {
|
|
136
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
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();
|
|
140
|
+
if (!token) {
|
|
141
|
+
setErrors({
|
|
142
|
+
form: 'Please complete the recaptcha before submitting'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
setSubmitting(true);
|
|
147
|
+
signUp(values, callback, token);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
setErrors({
|
|
152
|
+
form: 'Please complete the recaptcha before submitting'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
setSubmitting(true);
|
|
158
|
+
signUp(values, callback);
|
|
159
|
+
}
|
|
160
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
161
|
+
});
|
|
134
162
|
return {
|
|
163
|
+
recaptchaRef,
|
|
135
164
|
submitRef,
|
|
136
165
|
data,
|
|
137
166
|
comms,
|
|
@@ -1,6 +1,7 @@
|
|
|
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) => {
|
|
4
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
4
5
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
6
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
7
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -12,7 +13,7 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
12
13
|
guestDisabled: boolean;
|
|
13
14
|
submitting: boolean;
|
|
14
15
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
15
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
16
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
16
17
|
handleGuest: () => void;
|
|
17
18
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
19
|
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,8 @@ 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) => {
|
|
16
|
+
const recaptchaRef = (0, react_1.useRef)(null);
|
|
15
17
|
const submitRef = (0, react_1.useRef)(null);
|
|
16
18
|
const inputRef = (0, react_1.useRef)(null);
|
|
17
19
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -77,20 +79,44 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
77
79
|
: value;
|
|
78
80
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
79
81
|
};
|
|
80
|
-
const handleSubmit = (evt) => {
|
|
81
|
-
var _a, _b;
|
|
82
|
+
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
var _a, _b, _c, _d, _e;
|
|
82
84
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
83
85
|
if (!disabled) {
|
|
84
86
|
setErrors({});
|
|
85
|
-
setSubmitting(true);
|
|
86
87
|
const values = Object.assign(Object.assign({}, data), { email, communications: comms });
|
|
87
88
|
if (values.birth_date) {
|
|
88
89
|
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
if (includeRecaptcha) {
|
|
92
|
+
try {
|
|
93
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
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();
|
|
97
|
+
if (!token) {
|
|
98
|
+
setErrors({
|
|
99
|
+
form: 'Please complete the recaptcha before submitting'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
setSubmitting(true);
|
|
104
|
+
signUp(values, token);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
setErrors({
|
|
109
|
+
form: 'Please complete the recaptcha before submitting'
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
setSubmitting(true);
|
|
115
|
+
signUp(values);
|
|
116
|
+
}
|
|
117
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
92
118
|
}
|
|
93
|
-
};
|
|
119
|
+
});
|
|
94
120
|
const handleGuest = () => {
|
|
95
121
|
if (!guestDisabled) {
|
|
96
122
|
setErrors({});
|
|
@@ -113,6 +139,8 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
113
139
|
errs.form = 'There are one or more errors below';
|
|
114
140
|
}
|
|
115
141
|
setErrors(errs);
|
|
142
|
+
if (recaptchaRef.current)
|
|
143
|
+
recaptchaRef.current.reset();
|
|
116
144
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
117
145
|
}
|
|
118
146
|
else if (guestErrors) {
|
|
@@ -131,6 +159,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
131
159
|
};
|
|
132
160
|
}, []);
|
|
133
161
|
return {
|
|
162
|
+
recaptchaRef,
|
|
134
163
|
submitRef,
|
|
135
164
|
inputRef,
|
|
136
165
|
fields,
|
|
@@ -6,7 +6,8 @@ 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) => {
|
|
10
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
10
11
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
12
|
data: CustomerCreate;
|
|
12
13
|
comms: NotificationChannel[];
|
|
@@ -16,5 +17,5 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
|
|
|
16
17
|
notificationFields: NotificationCheckbox[];
|
|
17
18
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
18
19
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
19
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
20
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
20
21
|
};
|
|
@@ -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,8 @@ 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) => {
|
|
28
|
+
const recaptchaRef = useRef(null);
|
|
27
29
|
const submitRef = useRef(null);
|
|
28
30
|
const [data, setData] = useState(initState);
|
|
29
31
|
const [comms, setComms] = useState([]);
|
|
@@ -99,6 +101,8 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
99
101
|
errs.birth_date =
|
|
100
102
|
'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
|
|
101
103
|
}
|
|
104
|
+
if (recaptchaRef.current)
|
|
105
|
+
recaptchaRef.current.reset();
|
|
102
106
|
setErrors(errs);
|
|
103
107
|
}
|
|
104
108
|
}
|
|
@@ -116,19 +120,44 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
116
120
|
const updated = value ? [...other, name] : other;
|
|
117
121
|
setComms(updated);
|
|
118
122
|
};
|
|
119
|
-
const handleSubmit = (evt) => {
|
|
120
|
-
var _a, _b;
|
|
123
|
+
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
var _a, _b, _c, _d, _e;
|
|
121
125
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
122
126
|
setErrors({});
|
|
123
|
-
setSubmitting(true);
|
|
124
127
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
125
128
|
if (values.birth_date) {
|
|
126
129
|
values.birth_date = slashesToDashes(values.birth_date);
|
|
127
130
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
if (includeRecaptcha) {
|
|
132
|
+
try {
|
|
133
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
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();
|
|
137
|
+
if (!token) {
|
|
138
|
+
setErrors({
|
|
139
|
+
form: 'Please complete the recaptcha before submitting'
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
setSubmitting(true);
|
|
144
|
+
signUp(values, callback, token);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
setErrors({
|
|
149
|
+
form: 'Please complete the recaptcha before submitting'
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
setSubmitting(true);
|
|
155
|
+
signUp(values, callback);
|
|
156
|
+
}
|
|
157
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
158
|
+
});
|
|
131
159
|
return {
|
|
160
|
+
recaptchaRef,
|
|
132
161
|
submitRef,
|
|
133
162
|
data,
|
|
134
163
|
comms,
|
|
@@ -1,6 +1,7 @@
|
|
|
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) => {
|
|
4
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
4
5
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
6
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
7
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -12,7 +13,7 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
12
13
|
guestDisabled: boolean;
|
|
13
14
|
submitting: boolean;
|
|
14
15
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
15
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
16
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
16
17
|
handleGuest: () => void;
|
|
17
18
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
19
|
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,8 @@ 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) => {
|
|
13
|
+
const recaptchaRef = useRef(null);
|
|
12
14
|
const submitRef = useRef(null);
|
|
13
15
|
const inputRef = useRef(null);
|
|
14
16
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -74,20 +76,44 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
74
76
|
: value;
|
|
75
77
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
76
78
|
};
|
|
77
|
-
const handleSubmit = (evt) => {
|
|
78
|
-
var _a, _b;
|
|
79
|
+
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
var _a, _b, _c, _d, _e;
|
|
79
81
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
80
82
|
if (!disabled) {
|
|
81
83
|
setErrors({});
|
|
82
|
-
setSubmitting(true);
|
|
83
84
|
const values = Object.assign(Object.assign({}, data), { email, communications: comms });
|
|
84
85
|
if (values.birth_date) {
|
|
85
86
|
values.birth_date = slashesToDashes(values.birth_date);
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
if (includeRecaptcha) {
|
|
89
|
+
try {
|
|
90
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
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();
|
|
94
|
+
if (!token) {
|
|
95
|
+
setErrors({
|
|
96
|
+
form: 'Please complete the recaptcha before submitting'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
setSubmitting(true);
|
|
101
|
+
signUp(values, token);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
setErrors({
|
|
106
|
+
form: 'Please complete the recaptcha before submitting'
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
setSubmitting(true);
|
|
112
|
+
signUp(values);
|
|
113
|
+
}
|
|
114
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
89
115
|
}
|
|
90
|
-
};
|
|
116
|
+
});
|
|
91
117
|
const handleGuest = () => {
|
|
92
118
|
if (!guestDisabled) {
|
|
93
119
|
setErrors({});
|
|
@@ -110,6 +136,8 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
110
136
|
errs.form = 'There are one or more errors below';
|
|
111
137
|
}
|
|
112
138
|
setErrors(errs);
|
|
139
|
+
if (recaptchaRef.current)
|
|
140
|
+
recaptchaRef.current.reset();
|
|
113
141
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
114
142
|
}
|
|
115
143
|
else if (guestErrors) {
|
|
@@ -128,6 +156,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
128
156
|
};
|
|
129
157
|
}, []);
|
|
130
158
|
return {
|
|
159
|
+
recaptchaRef,
|
|
131
160
|
submitRef,
|
|
132
161
|
inputRef,
|
|
133
162
|
fields,
|
package/package.json
CHANGED