created contact page and component

This commit is contained in:
Joey Coscarelli 2018-11-18 21:40:21 -05:00
parent 17410d3eec
commit a24455dbff
4 changed files with 81 additions and 1 deletions

2
package-lock.json generated
View File

@ -5651,7 +5651,7 @@
}, },
"core-js": { "core-js": {
"version": "2.5.5", "version": "2.5.5",
"resolved": "http://registry.npmjs.org/core-js/-/core-js-2.5.5.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.5.tgz",
"integrity": "sha1-sU3ek2xkDAV5prUMq8wTLdYSfjs=" "integrity": "sha1-sU3ek2xkDAV5prUMq8wTLdYSfjs="
}, },
"firebase": { "firebase": {

View File

@ -0,0 +1,57 @@
import React, { Component } from 'react';
const encode = (data) => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&");
}
class ContactForm extends Component {
constructor(props) {
super(props);
this.state = { name: "", email: "", message: "" };
}
handleSubmit = e => {
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: encode({ "form-name": "contact", ...this.state })
})
.then(() => alert("Success!"))
.catch(error => alert(error));
e.preventDefault();
};
handleChange = e => this.setState({ [e.target.name]: e.target.value });
render() {
const { name, email, message } = this.state;
return (
<form onSubmit={this.handleSubmit}>
<p>
<label>
Your Name: <input type="text" name="name" value={name} onChange={this.handleChange} />
</label>
</p>
<p>
<label>
Your Email: <input type="email" name="email" value={email} onChange={this.handleChange} />
</label>
</p>
<p>
<label>
Message: <textarea name="message" value={message} onChange={this.handleChange} />
</label>
</p>
<p>
<button type="submit">Send</button>
</p>
</form>
);
}
}
export default ContactForm;

View File

@ -18,6 +18,7 @@ import AssignmentIcon from '@material-ui/icons/Assignment';
import MapIcon from '@material-ui/icons/Map'; import MapIcon from '@material-ui/icons/Map';
import InfoIcon from '@material-ui/icons/Info'; import InfoIcon from '@material-ui/icons/Info';
import ListIcon from '@material-ui/icons/List'; import ListIcon from '@material-ui/icons/List';
import ContactIcon from '@material-ui/icons/MailOutline';
import SlideshowIcon from '@material-ui/icons/Slideshow'; import SlideshowIcon from '@material-ui/icons/Slideshow';
import Home from '../pages/Home'; import Home from '../pages/Home';
import ViewMap from '../pages/ViewMap'; import ViewMap from '../pages/ViewMap';
@ -25,6 +26,7 @@ import Info from '../pages/Info';
import Quiz from '../pages/QuizPage'; import Quiz from '../pages/QuizPage';
import SightingList from '../pages/SightingList'; import SightingList from '../pages/SightingList';
import Report from '../pages/Report'; import Report from '../pages/Report';
import Contact from '../pages/ContactPage';
import CssBaseline from '@material-ui/core/CssBaseline'; import CssBaseline from '@material-ui/core/CssBaseline';
import ExpandLess from '@material-ui/icons/ExpandLess'; import ExpandLess from '@material-ui/icons/ExpandLess';
import ExpandMore from '@material-ui/icons/ExpandMore'; import ExpandMore from '@material-ui/icons/ExpandMore';
@ -116,6 +118,10 @@ class ResponsiveDrawer extends React.Component {
<ListItemIcon><InfoIcon /></ListItemIcon> <ListItemIcon><InfoIcon /></ListItemIcon>
<ListItemText primary='About' /> <ListItemText primary='About' />
</ListItem> </ListItem>
<ListItem button key='Contact' onClick={() => this.nav('Contact')}>
<ListItemIcon><ContactIcon /></ListItemIcon>
<ListItemText primary='Contact' />
</ListItem>
<ListItem button onClick={this.handleClick}> <ListItem button onClick={this.handleClick}>
<ListItemIcon> <ListItemIcon>
<SlideshowIcon /> <SlideshowIcon />
@ -196,6 +202,7 @@ class ResponsiveDrawer extends React.Component {
{this.state.key === 'Map' && <ViewMap />} {this.state.key === 'Map' && <ViewMap />}
{this.state.key === 'List' && <SightingList />} {this.state.key === 'List' && <SightingList />}
{this.state.key === 'About' && <Info />} {this.state.key === 'About' && <Info />}
{this.state.key === 'Contact' && <Contact />}
{this.state.key === 'Easy-Quiz' && <Quiz difficulty='Easy'/>} {this.state.key === 'Easy-Quiz' && <Quiz difficulty='Easy'/>}
{this.state.key === 'Medium-Quiz' && <Quiz difficulty='Medium'/>} {this.state.key === 'Medium-Quiz' && <Quiz difficulty='Medium'/>}
{this.state.key === 'Hard-Quiz' && <Quiz difficulty='Hard'/>} {this.state.key === 'Hard-Quiz' && <Quiz difficulty='Hard'/>}

16
src/pages/ContactPage.js Normal file
View File

@ -0,0 +1,16 @@
import React, { Component } from 'react';
import ContactForm from '../components/ContactForm';
class ContactPage extends Component {
componentDidMount() {
document.title = 'Marten Tracker | Contact';
}
render() {
return (
<ContactForm/>
);
}
}
export default ContactPage;