import { useMemo, useState } from "react" import { Link, useNavigate, useSearchParams } from "react-router-dom" import { ArrowLeft, Eye, EyeOff } from "lucide-react" import { toast } from "sonner" import { resetTeamPassword } from "../../api/team.api" import { BrandLogo } from "../../components/brand/BrandLogo" import { Button } from "../../components/ui/button" import { Input } from "../../components/ui/input" import { SpinnerIcon } from "../../components/ui/spinner-icon" import { mapTeamPasswordResetError } from "../../lib/teamPasswordReset" export function ResetPasswordPage() { const navigate = useNavigate() const [searchParams] = useSearchParams() const emailFromQuery = searchParams.get("email")?.trim() ?? "" const otpFromQuery = searchParams.get("otp")?.trim() ?? "" const [email, setEmail] = useState(emailFromQuery) const [otp, setOtp] = useState(otpFromQuery) const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [showPassword, setShowPassword] = useState(false) const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) const hasLinkParams = Boolean(emailFromQuery && otpFromQuery) const emailLocked = Boolean(emailFromQuery) const otpLocked = Boolean(otpFromQuery) const canSubmit = useMemo(() => { return email.trim().length > 0 && otp.trim().length > 0 && password.length >= 8 }, [email, otp, password]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) if (!email.trim() || !otp.trim()) { setError("Email and reset code are required. Open the link from your email or request a new one.") return } if (password.length < 8) { setError("Password must be at least 8 characters.") return } if (password !== confirmPassword) { setError("Passwords do not match.") return } setSubmitting(true) try { await resetTeamPassword({ email: email.trim(), otp: otp.trim(), password, }) toast.success("Password reset successfully", { description: "Sign in with your new password.", }) navigate("/login?reset=1", { replace: true }) } catch (err) { setError(mapTeamPasswordResetError(err)) } finally { setSubmitting(false) } } return (

Choose a strong password to secure your admin account.

Back to sign in

Account Recovery

Reset password

{hasLinkParams ? "Set a new password for your team account. This link expires in 5 minutes." : "Enter the email and code from your reset email, then choose a new password."}

{!hasLinkParams ? (
Missing reset link details. You can enter them manually, or{" "} request a new link .
) : null}
setEmail(e.target.value)} readOnly={emailLocked} required autoComplete="email" disabled={submitting} className="h-11 rounded-xl" />
setOtp(e.target.value)} readOnly={otpLocked} required autoComplete="one-time-code" disabled={submitting} className="h-11 rounded-xl" />
setPassword(e.target.value)} required minLength={8} autoComplete="new-password" disabled={submitting} className="h-11 rounded-xl pr-11" />

At least 8 characters

setConfirmPassword(e.target.value)} required minLength={8} autoComplete="new-password" disabled={submitting} className="h-11 rounded-xl" />
{error ? (

{error}

{(error.toLowerCase().includes("expired") || error.toLowerCase().includes("already used") || error.toLowerCase().includes("invalid reset")) && ( Request a new reset link )}
) : null}

© {new Date().getFullYear()} Yimaru Academy · All rights reserved

) }