import { ReactElement, useState } from "react"; import Image from "next/image"; import { useRouter } from "next/router"; import { Controller, useForm } from "react-hook-form"; // services import { AuthService } from "services/auth.service"; // hooks import useSignInRedirection from "hooks/use-sign-in-redirection"; import { useEventTracker } from "hooks/store"; // layouts import DefaultLayout from "layouts/default-layout"; // components import { LatestFeatureBlock } from "components/common"; import { PageHead } from "components/core"; // ui import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; // images import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png"; // helpers import { checkEmailValidity } from "helpers/string.helper"; // type import { NextPageWithLayout } from "lib/types"; // icons import { Eye, EyeOff } from "lucide-react"; // constants import { NEW_PASS_CREATED } from "constants/event-tracker"; type TResetPasswordFormValues = { email: string; password: string; }; const defaultValues: TResetPasswordFormValues = { email: "", password: "", }; // services const authService = new AuthService(); const ResetPasswordPage: NextPageWithLayout = () => { // router const router = useRouter(); const { uidb64, token, email } = router.query; // states const [showPassword, setShowPassword] = useState(false); // store hooks const { captureEvent } = useEventTracker(); // sign in redirection hook const { handleRedirection } = useSignInRedirection(); // form info const { control, formState: { errors, isSubmitting, isValid }, handleSubmit, } = useForm({ defaultValues: { ...defaultValues, email: email?.toString() ?? "", }, }); const handleResetPassword = async (formData: TResetPasswordFormValues) => { if (!uidb64 || !token || !email) return; const payload = { new_password: formData.password, }; await authService .resetPassword(uidb64.toString(), token.toString(), payload) .then(() => { captureEvent(NEW_PASS_CREATED, { state: "SUCCESS", }); handleRedirection(); }) .catch((err) => { captureEvent(NEW_PASS_CREATED, { state: "FAILED", }); setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }); }); }; return ( <>
Plane Logo Plane

Let{"'"}s get a new password

checkEmailValidity(value) || "Email is invalid", }} render={({ field: { value, onChange, ref } }) => ( )} /> (
{showPassword ? ( setShowPassword(false)} /> ) : ( setShowPassword(true)} /> )}
)} />
); }; ResetPasswordPage.getLayout = function getLayout(page: ReactElement) { return {page}; }; export default ResetPasswordPage;