diff --git a/client/src/App.tsx b/client/src/App.tsx
index 5a15f5e..386f2b1 100644
--- a/client/src/App.tsx
+++ b/client/src/App.tsx
@@ -1,5 +1,6 @@
import { Route, Routes } from "react-router-dom";
+import { ForgotPasswordPage } from "@/pages/forgot-password/page";
import VerifyEmailPage from "@/pages/verify-email/page";
import PrivateGuard from "@/guards/private-guard";
import { AppRoutes } from "@/constants/routes";
@@ -20,6 +21,10 @@ function App() {
Or
diff --git a/client/src/components/switch-auth.tsx b/client/src/components/switch-auth.tsx index 55fae3a..d11af44 100644 --- a/client/src/components/switch-auth.tsx +++ b/client/src/components/switch-auth.tsx @@ -1,15 +1,18 @@ import { Link } from "react-router-dom"; interface SwitchAuthProps { - label: string; + label?: string; tag: string; href: string; } const SwitchAuth = ({ label, tag, href }: SwitchAuthProps) => { return ( -{label}
+{label}
} { + const res = await fetch(`${baseURL}${AppRoutes.ForgotPassword}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(email), + }); + + const data = await res.json(); + + if (!res.ok) { + throw new ErrorResponse({ + status: res.status, + message: data.error, + }); + } + + return new GenericResponse({ + message: data.message, + }); + }, }; diff --git a/client/src/pages/forgot-password/_components/forgot-password-form.tsx b/client/src/pages/forgot-password/_components/forgot-password-form.tsx new file mode 100644 index 0000000..96161fa --- /dev/null +++ b/client/src/pages/forgot-password/_components/forgot-password-form.tsx @@ -0,0 +1,70 @@ +import { useMutation } from "@tanstack/react-query"; +import { useNavigate } from "react-router-dom"; +import { Mail } from "lucide-react"; +import { FormEvent } from "react"; +import { toast } from "sonner"; + +import { GenericResponse } from "@/lib/classes/generic-response-class"; +import { ErrorResponse } from "@/lib/classes/error-response-class"; +import { ForgotPasswordDTO } from "@/lib/DTO/forgot-password-dto"; +import { AuthService } from "@/lib/services/auth-service"; +import { ValidateEmail } from "@/lib/utils/validations"; +import { FORGOTPASSWORDKEY } from "@/constants/keys"; +import { Button } from "@/components/text-button"; +import { AppRoutes } from "@/constants/routes"; +import { Input } from "@/components/input"; + +const ForgotPasswordForm = () => { + const navigate = useNavigate(); + + const { mutate, isPending } = useMutation({ + mutationKey: [FORGOTPASSWORDKEY], + mutationFn: AuthService.forgotPassword, + onSuccess: (res: GenericResponse) => { + toast.success(res.message); + navigate(AppRoutes.ResetPassword); + }, + onError: (error: ErrorResponse) => toast.error(error.message), + }); + + const onSubmit = (e: FormEvent+ Enter your email address and wait for a reset password link to be + sent. +
+