1+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2+ import { useState } from 'react' ;
13import Image from 'next/image' ;
2- import React from 'react' ;
34import mailIcon from '../../../public/img/mail-icon.svg' ;
45import messageIcon from '../../../public/img/message-icon.svg' ;
56
7+ import { useForm , ValidationError } from '@formspree/react' ;
8+ import ReCAPTCHA from "react-google-recaptcha" ;
9+
10+
11+
612export default function MobileVersion ( ) {
13+
14+ const [ captchaComplete , setCaptchaComplete ] = useState < boolean > ( false ) ;
15+
16+ const [ state , handleSubmit ] = useForm ( process . env . NEXT_PUBLIC_FORMSPREE_ID ! ) ;
17+
18+ const handleRecaptchaResult = ( result : string | null ) => {
19+ if ( result ) {
20+ setCaptchaComplete ( true ) ;
21+ }
22+ }
23+
24+ if ( state . succeeded ) {
25+ return (
26+ < div className = "flex justify-center items-center" >
27+ < p className = 'text-xl font-medium text-green-800' > Thank you for your submission. We will get back to you as soon as possible</ p >
28+ </ div >
29+ )
30+ }
31+
32+
733 return (
834 < >
935 < h1 className = "text-black font-robotoMono text-4xl w-fit mx-auto py-4 font-bold" >
1036 Let's talk React
1137 </ h1 >
12- < form className = "w-4/5 mx-auto md:w-2/3" >
38+ < form className = "w-4/5 mx-auto md:w-2/3" onSubmit = { handleSubmit } >
1339 < label
1440 htmlFor = "name"
1541 className = "border border-black w-full rounded-md p-2 my-2 flex"
1642 >
1743 < input
1844 id = "name"
19- type = { 'text' }
20- placeholder = { 'Name' }
45+ type = 'text'
46+ name = 'name'
47+ placeholder = 'Name'
2148 className = " placeholder-[#7E7979] outline-none flex-grow ml-8 font-robotoMono text-base"
2249 required
2350 />
2451 </ label >
52+ < ValidationError prefix = "Name" field = "name" errors = { state . errors } />
2553 < label
2654 htmlFor = "email"
2755 className = "border border-black w-full rounded-md p-2 my-2 flex"
@@ -36,12 +64,14 @@ export default function MobileVersion() {
3664 />
3765 < input
3866 id = "email"
39- type = { 'email' }
40- placeholder = { 'Email' }
67+ type = 'email'
68+ placeholder = 'Email'
69+ name = 'email'
4170 className = "inline-block ml-2 outline-none flex-grow placeholder-[#7E7979] font-robotoMono text-base"
4271 required
4372 />
4473 </ label >
74+ < ValidationError prefix = "Email" field = "email" errors = { state . errors } />
4575 < label className = "border border-black w-full rounded-md p-2 my-2 flex items-start" >
4676 < Image
4777 src = { messageIcon }
@@ -52,17 +82,35 @@ export default function MobileVersion() {
5282 />
5383 < textarea
5484 placeholder = "Message"
85+ name = 'message'
5586 className = " inline-block ml-2 h-[270px] resize-none outline-none flex-grow placeholder-[#7E7979] font-robotoMono text-base "
5687 required
5788 > </ textarea >
5889 </ label >
90+ < ValidationError prefix = "Message" field = "message" errors = { state . errors } />
5991 { /*//TODO: replace this button with the app button component */ }
92+
93+ < ReCAPTCHA
94+ sitekey = { process . env . NEXT_PUBLIC_RECAPTCHA_SITE_KEY ! }
95+ onChange = { handleRecaptchaResult }
96+ />
97+
98+ { captchaComplete ?
6099 < button
61100 type = "submit"
101+ disabled = { state . submitting }
62102 className = "border-2 border-[#12A04E] w-full rounded-md p-2 my-2 font-montserrat font-bold text-[#12A04E]"
63103 >
64104 Send Message
65- </ button >
105+ </ button > :
106+ < button
107+ type = "submit"
108+ disabled
109+ className = "border-2 border-[#12A04E] w-full rounded-md p-2 my-2 font-montserrat font-bold text-[#12A04E]"
110+ >
111+ Send Message
112+ </ button > }
113+ < ValidationError errors = { state . errors } />
66114 </ form >
67115 </ >
68116 ) ;
0 commit comments