Skip to content

Commit f47d61e

Browse files
author
MICHAEL JACKSON
committed
Add newsletter signup form to the website
1 parent f5abb33 commit f47d61e

File tree

6 files changed

+159
-164
lines changed

6 files changed

+159
-164
lines changed

website/modules/components/Footer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { Block, Inline } from "jsxstyle";
33
import { DARK_GRAY, BRIGHT_GRAY, LIGHT_GRAY } from "../Theme";
4-
import NewsletterSignup from "./NewsletterSignup";
4+
import MailingListSignup from "./MailingListSignup";
55

66
const FooterLink = ({ href, ...rest }) => (
77
<Inline component="a" props={{ href }} {...rest} textDecoration="underline" />
@@ -27,7 +27,7 @@ const year = new Date().getFullYear();
2727

2828
const Footer = () => (
2929
<Block>
30-
<NewsletterSignup />
30+
<MailingListSignup />
3131
<Block
3232
background={DARK_GRAY}
3333
color={BRIGHT_GRAY}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import React, { Component } from "react";
2+
import PropTypes from "prop-types";
3+
import { Block, Flex } from "jsxstyle";
4+
5+
import subscribeToMailingList from "../utils/subscribeToMailingList";
6+
import { RED } from "../Theme";
7+
import SmallScreen from "./SmallScreen";
8+
9+
const Button = ({ children, ...props }) => (
10+
<Block
11+
component="button"
12+
color="#fff"
13+
padding="15px 10px"
14+
background={RED}
15+
borderRadius={0}
16+
cursor="pointer"
17+
border="none"
18+
textShadow="none"
19+
minWidth="80px"
20+
children={children}
21+
{...props}
22+
/>
23+
);
24+
25+
Button.propTypes = {
26+
children: PropTypes.node
27+
};
28+
29+
const Input = ({ margin, ...props }) => (
30+
<Block
31+
component="input"
32+
padding="10px 8px"
33+
border="1px solid #d6d6d6"
34+
borderRadius="0"
35+
backgroundColor="white"
36+
height="42px"
37+
flex="1"
38+
props={props}
39+
margin={margin}
40+
/>
41+
);
42+
43+
Input.propTypes = {
44+
margin: PropTypes.any
45+
};
46+
47+
class MailingListSignup extends Component {
48+
state = {
49+
email: "",
50+
submitted: true
51+
};
52+
53+
handleSubmit = e => {
54+
e.preventDefault();
55+
56+
if (this.state.email) {
57+
subscribeToMailingList(this.state.email).then(() => {
58+
this.setState({
59+
email: "",
60+
submitted: true
61+
});
62+
});
63+
}
64+
};
65+
66+
render() {
67+
const { email, submitted } = this.state;
68+
69+
return (
70+
<SmallScreen>
71+
{isSmallScreen => (
72+
<Block
73+
background="white"
74+
maxWidth="700px"
75+
margin="auto"
76+
padding={isSmallScreen ? "40px" : "80px"}
77+
>
78+
{submitted ? (
79+
<Block textAlign="center">
80+
<p>Thanks! You've been added to the list.</p>
81+
<p style={{ marginTop: 10 }}>
82+
<a
83+
style={{ textDecoration: "underline", cursor: "pointer" }}
84+
onClick={() => this.setState({ submitted: false })}
85+
>
86+
Reset
87+
</a>
88+
</p>
89+
</Block>
90+
) : (
91+
<div>
92+
<Block
93+
margin="auto"
94+
paddingBottom={isSmallScreen ? "20px" : "40px"}
95+
textAlign="center"
96+
fontSize={isSmallScreen ? "100%" : "150%"}
97+
fontWeight="bold"
98+
>
99+
Sign up to receive updates about React Router,{" "}
100+
<a
101+
href="https://reacttraining.com"
102+
style={{ textDecoration: "underline" }}
103+
>
104+
our React workshops
105+
</a>, and more:
106+
</Block>
107+
<form onSubmit={this.handleSubmit}>
108+
<Flex
109+
flexDirection={isSmallScreen ? "column" : "row"}
110+
justifyContent="space-around"
111+
>
112+
<Input
113+
value={email}
114+
onChange={e => this.setState({ email: e.target.value })}
115+
type="email"
116+
name="email"
117+
placeholder="[email protected]"
118+
margin={isSmallScreen ? "0 0 5px 0" : "0 5px 0 0"}
119+
/>
120+
<Button type="submit">Subscribe</Button>
121+
</Flex>
122+
</form>
123+
</div>
124+
)}
125+
</Block>
126+
)}
127+
</SmallScreen>
128+
);
129+
}
130+
}
131+
132+
export default MailingListSignup;

website/modules/components/NewsletterSignup.js

Lines changed: 0 additions & 157 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fetch from "isomorphic-fetch";
2+
import qs from "query-string";
3+
4+
function subscribeToMailingList(email) {
5+
return fetch("https://reacttraining.us16.list-manage.com/subscribe/post", {
6+
method: "POST",
7+
mode: "no-cors",
8+
headers: {
9+
"Content-Type": "application/x-www-form-urlencoded"
10+
},
11+
body: qs.stringify({
12+
u: "47df8ab2101d1dd83353427fc",
13+
id: "83f54bda60",
14+
MERGE0: email
15+
})
16+
});
17+
}
18+
19+
export default subscribeToMailingList;

website/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"private": true,
33
"name": "react-router-website",
4-
"version": "4.2.0",
54
"scripts": {
65
"build": "NODE_ENV=production webpack -p",
76
"clean": "git clean -fdX .",
@@ -40,7 +39,9 @@
4039
"dependencies": {
4140
"animated": "^0.2.1",
4241
"cheerio": "^0.22.0",
42+
"isomorphic-fetch": "^2.2.1",
4343
"prop-types": "^15.6.0",
44+
"query-string": "^5.1.0",
4445
"react": "^16.2.0",
4546
"react-css-property-operations": "^15.4.1",
4647
"react-dom": "^16.2.0",

0 commit comments

Comments
 (0)