import { NextPage } from "next"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; import { useTheme } from "next-themes"; import { Controller, useForm } from "react-hook-form"; // icons import { CircleCheck } from "lucide-react"; // ui import { Button, Input, TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui"; // helpers import { cn } from "@/helpers/common.helper"; import { checkEmailValidity } from "@/helpers/string.helper"; // hooks // import useAuthRedirection from "@/hooks/use-auth-redirection"; import useTimer from "@/hooks/use-timer"; // services import { AuthService } from "@/services/authentication.service"; // images import PlaneBackgroundPatternDark from "public/onboarding/background-pattern-dark.svg"; import PlaneBackgroundPattern from "public/onboarding/background-pattern.svg"; import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png"; type TForgotPasswordFormValues = { email: string; }; const defaultValues: TForgotPasswordFormValues = { email: "", }; // services const authService = new AuthService(); const ForgotPasswordPage: NextPage = () => { // router const router = useRouter(); const { email } = router.query; // hooks const { resolvedTheme } = useTheme(); // timer const { timer: resendTimerCode, setTimer: setResendCodeTimer } = useTimer(0); // form info const { control, formState: { errors, isSubmitting, isValid }, handleSubmit, } = useForm({ defaultValues: { ...defaultValues, email: email?.toString() ?? "", }, }); const handleForgotPassword = async (formData: TForgotPasswordFormValues) => { await authService .sendResetPasswordLink({ email: formData.email, }) .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Email sent", message: "Check your inbox for a link to reset your password. If it doesn't appear within a few minutes, check your spam folder.", }); setResendCodeTimer(30); }) .catch((err: any) => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }); }); }; return (
Plane background pattern
Plane Logo Plane

Reset your password

Enter your user account{"'"}s verified email address and we will send you a password reset link.

checkEmailValidity(value) || "Email is invalid", }} render={({ field: { value, onChange, ref } }) => ( 0} /> )} /> {resendTimerCode > 0 && (

We sent the reset link to your email address

)}
Back to sign in
); }; export default ForgotPasswordPage;