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 ( +
+

+ +

+

+ +

+

+