-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathForm.js
More file actions
212 lines (196 loc) · 6.2 KB
/
Form.js
File metadata and controls
212 lines (196 loc) · 6.2 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
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
import './Form.scss';
import React, { Component } from 'react';
import axios from 'axios';
import { withTranslation } from 'react-i18next';
import i18n from 'i18next'
import { BodyText } from '../BodyText/BodyText';
import Element from '../Element/Element';
const GOOGLE_FORM_ACTION_URL =
'https://docs.google.com/forms/d/e/1FAIpQLSeO9jt4-iUsiFaLT5Rpwt47sNceu25te2UO7WGQ2wcUNTbBiQ/formResponse';
const GOOGLE_FORM_NAME_ID = 'entry.1118152809';
const GOOGLE_FORM_TITLE_ID = 'entry.2015280305';
const GOOGLE_FORM_ORGANIZATION_ID = 'entry.578868795';
const GOOGLE_FORM_PHONE_ID = 'entry.1958784460';
const GOOGLE_FORM_EMAIL_ID = 'entry.2042435833';
const GOOGLE_FORM_QUESTION_ID = 'entry.1350466445';
const PROXY_URL = 'https://cors-anywhere.herokuapp.com/';
class Form extends Component {
constructor(props) {
super(props);
this.state = {
showForm: false,
formIsSent: false,
name: '',
title: '',
organization: '',
phone: '',
email: '',
question: '',
};
}
handleSubmit = (event) => {
event.preventDefault();
this.sendMessage();
};
handleChange = (e) => {
this.setState({ ...this.state, [e.target.name]: e.target.value });
};
sendMessage = () => {
const { name, title, organization, phone, email, question } = this.state;
const formData = new FormData();
formData.append(GOOGLE_FORM_NAME_ID, name);
formData.append(GOOGLE_FORM_TITLE_ID, title);
formData.append(GOOGLE_FORM_ORGANIZATION_ID, organization);
formData.append(GOOGLE_FORM_PHONE_ID, phone);
formData.append(GOOGLE_FORM_EMAIL_ID, email);
formData.append(GOOGLE_FORM_QUESTION_ID, question);
axios
.post(PROXY_URL + GOOGLE_FORM_ACTION_URL, formData)
.then(() => {
this.setState({
name: '',
title: '',
organization: '',
phone: '',
email: '',
question: '',
formIsSent: true,
});
})
.catch(() => {
this.setState({
messageError: true,
});
});
};
render() {
const {
showForm,
formIsSent,
name,
title,
organization,
phone,
email,
question,
} = this.state;
const { t } = this.props;
const isRtl = i18n.dir() === 'rtl'
return (
<>
{showForm ? (
<>
{!formIsSent ? (
<form onSubmit={this.handleSubmit} className="form col-10">
<p className="spacing--small">
{t('challengePage:nameLabel')}
<span aria-hidden="true">*</span>
</p>
<input
required
autoComplete="off"
className="col-10"
placeholder={t('challengePage:namePlaceholder')}
type="text"
name="name"
value={name}
onChange={this.handleChange}
/>
<p className="spacing--small">
{t('challengePage:titleLabel')}
<span aria-hidden="true">*</span>
</p>
<input
required
autoComplete="off"
className="col-10"
placeholder="CEO"
type="text"
name="title"
value={title}
onChange={this.handleChange}
/>
<p className="spacing--small">
{t('challengePage:companyLabel')}
<span aria-hidden="true">*</span>
</p>
<input
required
autoComplete="off"
className="col-10"
placeholder={t('challengePage:companyPlaceholder')}
type="text"
name="organization"
value={organization}
onChange={this.handleChange}
/>
<p className="spacing--small">
{t('challengePage:phoneLabel')}
<span aria-hidden="true">*</span>
</p>
<input
autoComplete="off"
className="col-10"
placeholder="+358 40 234 5678"
type="text"
name="phone"
value={phone}
onChange={this.handleChange}
/>
<p className="spacing--small">
{t('challengePage:emailLabel')}
<span aria-hidden="true">*</span>
</p>
<input
required
autoComplete="off"
className="col-10"
placeholder="email@domain.com"
type="email"
name="email"
value={email}
onChange={this.handleChange}
/>
<p className="spacing--small">
{t('challengePage:whereDidYouHearLabel')}
</p>
<input
autoComplete="off"
className="col-10"
type="text"
name="question"
value={question}
onChange={this.handleChange}
/>
<button
className={`submit spacing spacing--after ${isRtl ? 'push-left-4' : 'push-right-4'}`}
type="submit"
>
{t('challengePage:submitButton')}
</button>
</form>
) : (
<BodyText
className="spacing"
headingFont
text={t('challengePage:submitSuccessMessage')}
/>
)}
</>
) : (
<>
<Element flex spaceAround className="col-10 spacing">
<button
className="about__challenge-button about__challenge-button--turquoise"
onClick={() => this.setState({ showForm: true })}
>
{t('challengePage:registerButton')}
</button>
</Element>
</>
)}
</>
);
}
}
export default withTranslation()(Form);