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 = () => {