import { ReactElement, useEffect, useMemo, useState } from "react"; import Image from "next/image"; import { useRouter } from "next/router"; // icons import { useTheme } from "next-themes"; import { Eye, EyeOff } from "lucide-react"; // ui import { Button, Input, Spinner } from "@plane/ui"; // components import { PasswordStrengthMeter } from "@/components/account"; import { PageHead } from "@/components/core"; // helpers import { API_BASE_URL } from "@/helpers/common.helper"; import { getPasswordStrength } from "@/helpers/password.helper"; // hooks import useAuthRedirection from "@/hooks/use-auth-redirection"; // layouts import DefaultLayout from "@/layouts/default-layout"; // lib import { NextPageWithLayout } from "@/lib/types"; // services import { AuthService } from "@/services/auth.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 TResetPasswordFormValues = { email: string; password: string; confirm_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); const [resetFormData, setResetFormData] = useState({ ...defaultValues, email: email ? email.toString() : "", }); const [csrfToken, setCsrfToken] = useState(undefined); const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false); // hooks const { resolvedTheme } = useTheme(); // store hooks //const { captureEvent } = useEventTracker(); // sign in redirection hook const { isRedirecting, handleRedirection } = useAuthRedirection(); useEffect(() => { handleRedirection(); }, [handleRedirection]); const handleFormChange = (key: keyof TResetPasswordFormValues, value: string) => setResetFormData((prev) => ({ ...prev, [key]: value })); useEffect(() => { if (csrfToken === undefined) authService.requestCSRFToken().then((data) => data?.csrf_token && setCsrfToken(data.csrf_token)); }, [csrfToken]); const isButtonDisabled = useMemo( () => !!resetFormData.password && getPasswordStrength(resetFormData.password) >= 3 && resetFormData.password === resetFormData.confirm_password ? false : true, [resetFormData] ); if (isRedirecting) return (
); return (
Plane background pattern
Plane Logo Plane

Set new password

Secure your account with a strong password

handleFormChange("password", e.target.value)} //hasError={Boolean(errors.password)} placeholder="Enter password" className="h-[46px] w-full border border-onboarding-border-100 !bg-onboarding-background-200 pr-12 placeholder:text-onboarding-text-400" minLength={8} onFocus={() => setIsPasswordInputFocused(true)} onBlur={() => setIsPasswordInputFocused(false)} autoFocus /> {showPassword ? ( setShowPassword(false)} /> ) : ( setShowPassword(true)} /> )}
{isPasswordInputFocused && }
{getPasswordStrength(resetFormData.password) >= 3 && (
handleFormChange("confirm_password", e.target.value)} placeholder="Confirm password" className="h-[46px] w-full border border-onboarding-border-100 !bg-onboarding-background-200 pr-12 placeholder:text-onboarding-text-400" /> {showPassword ? ( setShowPassword(false)} /> ) : ( setShowPassword(true)} /> )}
{!!resetFormData.confirm_password && resetFormData.password !== resetFormData.confirm_password && ( Password doesn{"'"}t match )}
)}
); }; ResetPasswordPage.getLayout = function getLayout(page: ReactElement) { return {page}; }; export default ResetPasswordPage;