-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
212 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
"use client"; | ||
|
||
import { useForm } from "react-hook-form"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { z } from "zod"; | ||
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card"; | ||
import CustomFormField from "@/components/common/CustomFormField"; | ||
import { FormFieldType } from "@/types/fromTypes"; | ||
import SubmitButton from "@/components/common/SubmitButton"; | ||
import { useUpdatePassword } from "@/lib/hooks/patient/usePatientAuth"; | ||
import { Form } from "@/components/ui/form"; | ||
import { useAuth } from "@/lib/hooks/useAuth"; | ||
import { notFound, useRouter } from "next/navigation"; | ||
import { toast } from "@/components/ui/use-toast"; | ||
import { useUpdatePasswordDoctor } from "@/lib/hooks/doctor/useDoctorAuth"; | ||
|
||
const formSchema = z | ||
.object({ | ||
newPassword: z | ||
.string() | ||
.trim() | ||
.min(6, "Password must be at least 6 characters long") | ||
.max(25, "Password must be at most 25 characters long") | ||
.regex(/[A-Z]/, "Password must contain at least one uppercase letter") | ||
.regex(/[a-z]/, "Password must contain at least one lowercase letter") | ||
.regex(/[0-9]/, "Password must contain at least one number") | ||
.regex(/[@$!%*?&#]/, "Password must contain at least one special character"), | ||
confirmPassword: z.string(), | ||
}) | ||
.superRefine(({ newPassword, confirmPassword }, ctx) => { | ||
if (newPassword !== confirmPassword) { | ||
ctx.addIssue({ | ||
code: "custom", | ||
message: "The passwords do not match", | ||
path: ["confirmPassword"], | ||
}); | ||
} | ||
}); | ||
|
||
type FormValues = z.infer<typeof formSchema>; | ||
|
||
export default function ResetPasswordPage() { | ||
const form = useForm<FormValues>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
newPassword: "", | ||
confirmPassword: "", | ||
}, | ||
}); | ||
const route = useRouter(); | ||
const { mutate: updatePassword, isPending } = useUpdatePasswordDoctor(); | ||
const { control, handleSubmit } = form; | ||
const { resetMailDoctor, setCredentials } = useAuth(); | ||
const onSubmit = async (values: FormValues) => { | ||
updatePassword( | ||
{ | ||
password: values.newPassword, | ||
email: resetMailDoctor, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
toast({ | ||
title: "Password Updated ✅", | ||
description: "Password Updated Successfully", | ||
}); | ||
route.push("/doctor"); | ||
setTimeout(() => { | ||
setCredentials("resetMailDoctor", ""); | ||
}, 2000); | ||
}, | ||
onError: (error) => { | ||
toast({ | ||
title: "Updating Failed ❌", | ||
description: error.response?.data.message || "Please try again later.", | ||
variant: "destructive", | ||
}); | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
if (resetMailDoctor) { | ||
return ( | ||
<div className="container max-w-md mx-auto mt-48 remove-scrollbar"> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Reset Password</CardTitle> | ||
<CardDescription>Change your account password here.</CardDescription> | ||
</CardHeader> | ||
<Form {...form}> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<CardContent className="space-y-4"> | ||
<CustomFormField | ||
control={control} | ||
fieldType={FormFieldType.PASSWORD} | ||
name="newPassword" | ||
placeholder="Your new password" | ||
label="New Password" | ||
/> | ||
<CustomFormField | ||
control={control} | ||
fieldType={FormFieldType.PASSWORD} | ||
name="confirmPassword" | ||
placeholder="Confirm your new password" | ||
label="Confirm New Password" | ||
/> | ||
</CardContent> | ||
<CardFooter> | ||
<SubmitButton isLoading={isPending} variant={"secondary"}> | ||
Update Password | ||
</SubmitButton> | ||
</CardFooter> | ||
</form> | ||
</Form> | ||
</Card> | ||
</div> | ||
); | ||
}; | ||
|
||
notFound(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,46 +64,48 @@ const AdminSigninForm = () => { | |
}; | ||
|
||
return ( | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="space-y-6 flex-1" | ||
> | ||
<section className="mb-12 space-y-4"> | ||
<h1 className="header">Doctor Signin</h1> | ||
<p className="text-dark-700"> Don't have an account?{" "} | ||
<Link href={'/doctor/signup'} className="text-sky-600">Signup</Link> | ||
</p> | ||
</section> | ||
<> | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="space-y-6 flex-1" | ||
> | ||
<section className="mb-12 space-y-4"> | ||
<h1 className="header">Doctor Signin</h1> | ||
<p className="text-dark-700"> Don't have an account?{" "} | ||
<Link href={'/doctor/signup'} className="text-sky-600">Signup</Link> | ||
</p> | ||
</section> | ||
|
||
<CustomFormField | ||
fieldType={FormFieldType.INPUT} | ||
control={form.control} | ||
name="email" | ||
label="Email address *" | ||
placeholder="[email protected]" | ||
iconSrc={"/assets/icons/email.svg"} | ||
/> | ||
<CustomFormField | ||
fieldType={FormFieldType.INPUT} | ||
control={form.control} | ||
name="email" | ||
label="Email address *" | ||
placeholder="[email protected]" | ||
iconSrc={"/assets/icons/email.svg"} | ||
/> | ||
|
||
<CustomFormField | ||
control={form.control} | ||
fieldType={FormFieldType.PASSWORD} | ||
name="password" | ||
label="Password *" | ||
placeholder="Enter your password" | ||
/> | ||
<p | ||
className="text-dark-700 text-sm mt-2 cursor-pointer" | ||
onClick={() => setForgetPasswordModelOpen(!isForgetPasswordModelOpen)}> | ||
Forget Password? | ||
</p> | ||
<CustomFormField | ||
control={form.control} | ||
fieldType={FormFieldType.PASSWORD} | ||
name="password" | ||
label="Password *" | ||
placeholder="Enter your password" | ||
/> | ||
<p | ||
className="text-dark-700 text-sm mt-2 cursor-pointer" | ||
onClick={() => setForgetPasswordModelOpen(!isForgetPasswordModelOpen)}> | ||
Forget Password? | ||
</p> | ||
|
||
<FormMessage className="shad-error" /> | ||
<FormMessage className="shad-error" /> | ||
|
||
<SubmitButton isLoading={isPending}>Sign In</SubmitButton> | ||
<ForgotPasswordModalDoctor isOpen={isForgetPasswordModelOpen} setIsOpen={setForgetPasswordModelOpen} /> | ||
</form> | ||
</Form> | ||
<SubmitButton isLoading={isPending}>Sign In</SubmitButton> | ||
</form> | ||
</Form> | ||
<ForgotPasswordModalDoctor isOpen={isForgetPasswordModelOpen} setIsOpen={setForgetPasswordModelOpen} /> | ||
</> | ||
); | ||
}; | ||
|
||
|
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.
886c3c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
avm-care – ./
avm-care.vercel.app
avm-care-git-main-sinans-projects-8d312afe.vercel.app
avm-care-sinans-projects-8d312afe.vercel.app