import { ReactElement, useEffect, useMemo, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; // icons import { useTheme } from "next-themes"; import { Eye, EyeOff } from "lucide-react"; // ui import { Button, Input } from "@plane/ui"; // components import { AuthBanner, PasswordStrengthMeter } from "@/components/account"; import { PageHead } from "@/components/core"; // helpers import { EAuthenticationErrorCodes, EErrorAlertType, EPageTypes, TAuthErrorInfo, authErrorHandler, } from "@/helpers/authentication.helper"; import { API_BASE_URL } from "@/helpers/common.helper"; import { getPasswordStrength } from "@/helpers/password.helper"; // layouts import DefaultLayout from "@/layouts/default-layout"; // lib import { NextPageWithLayout } from "@/lib/types"; // wrappers import { AuthenticationWrapper } from "@/lib/wrappers"; // services import { AuthService } from "@/services/auth.service"; // images import PlaneBackgroundPatternDark from "public/auth/background-pattern-dark.svg"; import PlaneBackgroundPattern from "public/auth/background-pattern.svg"; import BlackHorizontalLogo from "public/plane-logos/black-horizontal-with-blue-logo.png"; import WhiteHorizontalLogo from "public/plane-logos/white-horizontal-with-blue-logo.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, error_code } = router.query; // states const [showPassword, setShowPassword] = useState({ password: false, retypePassword: false, }); const [resetFormData, setResetFormData] = useState({ ...defaultValues, email: email ? email.toString() : "", }); const [csrfToken, setCsrfToken] = useState(undefined); const [isPasswordInputFocused, setIsPasswordInputFocused] = useState(false); const [isRetryPasswordInputFocused, setIsRetryPasswordInputFocused] = useState(false); const [errorInfo, setErrorInfo] = useState(undefined); // hooks const { resolvedTheme } = useTheme(); const handleShowPassword = (key: keyof typeof showPassword) => setShowPassword((prev) => ({ ...prev, [key]: !prev[key] })); 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] ); useEffect(() => { if (error_code) { const errorhandler = authErrorHandler(error_code?.toString() as EAuthenticationErrorCodes); if (errorhandler) { setErrorInfo(errorhandler); } } }, [error_code]); const password = resetFormData?.password ?? ""; const confirmPassword = resetFormData?.confirm_password ?? ""; const renderPasswordMatchError = !isRetryPasswordInputFocused || confirmPassword.length >= password.length; const logo = resolvedTheme === "light" ? BlackHorizontalLogo : WhiteHorizontalLogo; return (
Plane background pattern
Plane logo

Set new password

Secure your account with a strong password

{errorInfo && errorInfo?.type === EErrorAlertType.BANNER_ALERT && ( setErrorInfo(value)} /> )}
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.password ? ( handleShowPassword("password")} /> ) : ( handleShowPassword("password")} /> )}
{isPasswordInputFocused && }
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" onFocus={() => setIsRetryPasswordInputFocused(true)} onBlur={() => setIsRetryPasswordInputFocused(false)} /> {showPassword.retypePassword ? ( handleShowPassword("retypePassword")} /> ) : ( handleShowPassword("retypePassword")} /> )}
{!!resetFormData.confirm_password && resetFormData.password !== resetFormData.confirm_password && renderPasswordMatchError && Passwords don{"'"}t match}
); }; ResetPasswordPage.getLayout = function getLayout(page: ReactElement) { return ( {page} ); }; export default ResetPasswordPage;