Skip to content

Commit

Permalink
forget password model added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Aug 31, 2024
1 parent aca9ff7 commit ddf6f1d
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 31 deletions.
20 changes: 13 additions & 7 deletions client/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
// import AboutAyurveda from "@/components/(patient)/home/AboutAyurveda";
// import ImageSlider from "@/components/(patient)/home/ImageSlider";
// import WhyUs from "@/components/(patient)/home/WhyUs";
// import AboutAyurveda from "@/components/patient/home/AboutAyurveda";
// import ImageSlider from "@/components/patient/home/ImageSlider";
// import WhyUs from "@/components/patient/home/WhyUs";
// import dynamic from "next/dynamic";
// import Loader from "@/components/common/Loader";

// const FeaturesList = dynamic(()=>import("@/components/(patient)/home/FeatureList"),{
// const FeaturesList = dynamic(()=>import("@/components/patient/home/FeatureList"),{
// loading:()=><Loader />,
// })


const Page = () => {
const HomePage = () => {
return (
<section className="mx-auto ">
{/* <ImageSlider />
<AboutAyurveda />
<WhyUs />
<FeaturesList /> */}
Home Page is not available due to overload 💪💪💪💪
<div className="text-2xl font-bold text-center my-28 mb-64">
🚧 Hold your horses! 🐴
<br />
Iam currently working on some awesome animations and large items.
<br />
Check back soon for a breathtaking experience! 🌟
</div>
</section>
);
};

export default Page;
export default HomePage;
20 changes: 4 additions & 16 deletions client/components/common/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@ interface SubmitButtonProps {
isLoading: boolean;
className?: string;
children: React.ReactNode;
variant?: "default" | "outline" | "link" | "ghost" | "destructive" | "secondary" | null;
}
const SubmitButton = ({
isLoading,
className,
children,
}: SubmitButtonProps) => {
const SubmitButton = ({ isLoading, className, children, variant }: SubmitButtonProps) => {
return (
<Button
type="submit"
disabled={isLoading}
className={className ?? "shad-primary-btn w-full"}
>
<Button type="submit" variant={variant} disabled={isLoading} className={className ?? "shad-primary-btn w-full"}>
{isLoading ? (
<div className="flex items-center gap-4">
<Image
src="/assets/icons/loader.svg"
alt="loader"
width={27}
height={27}
/>
<Image src="/assets/icons/loader.svg" alt="loader" width={27} height={27} />
</div>
) : (
children
Expand Down
14 changes: 6 additions & 8 deletions client/components/forms/patient/SigninForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import { useToast } from "@/components/ui/use-toast";
import { useRouter } from "next/navigation";
import { useSignInPatient } from "@/lib/hooks/usePatientAuth";
import { useAuth } from "@/lib/hooks/useAuth";
import { Button } from "@/components/ui/button";
import ForgetPasswordModel from "@/components/models/ForgetPasswordModel";

const LoginForm = () => {
const [error, setError] = useState("");
const { toast } = useToast();
const router = useRouter();
const { mutate: signIn, isPending } = useSignInPatient();
const { setCredentials } = useAuth();
const [isForgetPasswordOpen, setIsForgetPasswordOpen] = useState(false);

const form = useForm<z.infer<typeof signinFormValidation>>({
resolver: zodResolver(signinFormValidation),
Expand Down Expand Up @@ -56,10 +57,6 @@ const LoginForm = () => {
);
};

const handleForgetPassword = ()=>{

}

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6 flex-1">
Expand Down Expand Up @@ -91,14 +88,15 @@ const LoginForm = () => {
/>

{error && <p className="text-red-500 text-sm mt-2">{error}</p>}
<p className="text-dark-700 text-sm mt-2 cursor-pointer" onClick={handleForgetPassword}>
<p
className="text-dark-700 text-sm mt-2 cursor-pointer"
onClick={() => setIsForgetPasswordOpen(!isForgetPasswordOpen)}>
Forget Password?
</p>

<SubmitButton isLoading={isPending}>Sign In</SubmitButton>


</form>
<ForgetPasswordModel isOpen={isForgetPasswordOpen} setIsOpen={setIsForgetPasswordOpen} />
</Form>
);
};
Expand Down
90 changes: 90 additions & 0 deletions client/components/models/ForgetPasswordModel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Dispatch, SetStateAction } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import {
AlertDialog,
AlertDialogTitle,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogCancel,
AlertDialogAction,
AlertDialogHeader,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { Form } from "@/components/ui/form";
import SubmitButton from "../common/SubmitButton";
import CustomFormField from "../common/CustomFormField";
import { FormFieldType } from "@/types/fromTypes";

type Props = {
isOpen: boolean;
setIsOpen: Dispatch<SetStateAction<boolean>>;
};

const formSchema = z.object({
email: z.string().email("Please enter a valid email address."),
});

type FormValues = z.infer<typeof formSchema>;

const ForgotPasswordModal = ({ isOpen, setIsOpen }: Props) => {
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
email: "",
},
});

const { control, handleSubmit, formState: { isSubmitting } } = form;

const onSubmit = async (data: FormValues) => {
try {
await new Promise(resolve => setTimeout(resolve, 2000));
console.log("Password reset email sent to:", data.email);
setIsOpen(false);
} catch (error) {
console.error("Error sending password reset email:", error);
}
};

return (
<AlertDialog open={isOpen} onOpenChange={setIsOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Forgot Password</AlertDialogTitle>
<AlertDialogDescription>
Enter your email address and we'll send you instructions to reset your password.
</AlertDialogDescription>
</AlertDialogHeader>
<Form {...form}>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<CustomFormField
fieldType={FormFieldType.INPUT}
control={control}
name="email"
label="Email Address *"
placeholder="[email protected]"
iconSrc="/assets/icons/email.svg"
/>
<AlertDialogFooter className="mt-6">
<AlertDialogCancel asChild>
<Button variant="ghost" onClick={() => setIsOpen(false)}>
Cancel
</Button>
</AlertDialogCancel>
<AlertDialogAction asChild>
<SubmitButton isLoading={isSubmitting} variant="outline" className="bg-slate-500 bg-opacity-40" >
Send Reset Instructions
</SubmitButton>
</AlertDialogAction>
</AlertDialogFooter>
</form>
</Form>
</AlertDialogContent>
</AlertDialog>
);
};

export default ForgotPasswordModal;

0 comments on commit ddf6f1d

Please sign in to comment.