/
ApplyForm.js
272 lines (249 loc) · 7.92 KB
/
ApplyForm.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import {
Button,
Card,
Heading1,
InlineLink,
Input,
LabelText,
Text,
} from '@algolia/ui-library';
import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';
import React, { useState } from 'react';
function ApplyForm() {
const { withBaseUrl } = useBaseUrlUtils();
const [state, setState] = useState({ status: 'stalled', message: '' });
const [url, setUrl] = useState('');
const [email, setEmail] = useState('');
const [repo, setRepo] = useState('');
const handleSetUrl = (event) => {
setUrl(event.target.value);
};
const handleSetEmail = (event) => {
setEmail(event.target.value);
};
const handleSetRepo = (event) => {
setRepo(event.target.value);
};
const onSubmit = (event) => {
event.preventDefault();
if (state.status === 'loading') {
return;
}
setState({ status: 'loading' });
const applyForm = event.target;
const method = applyForm.getAttribute('method');
const action = applyForm.getAttribute('action');
const formData = new FormData(applyForm);
const data = {};
formData.forEach(function (value, key) {
data[key] = value;
});
const body = JSON.stringify(data);
fetch(action, {
method,
headers: { 'Content-Type': 'application/json' },
body,
})
.then((response) => response.json())
.then(({ success, message }) => {
if (!success) {
return setState({
status: 'failed',
message: 'Unable to submit your request.',
});
}
return setState({ status: 'succeed', message });
})
.catch(() =>
setState({
status: 'failed',
message: 'Unable to submit your request.',
})
);
};
if (state.status === 'succeed' && state.message) {
return (
<Card className="uil-m-auto uil-ta-center apply-form">
<Heading1 className="apply-text">Thank you!</Heading1>
<br />
{state.message.startsWith('Your DocSearch') ? (
<Text
className="uil-pv-8 uil-d-block apply-text"
aria-label="Request has already been processed"
>
{state.message}
</Text>
) : (
<>
<Text
className="uil-pv-8 uil-d-block apply-text"
aria-label="Request will be processed"
>
{state.message} We'll get back to you at <strong>{email}</strong>{' '}
with the snippet you'll need to integrate into{' '}
<InlineLink href={url}>{url}</InlineLink>.
</Text>
<Text aria-label="recommendations" className="apply-text">
Please be patient, in the meantime, you can implement{' '}
<InlineLink href={withBaseUrl('docs/tips')}>
our recommendations for building a great DocSearch experience.
</InlineLink>
</Text>
</>
)}
</Card>
);
}
return (
<Card className="uil-m-auto apply-form uil-pb-24">
<form
id="form-apply-docsearch"
method="POST"
action="https://docsearch-hub.herokuapp.com/form/inbound"
onSubmit={onSubmit}
>
<LabelText key="url" tag="label" htmlFor="url" className="apply-text">
Documentation or Blog URL
<Input
required={true}
id="url"
type="url"
name="url"
aria-label="URL of the open-source blog or documentation website"
value={url}
placeholder="https://project.org/docs"
onChange={handleSetUrl}
/>
</LabelText>
<Text small={true} className="uil-pv-8 uil-d-block apply-text">
We'll scrape pages at this address and index the content on Algolia.
</Text>
<LabelText
tag="label"
htmlFor="email"
key="email"
className="apply-text"
>
Email
<Input
required={true}
id="email"
type="email"
name="email"
aria-label="Email address of the owner of this website"
value={email}
placeholder="you@project.org"
onChange={handleSetEmail}
/>
</LabelText>
<Text small={true} className="uil-pv-8 uil-d-block apply-text">
We'll send you the snippet you'll have to integrate into your website
and grant access to your Algolia application.
</Text>
<LabelText
tag="label"
htmlFor="repoURL"
key="repoURL"
className="apply-text"
>
Repository URL
<Input
required={true}
id="repoURL"
type="url"
name="repoURL"
aria-label="The URL of your project repository"
value={repo}
placeholder="https://github.com/algolia/docsearch, https://gitlab.com/gitlab-org/gitlab, etc..."
onChange={handleSetRepo}
/>
</LabelText>
<Text small={true} className="uil-pv-8 uil-d-block apply-text">
We will use this link to determine if your project is open-source.
</Text>
<div className="uil-ph-32 uil-d-flex uil-fxd-column">
<LabelText
className="uil-pt-12 apply-text"
tag="label"
htmlFor="public"
key="public"
>
<input
required={true}
id="public"
name="public"
aria-label="Confirm my website is publicly available"
type="checkbox"
className="uil-mr-8"
/>
My website is publicly available
</LabelText>
<LabelText
className="uil-pt-12 apply-text"
tag="label"
htmlFor="opensource"
key="opensource"
>
<input
required={true}
id="opensource"
name="opensource"
aria-label="Confirm my website is an technical documentation of an open-source project or technical blog"
type="checkbox"
className="uil-mr-8"
/>
My website is a technical documentation of an open-source project or
a technical blog
</LabelText>
<LabelText
className="uil-pt-12 apply-text"
tag="label"
htmlFor="owner"
key="owner"
>
<input
required={true}
id="owner"
name="owner"
aria-label="Confirm I am owner of the website"
type="checkbox"
className="uil-mr-8"
/>
I'm the owner of the website and I have{' '}
<InlineLink href={withBaseUrl('docs/who-can-apply')}>
read the checklist
</InlineLink>
</LabelText>
<Button
primary={true}
disabled={state.status === 'loading'}
className="uil-mt-16 uil-mb-16"
tag="button"
type="submit"
id="joinButton"
>
Join the program
</Button>
</div>
<Text small={true} className="uil-ta-center">
<InlineLink href="https://www.algolia.com/policies/terms">
Refer to Algolia's Privacy Policy for more information on how we use
and protect your data
</InlineLink>
</Text>
<Text small={true} className="uil-ta-center">
<strong>
Only apply if you don't have a DocSearch application yet. DocSearch
offers best effort support, make sure to first read the
documentation and the GitHub issues.
</strong>{' '}
Ultimately, you can reach out via{' '}
<InlineLink href="https://www.algolia.com/support/">
our support page.
</InlineLink>
</Text>
</form>
</Card>
);
}
export default ApplyForm;