-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContactForm.tsx
More file actions
186 lines (168 loc) · 5.71 KB
/
ContactForm.tsx
File metadata and controls
186 lines (168 loc) · 5.71 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import type { Component } from 'solid-js';
import { createSignal } from 'solid-js';
import toast, { Toaster } from 'solid-toast';
import { useForm } from '../utils/validation.jsx';
import './ContactForm.scss';
export const ContactForm: Component = () => {
const [loading, setLoading] = createSignal(false);
function _successMessage() {
setLoading(false);
toast.success("Thanks for contacting us! We'll be in touch shortly.");
}
function _errorMessage() {
setLoading(false);
toast.error('Something went wrong :(. Please refresh and try again.');
}
const sendContactRequest = async function (form) {
setLoading(true);
const formData = new FormData(form);
return fetch('https://shipshape.io/', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams(formData).toString()
})
.then(_successMessage)
.catch(_errorMessage);
};
const { validate, formSubmit, errors } = useForm({
errorClass: 'error-input'
});
const SubmitButton = () => (
<input
disabled={Object.keys(errors).length}
type="submit"
value="Send Message"
class="btn btn-red cursor-pointer inline-flex justify-center border border-transparent transition-colors font-medium rounded-md disabled:opacity-50 disabled:cursor-not-allowed"
/>
);
const LoadingButton = () => (
<button
type="button"
class="btn btn-red cursor-pointer flex relative justify-center border border-transparent transition-colors font-medium rounded-md disabled:cursor-not-allowed"
disabled
>
<div class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div>Loading...</div>
</button>
);
const ErrorMessage = (props) => (
<span class="error-message">{props.error}</span>
);
return (
<div class="w-full">
<form
class="contact-form grid grid-cols-1 gap-y-6 -mt-6 lg:grid-cols-2 lg:gap-x-6"
data-netlify-recaptcha="true"
name="contact-us"
netlify-honeypot="bot-field"
netlify
use:formSubmit={sendContactRequest}
>
<div class="lg:col-span-2">
<input type="hidden" name="form-name" value="contact-us" />
<fieldset>
<div class="bot-field">
<label>
Don’t fill this out if you're human:
<input name="bot-field" />
</label>
</div>
</fieldset>
</div>
<div>
<label for="name" class="block text-sm font-bold text-navy">
Name
</label>
<div class="mt-1">
<input
class="block w-full shadow-sm sm:text-sm focus:outline-none focus:ring-navy-card-light focus:border-navy-card-light border-grey-light rounded-md"
id="name"
type="text"
name="name"
required
use:validate={[]}
/>
</div>
{errors.name && <ErrorMessage error={errors.name} />}
</div>
<div>
<label for="email" class="block text-sm font-bold text-navy">
Email
</label>
<div class="mt-1">
<input
autocomplete="email"
class="block w-full shadow-sm sm:text-sm focus:outline-none focus:ring-navy-card-light focus:border-navy-card-light border-grey-light rounded-md"
id="email"
type="email"
name="email"
required
use:validate={[]}
/>
</div>
{errors.email && <ErrorMessage error={errors.email} />}
</div>
<div>
<label for="company" class="block text-sm font-bold text-navy">
Company
</label>
<div class="mt-1">
<input
id="company"
type="text"
name="company"
autocomplete="organization"
class="block w-full shadow-sm sm:text-sm focus:outline-none focus:ring-navy-card-light focus:border-navy-card-light border-grey-light rounded-md"
/>
</div>
</div>
<div>
<label for="budget" class="block text-sm font-bold text-navy">
Expected Budget
</label>
<select
id="budget"
name="budget"
class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-grey-light focus:outline-none focus:ring-navy-card-light sm:text-sm rounded-md"
>
<option value="25k-50k">$25,000 – $50,000</option>
<option value="50k-100k">$50,000 – $100,000</option>
<option value="100k-250k">$100,000 – $250,000</option>
<option value="over_250k">$250,000+</option>
</select>
</div>
<div class="lg:col-span-2">
<div class="flex justify-between">
<label class="block text-sm font-bold text-navy" for="description">
How can we help you?
</label>
</div>
<div class="mt-1">
<textarea
class="block w-full shadow-sm sm:text-sm focus:ring-navy-card-light focus:border-navy-card-light border-grey-light rounded-md"
id="description"
name="description"
required
rows={4}
use:validate={[]}
/>
</div>
{errors.description && <ErrorMessage error={errors.description} />}
</div>
{/* {loading() ? <LoadingButton /> : <SubmitButton />} */}
<LoadingButton />
</form>
<Toaster
position="top-center"
toastOptions={{
duration: 5000
}}
/>
</div>
);
};