Skip to content

Commit dc48820

Browse files
committed
WIP Form
1 parent 49e8448 commit dc48820

File tree

5 files changed

+154
-1
lines changed

5 files changed

+154
-1
lines changed

src/components/contact-us/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
import Container from '../container';
4+
import Form from '../form';
5+
6+
export default props => {
7+
return (
8+
<Container size="medium">
9+
<h1>Contact us</h1>
10+
<p>If you would like to organize a Python Pizza, get in touch!</p>
11+
<Container size="small">
12+
<Form />
13+
</Container>
14+
</Container>
15+
);
16+
};

src/components/container/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
--container-size: 120rem;
1616
}
1717

18-
h1 {
18+
h1,
19+
p {
1920
text-align: center;
2021
}
2122
}

src/components/form/index.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.Form {
2+
label {
3+
display: block;
4+
text-align: center;
5+
6+
margin-top: 1rem;
7+
}
8+
9+
input,
10+
textarea {
11+
display: block;
12+
width: 100%;
13+
margin-top: 0.2rem;
14+
}
15+
16+
textarea {
17+
min-height: 10rem;
18+
resize: vertical;
19+
}
20+
21+
&--submit-container {
22+
text-align: center;
23+
margin-top: 1rem;
24+
25+
button {
26+
max-width: 30rem;
27+
width: 100%;
28+
height: 3rem;
29+
30+
font-family: var(--font-name--heading);
31+
font-size: 1.6rem;
32+
33+
background: var(--primary-color);
34+
border-radius: 0.4rem;
35+
color: var(--white);
36+
cursor: pointer;
37+
border: 0;
38+
39+
appearance: none;
40+
}
41+
}
42+
}

src/components/form/index.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { useState, useCallback } from 'react';
2+
3+
import './index.css';
4+
5+
const encode = data => {
6+
return Object.keys(data)
7+
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
8+
.join('&');
9+
};
10+
11+
export default props => {
12+
const [name, setName] = useState('');
13+
const [email, setEmail] = useState('');
14+
const [message, setMessage] = useState('');
15+
const [city, setCity] = useState('');
16+
17+
const onChangeName = useCallback(e => setName(e.target.value), []);
18+
const onChangeEmail = useCallback(e => setEmail(e.target.value), []);
19+
const onChangeMessage = useCallback(e => setMessage(e.target.value), []);
20+
const onChangeCity = useCallback(e => setCity(e.target.value), []);
21+
const onSubmit = useCallback(
22+
async e => {
23+
e.preventDefault();
24+
25+
try {
26+
const response = await fetch('/', {
27+
method: 'POST',
28+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
29+
body: encode({
30+
'form-name': 'contact',
31+
name,
32+
email,
33+
city,
34+
message,
35+
}),
36+
});
37+
38+
console.log('response', response);
39+
} catch (e) {
40+
console.error('error');
41+
}
42+
},
43+
[name, email]
44+
);
45+
46+
return (
47+
<form onSubmit={onSubmit} className="Form" name="contact">
48+
<label>
49+
<span>Your name</span>
50+
<input
51+
required
52+
onChange={onChangeName}
53+
value={name}
54+
type="text"
55+
name="name"
56+
/>
57+
</label>
58+
<label>
59+
<span>Your Email</span>
60+
<input
61+
required
62+
onChange={onChangeEmail}
63+
value={email}
64+
type="email"
65+
name="email"
66+
/>
67+
</label>
68+
<label>
69+
<span>City</span>
70+
<input
71+
required
72+
onChange={onChangeCity}
73+
value={city}
74+
type="text"
75+
name="city"
76+
/>
77+
</label>
78+
<label>
79+
<span>Your message</span>
80+
<textarea
81+
required
82+
onChange={onChangeMessage}
83+
value={message}
84+
name="email"
85+
/>
86+
</label>
87+
<div className="Form--submit-container">
88+
<button type="submit">Send</button>
89+
</div>
90+
</form>
91+
);
92+
};

src/pages/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import Layout from '../components/layout';
44
import SEO from '../components/seo';
55
import Hero from '../components/hero';
66
import PastEvents from '../components/past-events';
7+
import ContactUs from '../components/contact-us';
78

89
export default props => (
910
<Layout>
1011
<SEO title="Home" />
1112
<Hero />
1213
<PastEvents />
14+
<ContactUs />
1315
</Layout>
1416
);

0 commit comments

Comments
 (0)