-
Notifications
You must be signed in to change notification settings - Fork 9
/
FeedbackForm.js
140 lines (134 loc) · 5.44 KB
/
FeedbackForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPaperPlane } from '@fortawesome/free-solid-svg-icons'
import styles from './FeedbackForm.module.css'
export default function FeedbackForm({ feedbackData }) {
const router = useRouter()
const [email, setEmail] = useState('')
const [message, setMessage] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
const [formHidden, setFormHidden] = useState(false)
// Update local state when feedbackData changes
useEffect(() => {
if (feedbackData) {
setEmail(feedbackData.email)
setMessage(feedbackData.message)
}
}, [feedbackData])
const handleSubmit = async (event) => {
event.preventDefault()
setIsSubmitting(true)
const formData = new FormData(event.target)
formData.append('form-name', 'feedback')
fetch('/form.html', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams(formData).toString(),
})
.then((response) => {
if (response.ok) {
setFormHidden(true) // Hide form and show success message on successful submission
console.log('Form successfully submitted')
} else {
console.error('Form submission failed')
}
setIsSubmitting(false)
})
.catch((error) => {
console.error('Form submission error:', error)
setIsSubmitting(false)
})
}
return (
<div
id="waitlist"
className={`${styles.background} px-10`}
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
height: '100vh',
}}
>
{formHidden ? (
<div
className="fade-in"
style={{ opacity: 1, transition: 'opacity 1s ease-in' }}
>
<h2 className="font-extralight text-white text-2xl">
<FontAwesomeIcon icon={faPaperPlane} className="mr-4" />
Get Ready
</h2>
</div>
) : (
<form
id="feedback-form"
className="flex items-center justify-center"
onSubmit={handleSubmit}
data-netlify="true"
data-netlify-honeypot="bot-field"
name="feedback"
>
<div className="grid grid-flow-row auto-rows-max row-auto">
<input
type="hidden"
name="form-name"
value="feedback"
/>
<p className={styles.hidden}>
<label>
Don’t fill this out if you’re human:{' '}
<input name="bot-field" />
</label>
</p>
<h1 className="font-light text-3xl text-white my-0">
Join the Waitlist
</h1>
<h2 className="mt-10 mb-8 font-light text-white flex-auto">
We'll email you when you can access OpenAdapt Alpha.
</h2>
<label
className={styles['email_label']}
htmlFor="email_form"
>
Email Address:
<span className={styles['required']}>*</span>
</label>
<input
id="email_form"
className={styles['form-field']}
type="email"
name="email_form"
required
/>
<label className={styles['input_label']} htmlFor="help">
How can OpenAdapt help you?
</label>
<textarea
id="help"
style={{ minHeight: '100px' }}
className={styles['form-field']}
wrap="soft"
name="help"
value={message} // Use controlled component
onChange={(e) => setMessage(e.target.value)}
></textarea>
<div
className="container mx-auto"
style={{ textAlign: 'center' }}
>
<button
className="btn btn-primary"
disabled={isSubmitting}
>
{isSubmitting ? 'Submitting...' : 'Submit'}
</button>
</div>
</div>
</form>
)}
</div>
)
}