Browse Source

contactForm: vérification de la présence des données

Lou 3 years ago
parent
commit
fb14feca94

+ 26
- 11
src/components/contactForm/index.jsx View File

@@ -4,12 +4,15 @@ import React, { useState } from "react";
4 4
 import "./index.scss";
5 5
 import ProfilePic from "../../images/profile.svg";
6 6
 import AtSymbole from "../../images/atSymbole.svg";
7
+// import { toast } from "react-toastify";
7 8
 
8 9
 const ContactForm = () => {
9 10
 	const [name, setName] = useState("");
10 11
 	const [email, setEmail] = useState("");
11 12
 	const [message, setMessage] = useState("");
12 13
 
14
+	// const notify = (msg) => toast(msg);
15
+
13 16
 	const handleNameChange = (e) => {
14 17
 		setName(e.target.value);
15 18
 	};
@@ -23,6 +26,10 @@ const ContactForm = () => {
23 26
 	};
24 27
 
25 28
 	const sendEmail = (data) => {
29
+		console.log("Log name " + data.from_name);
30
+		console.log("Log email " + data.from_email);
31
+		console.log("Log message " + data.from_message);
32
+
26 33
 		emailjs
27 34
 			.send(
28 35
 				process.env.SERVICE_ID,
@@ -31,11 +38,13 @@ const ContactForm = () => {
31 38
 				process.env.USER_ID
32 39
 			)
33 40
 			.then(
34
-				(result) => {
35
-					return true;
41
+				() => {
42
+					alert("Message envoyé");
36 43
 				},
37
-				(error) => {
38
-					return false;
44
+				() => {
45
+					alert(
46
+						"Votre message n'a pas pu être envoyé. Merci de nous contacter directement par mail."
47
+					);
39 48
 				}
40 49
 			);
41 50
 	};
@@ -43,17 +52,23 @@ const ContactForm = () => {
43 52
 	const handleSubmit = (e) => {
44 53
 		e.preventDefault();
45 54
 
46
-		const data = {
47
-			from_name: name,
48
-			from_email: email,
49
-			from_message: message
50
-		};
55
+		if (name === "" || email === "" || message === "") {
56
+			alert("Veuillez remplir tous les champs.");
57
+			return;
58
+		} else {
59
+			const data = {
60
+				from_name: name,
61
+				from_email: email,
62
+				from_message: message
63
+			};
51 64
 
52
-		if (sendEmail) e.target.reset();
65
+			sendEmail(data);
66
+			e.target.reset();
67
+		}
53 68
 	};
54 69
 
55 70
 	return (
56
-		<div id="contact">
71
+		<div id="contact-form-container">
57 72
 			<form id="contact-form" action="" onSubmit={handleSubmit}>
58 73
 				<div className="form-group">
59 74
 					<img

+ 3
- 4
src/components/contactForm/index.scss View File

@@ -1,12 +1,11 @@
1
-#contact {
1
+#contact-form-container {
2 2
 	border-radius: 10px;
3 3
 	background-color: #fff;
4
-	margin: 0 auto;
5 4
 	padding: 10px;
6
-	width: auto;
5
+	width: 40rem;
7 6
 
8 7
 	#contact-form {
9
-		width: 100%;
8
+		width: 80vw, 40rem;
10 9
 		display: flex;
11 10
 		flex-direction: column;
12 11
 		margin: 1rem;

+ 1
- 1
src/components/realisationCard/index.jsx View File

@@ -5,7 +5,7 @@ import Specs from "../../images/undraw_Specs.svg";
5 5
 
6 6
 const RealisationCard = ({ cardName, cardDescription, techTag }) => {
7 7
 	const displayTags = techTag.split(",").map((tag) => (
8
-		<span key={tag.id} className="tech-tag">
8
+		<span key={tag} className="tech-tag">
9 9
 			{tag}
10 10
 		</span>
11 11
 	));

+ 2
- 0
src/pages/nous-contacter.jsx View File

@@ -1,4 +1,5 @@
1 1
 import React from "react";
2
+// import ToastContainer from "react-toastify";
2 3
 
3 4
 import Header from "../components/header";
4 5
 import ContactForm from "../components/contactForm";
@@ -30,6 +31,7 @@ const NousContacter = () => {
30 31
 				</div>
31 32
 				<ContactForm />
32 33
 			</div>
34
+			{/* <ToastContainer /> */}
33 35
 			<Footer />
34 36
 		</main>
35 37
 	);

+ 1
- 1
src/scss/index.scss View File

@@ -118,7 +118,7 @@ section.services-list {
118 118
 .page-contact {
119 119
 	display: flex;
120 120
 	flex-wrap: wrap-reverse;
121
-
121
+	justify-content: center;
122 122
 	.contact-instructions {
123 123
 		margin: 1rem;
124 124
 

+ 1
- 8
yarn.lock View File

@@ -999,7 +999,7 @@
999 999
     core-js-pure "^3.16.0"
1000 1000
     regenerator-runtime "^0.13.4"
1001 1001
 
1002
-"@babel/runtime@^7.10.0", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.14.6", "@babel/runtime@^7.14.8", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
1002
+"@babel/runtime@^7.10.0", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.14.6", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
1003 1003
   version "7.15.3"
1004 1004
   resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.15.3.tgz#2e1c2880ca118e5b2f9988322bd8a7656a32502b"
1005 1005
   integrity sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==
@@ -4916,13 +4916,6 @@ gatsby-page-utils@^1.11.0:
4916 4916
     lodash "^4.17.21"
4917 4917
     micromatch "^4.0.2"
4918 4918
 
4919
-gatsby-plugin-layout@^2.12.0:
4920
-  version "2.12.0"
4921
-  resolved "https://registry.yarnpkg.com/gatsby-plugin-layout/-/gatsby-plugin-layout-2.12.0.tgz#8564e6b012287f0108fbfadf4e269a581a570a08"
4922
-  integrity sha512-zBj7JTrAC6ro5GJPA2WxFEc+VMa6P62SnbKsj1fOUo8oVgNSV3I2oX9UMGv+S58nquW0NX/pNjIU8wR4IRwYmw==
4923
-  dependencies:
4924
-    "@babel/runtime" "^7.14.8"
4925
-
4926 4919
 gatsby-plugin-manifest@^3.11.0:
4927 4920
   version "3.11.0"
4928 4921
   resolved "https://registry.yarnpkg.com/gatsby-plugin-manifest/-/gatsby-plugin-manifest-3.11.0.tgz#9dfc08f3573636edb7eba904291da9ca482524f4"

Loading…
Cancel
Save