From d1427010c26e6c72d8c89016582512c932718e8c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 11 Jun 2024 12:58:21 -0700 Subject: [PATCH 01/11] Added validation for eamil field in forgot-password page. Make axios request to backend --- Client/src/Pages/ForgotPassword/index.jsx | 49 ++++++++++++++++++++++- Client/src/Pages/Register/index.jsx | 1 - Client/src/Validation/validation.js | 13 +++++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/ForgotPassword/index.jsx b/Client/src/Pages/ForgotPassword/index.jsx index b94546251..d5ec84088 100644 --- a/Client/src/Pages/ForgotPassword/index.jsx +++ b/Client/src/Pages/ForgotPassword/index.jsx @@ -5,8 +5,52 @@ import Logomark from "../../assets/Images/key-password.png"; import EmailTextField from "../../Components/TextFields/Email/EmailTextField"; import Button from "../../Components/Button"; import LeftArrow from "../../assets/Images/arrow-left.png"; +import { useState, useEffect } from "react"; +import { recoveryValidation } from "../../Validation/validation"; +import axios from "axios"; + +const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL; const ForgotPassword = () => { + const [errors, setErrors] = useState({}); + const [form, setForm] = useState({ + email: "", + }); + + const idMap = { + "forgot-password-email-input": "email", + }; + + useEffect(() => { + const { error } = recoveryValidation.validate(form); + if (error === undefined) { + setErrors({}); + } else { + const validationErrors = error.details.reduce((acc, err) => { + return { ...acc, [err.path[0]]: err.message }; + }, {}); + setErrors(validationErrors); + } + }, [form]); + + const handleInput = (e) => { + const fieldName = idMap[e.target.id]; + setForm({ ...form, [fieldName]: e.target.value }); + }; + + const handleSubmit = async () => { + const { error } = recoveryValidation.validate(form); + if (error === undefined) { + try { + const res = await axios.post(`${BASE_URL}/auth/recovery/request`, form); + console.log(res); + } catch (error) { + console.log(error); + } + } else { + alert(error); + } + }; return (
@@ -27,12 +71,15 @@ const ForgotPassword = () => {
-
+ ); }; diff --git a/Client/src/Pages/Register/index.jsx b/Client/src/Pages/Register/index.jsx index 70181e194..5f8622e8b 100644 --- a/Client/src/Pages/Register/index.jsx +++ b/Client/src/Pages/Register/index.jsx @@ -59,7 +59,8 @@ const Register = () => { setForm(newForm); }; - const handleSubmit = async () => { + const handleSubmit = async (e) => { + e.preventDefault(); try { await registerValidation.validateAsync(form, { abortEarly: false }); const action = await dispatch(register(form)); @@ -94,82 +95,80 @@ const Register = () => { return (
-
-
-
- Logomark -
-
Create an account
-
-
-
-
- -
- -
- -
- -
-
-
- -
- -
-
-
-
+ +
+ Logomark +
+
Create an account
+
+
+
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+
-
+
); }; From 7d0fa0fe17eb89fed094ff8458215b5c23cb6457 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 12 Jun 2024 13:51:28 -0700 Subject: [PATCH 11/11] Added autocomplete attribute --- Client/src/Pages/Login/index.jsx | 2 +- Client/src/Pages/Register/index.jsx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Client/src/Pages/Login/index.jsx b/Client/src/Pages/Login/index.jsx index 1bf2ad9c9..c67f67ec1 100644 --- a/Client/src/Pages/Login/index.jsx +++ b/Client/src/Pages/Login/index.jsx @@ -102,7 +102,7 @@ const Login = () => { error={errors.email ? true : false} helperText={errors.email ? errors.email : ""} placeholder="Enter your email" - autoComplete="username" + autoComplete="email" id="login-email-input" />
diff --git a/Client/src/Pages/Register/index.jsx b/Client/src/Pages/Register/index.jsx index 5f8622e8b..5d08e0c0d 100644 --- a/Client/src/Pages/Register/index.jsx +++ b/Client/src/Pages/Register/index.jsx @@ -132,6 +132,7 @@ const Register = () => { error={errors.email ? true : false} helperText={errors.email ? errors.email : ""} placeholder="Enter your email" + autoComplete="email" id="register-email-input" />
@@ -141,6 +142,7 @@ const Register = () => { error={errors.password ? true : false} helperText={errors.password ? errors.password : ""} placeholder="Create a password" + autoComplete="current-password" id="register-password-input" />