From 25e2804081a4565fb56b1b6dcd0ef296b6f44be7 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Lamontagne Date: Tue, 1 Nov 2022 11:24:21 -0400 Subject: [PATCH] validation contact --- .../grosses-mitaines-ui/package-lock.json | 22 ++++++ .../grosses-mitaines-ui/package.json | 1 + .../src/pages/ContactUs.js | 73 +++++++++++++++---- .../grosses-mitaines-ui/src/pages/Login.js | 2 +- .../src/stylesheets/site.css | 9 +++ 5 files changed, 92 insertions(+), 15 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/package-lock.json b/GrossesMitaines/grosses-mitaines-ui/package-lock.json index e5682f0..561588e 100644 --- a/GrossesMitaines/grosses-mitaines-ui/package-lock.json +++ b/GrossesMitaines/grosses-mitaines-ui/package-lock.json @@ -25,6 +25,7 @@ "react-devtools": "^4.26.0", "react-dom": "^18.2.0", "react-fontawesome": "^1.7.1", + "react-hook-form": "^7.38.0", "react-icons": "^4.6.0", "react-router-dom": "^6.4.1", "react-scripts": "^5.0.1", @@ -15344,6 +15345,21 @@ "react": ">=0.12.0" } }, + "node_modules/react-hook-form": { + "version": "7.38.0", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.38.0.tgz", + "integrity": "sha512-gxWW1kMeru9xR1GoR+Iw4hA+JBOM3SHfr4DWCUKY0xc7Vv1MLsF109oHtBeWl9shcyPFx67KHru44DheN0XY5A==", + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/react-hook-form" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/react-icons": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.6.0.tgz", @@ -29471,6 +29487,12 @@ "prop-types": "^15.5.6" } }, + "react-hook-form": { + "version": "7.38.0", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.38.0.tgz", + "integrity": "sha512-gxWW1kMeru9xR1GoR+Iw4hA+JBOM3SHfr4DWCUKY0xc7Vv1MLsF109oHtBeWl9shcyPFx67KHru44DheN0XY5A==", + "requires": {} + }, "react-icons": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.6.0.tgz", diff --git a/GrossesMitaines/grosses-mitaines-ui/package.json b/GrossesMitaines/grosses-mitaines-ui/package.json index fb6e146..0421fe3 100644 --- a/GrossesMitaines/grosses-mitaines-ui/package.json +++ b/GrossesMitaines/grosses-mitaines-ui/package.json @@ -20,6 +20,7 @@ "react-devtools": "^4.26.0", "react-dom": "^18.2.0", "react-fontawesome": "^1.7.1", + "react-hook-form": "^7.38.0", "react-icons": "^4.6.0", "react-router-dom": "^6.4.1", "react-scripts": "^5.0.1", diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/ContactUs.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/ContactUs.js index 663a9ea..8e27e98 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/ContactUs.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/ContactUs.js @@ -1,18 +1,63 @@ -import React from "react"; -import { useEffect } from "react"; -import ContactForm from "../components/ContactForm"; +import { useForm } from "react-hook-form"; -const ContactUs = () => { +export default function App() { + const { register, handleSubmit, watch, formState: { errors } } = useForm(); + const onSubmit = data => console.log(data); - useEffect(() => { - document.title = 'Nous contacter'; - }); + return ( + /* "handleSubmit" will validate your inputs before invoking "onSubmit" */ +
+
+

Contacter-nous!

+
+
+
+ +
+ {/* include validation with required or other standard HTML validation rules */} + + {/* errors will return when field validation fails */} +
+ {errors.Nom && errors.Nom.type === 'required' && Vous devez entrer votre nom!} + {errors.Nom && errors.Nom.type === 'minLength' && Votre nom doit avoir au moins 2 lettres!} +
+
- return ( -
- -
- ); -} +
+
+ +
+ +
+ {errors.Email && errors.Email.type === 'required' && Vous devez entrer une adresse!} + {errors.Email && errors.Email.type === 'pattern' && Adresse non valide!} +
+
-export default ContactUs; \ No newline at end of file +
+
+ +
+ +
+ {errors.Téléphone && errors.Téléphone.type === 'required' && Vous devez entrer un numéro de téléphone!} + {errors.Téléphone && errors.Téléphone.type === 'pattern' && Téléphone non valide!} +
+
+ +
+
+ +
+