page update

This commit is contained in:
Sergejs Kozinecs 2022-10-19 17:28:46 +03:00
parent 08ab3418c6
commit 7c05d1dd66
11 changed files with 154 additions and 60 deletions

View file

@ -1,5 +1,6 @@
import React, { useState } from "react"; import React, { useState, useRef } from "react";
import axios from "axios"; import axios from "axios";
import { useTranslation } from "react-i18next";
import "./contact-form.style.scss"; import "./contact-form.style.scss";
import Dog from "../../assets/images/main/contact-form/mask.svg"; import Dog from "../../assets/images/main/contact-form/mask.svg";
import BluePlanet from "../../assets/images/main/contact-form/Planet Blue.svg"; import BluePlanet from "../../assets/images/main/contact-form/Planet Blue.svg";
@ -8,21 +9,43 @@ import YellowPlanet from "../../assets/images/main/contact-form/Planet Yellow.sv
import FormInput from "../form-input/form-input.component"; import FormInput from "../form-input/form-input.component";
import CustomButton from "../custom-button/custom-button.component"; import CustomButton from "../custom-button/custom-button.component";
const postForm = (e, data) => { const postForm = async (data) => {
e.preventDefault(); return axios
console.log("post form", data); .post(
axios "https://api.midcreative.eu/api/email/",
.post("http://127.0.0.1:3005/contact", data) {
.then((res) => console.log(res)); to: "sergei.kozinecs@gmail.com",
from: "info@midcreative.eu",
subject: "Midcreative Submit Form",
html: `<b>Name: </b>${data.name} <br><b>Email: </b>${data.email} <b><br>Phone: </b> ${data.phone}<br>`,
},
{
headers: {
"Content-Type": "application/json",
},
}
)
.then(() => {
return true;
})
.catch((err) => err);
}; };
const ContactForm = () => { const ContactForm = () => {
const { t } = useTranslation();
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
name: "", name: "",
email: "", email: "",
phone: "", phone: "",
}); });
const nameInputRef = useRef(null);
const emailInputRef = useRef(null);
const phoneInputRef = useRef(null);
const [success, setSuccess] = useState();
const [error, setError] = useState();
const setName = (name) => { const setName = (name) => {
setFormData({ ...formData, name: name }); setFormData({ ...formData, name: name });
}; };
@ -35,14 +58,32 @@ const ContactForm = () => {
setFormData({ ...formData, phone: phone }); setFormData({ ...formData, phone: phone });
}; };
const handleSubmit = (e) => { const cleanFields = () => {
nameInputRef.current.clean();
emailInputRef.current.clean();
phoneInputRef.current.clean();
};
const handlePost = (e) => {
e.preventDefault(); e.preventDefault();
console.log(e);
postForm(formData).then((res) => {
if (res === true) {
cleanFields();
setError(false);
setSuccess(true);
setTimeout(() => setSuccess(false), 6000);
} else {
cleanFields();
setError(true);
setSuccess(false);
}
});
}; };
return ( return (
<div className="container contact-form"> <div className="container contact-form">
<h2>Lets bring your project to the Moon</h2> <h2>{t("contacts.title")}</h2>
<div className="image"> <div className="image">
<img src={Dog} alt="cute dog in space" /> <img src={Dog} alt="cute dog in space" />
@ -50,35 +91,40 @@ const ContactForm = () => {
<img src={YellowPlanet} alt="yellow planet" className="planet yellow" /> <img src={YellowPlanet} alt="yellow planet" className="planet yellow" />
</div> </div>
<form <form className="container" onSubmit={(e) => handlePost(e)}>
// action="http://127.0.0.1:3005/contact" {success ? <p className="success">{t("contacts.success")}</p> : null}
className="container" {error ? (
// method="POST" <p className="error">
// onSubmit={(e) => postForm(e, formData)} {t("contacts.error")}{" "}
> <a href="mailto:info@midcreative.eu">info@midcreative.eu</a>
</p>
) : null}
<FormInput <FormInput
name="name" name="name"
type="text" type="text"
label="Name" label={t("contacts.name")}
onChange={setName} onChange={setName}
ref={nameInputRef}
required required
/> />
<FormInput <FormInput
name="email" name="email"
type="email" type="email"
label="E-mail" label={t("contacts.email")}
onChange={setEmail} onChange={setEmail}
ref={emailInputRef}
required required
/> />
<FormInput <FormInput
name="phone" name="phone"
type="tel" type="tel"
label="Phone" label={t("contacts.phone")}
onChange={setPhone} onChange={setPhone}
ref={phoneInputRef}
required required
/> />
<CustomButton text="Send" /> <CustomButton text={t("contacts.send")} />
</form> </form>
</div> </div>
); );

View file

@ -14,6 +14,20 @@ section.content {
grid-row: 1/2; grid-row: 1/2;
} }
.success {
margin-bottom: 16px;
color: rgba(116, 199, 103, 1);
}
.error {
margin-bottom: 16px;
color: rgba(246, 81, 81, 1);
a {
color: rgba(246, 81, 81, 1);
}
}
form { form {
grid-column: 1/5; grid-column: 1/5;
grid-row: 2/3; grid-row: 2/3;
@ -44,7 +58,12 @@ section.content {
img { img {
&:first-child { &:first-child {
background: linear-gradient(0deg, rgba(27, 27, 27, 0.2), rgba(27, 27, 27, 0.2)), rgba(255, 255, 255, 0.01); background: linear-gradient(
0deg,
rgba(27, 27, 27, 0.2),
rgba(27, 27, 27, 0.2)
),
rgba(255, 255, 255, 0.01);
box-shadow: inset 0px 2px 5px rgb(255 255 255 / 15%); box-shadow: inset 0px 2px 5px rgb(255 255 255 / 15%);
backdrop-filter: blur(8px); backdrop-filter: blur(8px);
border-radius: 33px; border-radius: 33px;
@ -66,7 +85,8 @@ section.content {
} }
@include for-tablets { @include for-tablets {
h2, form { h2,
form {
grid-column: 1/7; grid-column: 1/7;
} }
@ -74,7 +94,6 @@ section.content {
grid-column: 8/13; grid-column: 8/13;
} }
} }
@include for-mobile { @include for-mobile {
h2, h2,
@ -94,6 +113,8 @@ section.content {
.image { .image {
grid-row: 2/3; grid-row: 2/3;
width: 100%; width: 100%;
margin-bottom: 16px;
img { img {
margin: 0 auto; margin: 0 auto;
} }

View file

@ -1,33 +1,42 @@
import React, { useState } from "react"; import React, { useState, forwardRef, useImperativeHandle } from "react";
import "./form-input.style.scss"; import "./form-input.style.scss";
const FormInput = ({ handleChange, label, onChange, ...otherProps }) => { const FormInput = forwardRef(
const [input, setInput] = useState(""); ({ handleChange, label, onChange, ...otherProps }, ref) => {
const [toggleLabel, changeToggleLabel] = useState(false); const [input, setInput] = useState("");
const [toggleLabel, changeToggleLabel] = useState(false);
return ( useImperativeHandle(ref, () => ({
<div className="group"> clean() {
<label setInput("");
className={`${toggleLabel ? "shrink" : ""} ${ changeToggleLabel(false);
input ? "shrink" : "" },
} form-input-label`} }));
>
{label} return (
</label> <div className="group">
<input <label
value={input} className={`${toggleLabel ? "shrink" : ""} ${
onChange={(e) => { input ? "shrink" : ""
setInput(e.target.value); } form-input-label`}
onChange(e.target.value); >
}} {label}
onFocus={() => changeToggleLabel(true)} </label>
onBlur={() => <input
input ? changeToggleLabel(true) : changeToggleLabel(false) value={input}
} onChange={(e) => {
{...otherProps} setInput(e.target.value);
/> onChange(e.target.value);
</div> }}
); onFocus={() => changeToggleLabel(true)}
}; onBlur={() =>
input ? changeToggleLabel(true) : changeToggleLabel(false)
}
{...otherProps}
/>
</div>
);
}
);
export default FormInput; export default FormInput;

View file

@ -12,7 +12,7 @@ import Email from "../../assets/images/main/footer/email.png";
import "./header.style.scss"; import "./header.style.scss";
const MidHeader = () => { const MidHeader = () => {
const { t, i18n } = useTranslation(); const { t } = useTranslation();
const toggleMenu = () => { const toggleMenu = () => {
if (window !== "undefined") { if (window !== "undefined") {

View file

@ -6,7 +6,7 @@ import "./intro.styles.scss";
import Spaceship from "../../assets/images/main/intro/spaceship.svg"; import Spaceship from "../../assets/images/main/intro/spaceship.svg";
const Intro = () => { const Intro = () => {
const { t, i18n } = useTranslation(); const { t } = useTranslation();
return ( return (
<section className="container intro"> <section className="container intro">

View file

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React from "react";
import i18n from "../../i18n"; import i18n from "../../i18n";
import "./language-switch.style.scss"; import "./language-switch.style.scss";

View file

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import { useSiteMetadata } from "../hooks/use-site-metadata"; import { useSiteMetadata } from "../hooks/use-site-metadata";
export const SEO = ({ title, description, pathname, children }) => { export const Seo = ({ title, description, pathname, children }) => {
const { const {
title: defaultTitle, title: defaultTitle,
description: defaultDescription, description: defaultDescription,

View file

@ -13,7 +13,7 @@ import MidFooter from "../components/footer/footer.component";
import Projects from "../components/projects/projects.component"; import Projects from "../components/projects/projects.component";
const MidMainPage = () => { const MidMainPage = () => {
const { t, i18n } = useTranslation(); const { t } = useTranslation();
return ( return (
<div className="main-page"> <div className="main-page">

View file

@ -1,5 +1,5 @@
import * as React from "react"; import * as React from "react";
import { SEO } from "../components/seo"; import { Seo } from "../components/seo";
import "../assets/stylesheets/style.scss"; import "../assets/stylesheets/style.scss";
@ -11,4 +11,4 @@ const IndexPage = () => {
export default IndexPage; export default IndexPage;
export const Head = () => <SEO />; export const Head = () => <Seo />;

View file

@ -82,5 +82,14 @@
"info": ["Website", "CMS"], "info": ["Website", "CMS"],
"text": "Fleet Management Software providers - website and content management system development" "text": "Fleet Management Software providers - website and content management system development"
} }
] ],
"contacts": {
"title": "Lets bring your project to the Moon",
"name": "name",
"email": "E-mail",
"phone": "phone",
"send": "Send",
"success": "Thank you for sharing your contacts! We will get in touch!",
"error": "Looks like something went wrong, please try to reach us directly "
}
} }

View file

@ -82,5 +82,14 @@
"info": ["Website", "CMS"], "info": ["Website", "CMS"],
"text": "Autoparka pārvaldības sistēmas mājas lapa un satura vadības sistēmas izstrāde" "text": "Autoparka pārvaldības sistēmas mājas lapa un satura vadības sistēmas izstrāde"
} }
] ],
"contacts": {
"title": "Lets bring your project to the Moon",
"name": "Vārds",
"email": "Ēpasts",
"phone": "Telefons",
"send": "Nosūtīt",
"success": "Paldies ",
"error": "Looks like something went wrong, please try to reach us directly info@midcreative.eu"
}
} }