@@ -5,26 +5,34 @@ import Col from "react-bootstrap/Col";
5
5
import Form from "react-bootstrap/Form" ;
6
6
import Container from "react-bootstrap/Container" ;
7
7
import Row from "react-bootstrap/Row" ;
8
+ import ReCAPTCHA from "react-google-recaptcha" ;
9
+ import submitRecaptchaForm from "../../../helpers/submitRecaptchaForm" ;
8
10
import s from "./New.scss" ;
9
11
10
12
interface NewProps {
11
13
email ?: string ;
14
+ recaptchaSiteKey : string ;
12
15
}
13
16
14
17
interface NewState {
15
18
email ?: string ;
16
19
}
17
20
21
+ const action = "/invitation?success=sent" ;
22
+
18
23
class New extends Component < NewProps , NewState > {
19
24
emailField : RefObject < HTMLInputElement > ;
20
25
26
+ recaptchaRef : RefObject < any > ;
27
+
21
28
static defaultProps = {
22
29
email : "" ,
23
30
} ;
24
31
25
32
constructor ( props : NewProps ) {
26
33
super ( props ) ;
27
34
this . emailField = createRef ( ) ;
35
+ this . recaptchaRef = createRef ( ) ;
28
36
29
37
this . state = {
30
38
email : props . email ,
@@ -38,8 +46,24 @@ class New extends Component<NewProps, NewState> {
38
46
handleChange = ( event : ChangeEvent < HTMLInputElement | HTMLTextAreaElement > ) =>
39
47
this . setState ( { email : event . currentTarget . value } ) ;
40
48
49
+ handleSubmit = async ( event : React . TargetedEvent < HTMLFormElement > ) => {
50
+ event . preventDefault ( ) ;
51
+
52
+ const token = await this . recaptchaRef . current . executeAsync ( ) ;
53
+
54
+ const email = this . state . email ;
55
+
56
+ if ( email != null ) {
57
+ submitRecaptchaForm ( action , {
58
+ email,
59
+ "g-recaptcha-response" : token ,
60
+ } ) ;
61
+ }
62
+ } ;
63
+
41
64
render ( ) {
42
65
const { email } = this . state ;
66
+ const { recaptchaSiteKey } = this . props ;
43
67
44
68
return (
45
69
< div className = { s . root } >
@@ -49,7 +73,12 @@ class New extends Component<NewProps, NewState> {
49
73
Enter your email address and we will send you a link to confirm your
50
74
request.
51
75
</ p >
52
- < form action = "/invitation?success=sent" method = "post" >
76
+ < form action = { action } method = "post" onSubmit = { this . handleSubmit } >
77
+ < ReCAPTCHA
78
+ ref = { this . recaptchaRef }
79
+ size = "invisible"
80
+ sitekey = { recaptchaSiteKey }
81
+ />
53
82
< Row >
54
83
< Col sm = { 6 } >
55
84
< Form . Group className = "mb-3" controlId = "invitationNew-email" >
0 commit comments