From 76378f075a8c5f0a8c40b9f75d31dbde70f765f6 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Thu, 23 Jul 2020 21:19:33 +0300 Subject: [PATCH] netlify form test --- src/components/Contacts/Contacts.scss | 6 ++ .../Contacts/ContactsForm/ContactsForm.js | 83 +++++++++++++++++-- src/components/Header/Header.js | 47 +++++++---- src/components/Header/Header.scss | 12 ++- src/images/yadzen-icon.svg | 19 +++++ 5 files changed, 140 insertions(+), 27 deletions(-) create mode 100644 src/images/yadzen-icon.svg diff --git a/src/components/Contacts/Contacts.scss b/src/components/Contacts/Contacts.scss index a55d329..4d123c9 100644 --- a/src/components/Contacts/Contacts.scss +++ b/src/components/Contacts/Contacts.scss @@ -21,6 +21,12 @@ font-weight: 500; } } + & .contacts-submitted { + margin-bottom: 30px; + & h2 { + margin-bottom: 10px; + } + } & .contacts-form { margin-bottom: 50px; & h2 { diff --git a/src/components/Contacts/ContactsForm/ContactsForm.js b/src/components/Contacts/ContactsForm/ContactsForm.js index 127177e..ef48b00 100644 --- a/src/components/Contacts/ContactsForm/ContactsForm.js +++ b/src/components/Contacts/ContactsForm/ContactsForm.js @@ -1,16 +1,87 @@ import React from "react" +function encode(data) { + return Object.keys(data) + .map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key])) + .join("&") +} + const ContactsFrom = () => { + const [state, setState] = React.useState({}) + const [submitted, setSubmitted] = React.useState(false) + + const handleChange = e => { + setState({ ...state, [e.target.name]: e.target.value }) + } + + const handleSubmit = e => { + e.preventDefault() + const form = e.target + fetch("/", { + method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: encode({ + "form-name": form.getAttribute("name"), + ...state, + }), + }) + .then(() => setSubmitted(true)) + .catch(error => alert(error)) + } + + if (submitted) + return ( +
+

+ + ✔️ + {" "} + Данные приняты! +

+

+ Ваше письмо было обработано, в течение нескольких дней вам на почту + придет ответ. +

+
+ ) + return (

форма обратной связи

-
- - - -