diff --git a/src/assets/images/illustration/mail.png b/src/assets/images/illustration/mail.png
new file mode 100644
index 0000000..4d073e8
Binary files /dev/null and b/src/assets/images/illustration/mail.png differ
diff --git a/src/roles/guest/PublicRoutes.jsx b/src/roles/guest/PublicRoutes.jsx
index 3ab5d58..2949fdf 100644
--- a/src/roles/guest/PublicRoutes.jsx
+++ b/src/roles/guest/PublicRoutes.jsx
@@ -10,6 +10,7 @@ import LoginPage from './auth/views/Login';
import RegisterPage from './auth/views/Register';
import ForgotPage from './auth/views/ForgotPass';
import ValidateEmail from './auth/views/ValidateEmail';
+import ResetPass from './auth/views/ResetPass';
function PublicRoutes() {
return(
@@ -24,6 +25,7 @@ function PublicRoutes() {
} />
} />
} />
+ } />
)
diff --git a/src/roles/guest/auth/hooks/useAuth.jsx b/src/roles/guest/auth/hooks/useAuth.jsx
index 930d266..53d9b2e 100644
--- a/src/roles/guest/auth/hooks/useAuth.jsx
+++ b/src/roles/guest/auth/hooks/useAuth.jsx
@@ -48,19 +48,6 @@ const useAuth = () => {
}
};
- const forgotPassword = async (email) => {
- setLoading(true);
- setError(null);
- try {
- await authService.forgotPassword(email);
- // Handle success response (e.g. navigate to success page)
- } catch (err) {
- setError(err.message);
- } finally {
- setLoading(false);
- }
- };
-
const logout = () => {
authService.logout();
setUser(null);
@@ -85,7 +72,6 @@ const useAuth = () => {
error,
login,
register,
- forgotPassword,
logout,
getUserFromToken,
};
diff --git a/src/roles/guest/auth/hooks/useForgot.jsx b/src/roles/guest/auth/hooks/useForgot.jsx
new file mode 100644
index 0000000..8614609
--- /dev/null
+++ b/src/roles/guest/auth/hooks/useForgot.jsx
@@ -0,0 +1,86 @@
+import { useState } from 'react';
+import authService from '../services/authService';
+import { useNavigate } from 'react-router-dom';
+
+const useForgot = () => {
+ const [user, setUser] = useState(null);
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState(null);
+
+ const [pass, setPass] = useState('');
+ const [confirmPass, setConfirmPass] = useState('');
+
+
+ const navigate = useNavigate();
+
+ const [showLoader, setShowLoader] = useState(false);
+ const [modalMessage, setModalMessage] = useState('');
+ const [modalType, setModalType] = useState('');
+
+ const forgotPassword = async () => {
+ setLoading(true);
+ setError(null);
+ const dataForgot = {
+ EMAIL : user
+ }
+ try {
+ await authService.forgotPassword(dataForgot);
+ setLoading(false);
+ setUser('');
+ setModalType("SUCCESS");
+ handleShowLoader("We've sent a link to your email to help you reset your password. Please check your inbox to continue.");
+ } catch (err) {
+ setLoading(false);
+ setModalType("ERROR")
+ handleShowLoader(err.message);
+ }
+ };
+
+ const updatePassword = async (token) => {
+ setLoading(true);
+ setError(null);
+ const dataReset = {
+ TOKEN : token,
+ NEW_PASSWORD: pass,
+ CONFIRM_NEW_PASSWORD: confirmPass
+ }
+ try {
+ await authService.resetPass(dataReset);
+ setLoading(false);
+ setUser('');
+ setModalType("SUCCESS");
+ handleShowLoader("Your password has been successfully reset. Please login with your new password.");
+ } catch (err) {
+ setLoading(false);
+ setModalType("ERROR")
+ handleShowLoader(err.message);
+ }
+ };
+
+ const handleCloseLoader = () => setShowLoader(false);
+ const handleShowLoader = (message) => {
+ setShowLoader(true);
+ setModalMessage(message);
+ };
+
+ return {
+ user,
+ setUser,
+ forgotPassword,
+ loading,
+ error,
+ showLoader,
+ handleShowLoader,
+ handleCloseLoader,
+ modalMessage,
+ modalType,
+
+ pass,
+ setPass,
+ confirmPass,
+ setConfirmPass,
+ updatePassword
+ };
+};
+
+export default useForgot;
diff --git a/src/roles/guest/auth/services/authService.jsx b/src/roles/guest/auth/services/authService.jsx
index 3307f0f..26297f9 100644
--- a/src/roles/guest/auth/services/authService.jsx
+++ b/src/roles/guest/auth/services/authService.jsx
@@ -44,9 +44,18 @@ const register = async (endpoint, data) => {
}
};
-const forgotPassword = async (email) => {
+const forgotPassword = async (EMAIL) => {
try {
- const response = await axios.post(`${API_URL}/forgot-password`, { email });
+ const response = await axios.post(`${API_URL}/forgotPassword`, EMAIL);
+ return response.data;
+ } catch (error) {
+ throw new Error(error.response?.data?.message || 'Password reset failed');
+ }
+};
+
+const resetPass = async (data) => {
+ try {
+ const response = await axios.post(`${API_URL}/resetPassword`, data);
return response.data;
} catch (error) {
throw new Error(error.response?.data?.message || 'Password reset failed');
@@ -72,5 +81,6 @@ export default {
register,
forgotPassword,
logout,
- validateEmail
+ validateEmail,
+ resetPass
};
diff --git a/src/roles/guest/auth/views/ForgotPass.jsx b/src/roles/guest/auth/views/ForgotPass.jsx
index 873f3f7..507d19e 100644
--- a/src/roles/guest/auth/views/ForgotPass.jsx
+++ b/src/roles/guest/auth/views/ForgotPass.jsx
@@ -1,10 +1,28 @@
-import React from 'react';
-import useAuth from '../hooks/useAuth';
-import { Container, Row, Col, Form, Button } from 'react-bootstrap';
+import React, { useState }from 'react';
+import useAuth from '../hooks/useForgot';
+import { Container, Row, Col, Form, Button, Modal } from 'react-bootstrap';
+
import illustration from '../../../../assets/images/illustration/IllustrationForgot.png';
+import successIllustration from '../../../../assets/images/illustration/mail.png';
const ForgotPage = () => {
- const { username, setUsername, password, setPassword, handleLogin, error } = useLogin();
+ const {
+ user,
+ setUser,
+ forgotPassword,
+ loading,
+ error,
+ showLoader,
+ handleShowLoader,
+ handleCloseLoader,
+ modalMessage,
+ modalType
+ } = useAuth();
+
+ const onSubmit = async (e) => {
+ e.preventDefault();
+ await forgotPassword();
+ };
return (
@@ -22,24 +40,43 @@ const ForgotPage = () => {
Enter your email and wait for a link to reset the password.
-
- Email Address *
- setUsername(e.target.value)}
- />
-
-
- {error &&
{error}
}
-
Remember the password? Just Log In
+
+ Email Address *
+ setUser(e.target.value)}
+ />
+
+
+
+ {error &&
{error}
}
+
+
Remember the password? Just Log In
+
+ {modalType === "ERROR"?(
+
+ ERROR!
+
+ {modalMessage}
+
+
+ ):(
+
+ Check Email!
+
+ {modalMessage}
+ Check Email
+
+ )}
+
);
};
diff --git a/src/roles/guest/auth/views/ResetPass.jsx b/src/roles/guest/auth/views/ResetPass.jsx
new file mode 100644
index 0000000..dc21d88
--- /dev/null
+++ b/src/roles/guest/auth/views/ResetPass.jsx
@@ -0,0 +1,91 @@
+import React, { useEffect }from 'react';
+import useAuth from '../hooks/useForgot';
+import { Container, Row, Col, Form, Button, Modal } from 'react-bootstrap';
+import { Link, useParams } from 'react-router-dom';
+
+import illustration from '../../../../assets/images/illustration/changePass.png';
+import successIllustration from '../../../../assets/images/illustration/successModal.png';
+import ask from '../../../../assets/images/illustration/IllustrationForgot.png';
+
+const ResetPass = () => {
+ const { token } = useParams();
+ const {
+ pass,
+ setPass,
+ confirmPass,
+ setConfirmPass,
+
+ updatePassword,
+ loading,
+ showLoader,
+ handleCloseLoader,
+ modalMessage,
+ modalType
+ } = useAuth();
+
+ const onSubmit = async (e) => {
+ e.preventDefault();
+ await updatePassword(token);
+ };
+
+ return (
+
+
+
+
+

+
+
+
+
+
Forgot Password?
+
+ Don’t worry, we will help you...
+ Enter your email and wait for a link to reset the password.
+
+
+
+ New Password *
+ setPass(e.target.value)}
+ />
+
+
+ Confirm New Password *
+ setConfirmPass(e.target.value)}
+ />
+
+
+
+
+
+
+
+
+ {modalType === "ERROR"?(
+
+ ERROR!
+
+ {modalMessage}
+
+
+ ):(
+
+ All Set!
+
+ {modalMessage}
+ Login
+
+ )}
+
+
+ );
+};
+
+export default ResetPass;