-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Fingertips18/development
Create forgot password form.
- Loading branch information
Showing
20 changed files
with
190 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
client/src/pages/forgot-password/_components/forgot-password-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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 { 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<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
|
||
const formData = new FormData(e.currentTarget); | ||
|
||
const forgotPasswordData = Object.fromEntries(formData.entries()); | ||
|
||
mutate(forgotPasswordData["email"] as string); | ||
}; | ||
|
||
return ( | ||
<form | ||
onSubmit={onSubmit} | ||
className="p-4 lg:p-6 w-full md:w-fit rounded-md border border-primary/50 bg-primary/15 drop-shadow-2xl space-y-4 lg:space-y-6" | ||
> | ||
<Input | ||
required | ||
name="email" | ||
label="Email Address" | ||
tooltip="Please enter a valid email address. Ensure it includes an '@' symbol and a domain name." | ||
placeholder="e.g. [email protected]" | ||
type="email" | ||
autoComplete="email" | ||
suffixIcon={Mail} | ||
disabled={isPending} | ||
validation={ValidateEmail} | ||
maxLength={320} | ||
/> | ||
|
||
<Button | ||
label="Send Reset Link" | ||
disabled={isPending} | ||
loading={isPending} | ||
type="submit" | ||
/> | ||
</form> | ||
); | ||
}; | ||
|
||
export { ForgotPasswordForm }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SwitchAuth } from "@/components/switch-auth"; | ||
import { ForgotPasswordForm } from "./_components/forgot-password-form"; | ||
import { AppRoutes } from "@/constants/routes"; | ||
|
||
const ForgotPasswordPage = () => { | ||
return ( | ||
<section className="px-4 lg:px-0 h-full flex-center flex-col gap-y-6 w-fit mx-auto"> | ||
<div className="w-full rounded-md border border-primary/50 bg-primary/15 drop-shadow-2xl"> | ||
<h2 className="text-lg lg:text-2xl font-extrabold text-center uppercase pt-4 pb-2"> | ||
Forgot Password | ||
</h2> | ||
<div className="w-full bg-primary/25 p-2.5 flex-center border-t border-primary/50"> | ||
<p className="text-xs lg:text-base text-center lg:max-w-[324px] text-foreground/60 font-medium"> | ||
Enter your email address and wait for a reset password link to be | ||
sent. | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<ForgotPasswordForm /> | ||
|
||
<SwitchAuth href={AppRoutes.Root} tag="Back" /> | ||
</section> | ||
); | ||
}; | ||
|
||
export { ForgotPasswordPage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.