From a24455dbffeb3efd0e5467e191a68fe42eb8a692 Mon Sep 17 00:00:00 2001 From: Joey Coscarelli <38106822+malfecient@users.noreply.github.com> Date: Sun, 18 Nov 2018 21:40:21 -0500 Subject: [PATCH] created contact page and component --- package-lock.json | 2 +- src/components/ContactForm.js | 57 +++++++++++++++++++++++++++++++++++ src/components/Main.js | 7 +++++ src/pages/ContactPage.js | 16 ++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/components/ContactForm.js create mode 100644 src/pages/ContactPage.js diff --git a/package-lock.json b/package-lock.json index d358b66..8af99fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5651,7 +5651,7 @@ }, "core-js": { "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=" }, "firebase": { diff --git a/src/components/ContactForm.js b/src/components/ContactForm.js new file mode 100644 index 0000000..7882ce2 --- /dev/null +++ b/src/components/ContactForm.js @@ -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 ( +
+ ); + } + } + + export default ContactForm; \ No newline at end of file diff --git a/src/components/Main.js b/src/components/Main.js index 8ecb20a..1b9d8b0 100644 --- a/src/components/Main.js +++ b/src/components/Main.js @@ -18,6 +18,7 @@ import AssignmentIcon from '@material-ui/icons/Assignment'; import MapIcon from '@material-ui/icons/Map'; import InfoIcon from '@material-ui/icons/Info'; import ListIcon from '@material-ui/icons/List'; +import ContactIcon from '@material-ui/icons/MailOutline'; import SlideshowIcon from '@material-ui/icons/Slideshow'; import Home from '../pages/Home'; import ViewMap from '../pages/ViewMap'; @@ -25,6 +26,7 @@ import Info from '../pages/Info'; import Quiz from '../pages/QuizPage'; import SightingList from '../pages/SightingList'; import Report from '../pages/Report'; +import Contact from '../pages/ContactPage'; import CssBaseline from '@material-ui/core/CssBaseline'; import ExpandLess from '@material-ui/icons/ExpandLess'; import ExpandMore from '@material-ui/icons/ExpandMore'; @@ -116,6 +118,10 @@ class ResponsiveDrawer extends React.Component {