import { zodResolver } from "@hookform/resolvers/zod"; import { t, Trans } from "@lingui/macro"; import { resetPasswordSchema } from "@reactive-resume/dto"; import { usePasswordToggle } from "@reactive-resume/hooks"; import { Button, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Input, } from "@reactive-resume/ui"; import { useEffect, useRef } from "react"; import { Helmet } from "react-helmet-async"; import { useForm } from "react-hook-form"; import { useNavigate, useSearchParams } from "react-router"; import type { z } from "zod"; import { useResetPassword } from "@/client/services/auth"; type FormValues = z.infer; export const ResetPasswordPage = () => { const navigate = useNavigate(); const [searchParams] = useSearchParams(); const token = searchParams.get("token") ?? ""; const { resetPassword, loading } = useResetPassword(); const formRef = useRef(null); usePasswordToggle(formRef); const form = useForm({ resolver: zodResolver(resetPasswordSchema), defaultValues: { token, password: "" }, }); const onSubmit = async (data: FormValues) => { try { await resetPassword(data); void navigate("/auth/login"); } catch { form.reset(); } }; // Redirect the user to the forgot password page if the token is not present. useEffect(() => { if (!token) void navigate("/auth/forgot-password"); }, [token, navigate]); return (
{t`Reset your password`} - {t`Reactive Resume`}

{t`Reset your password`}

{t`Enter a new password below, and make sure it's secure.`}
( {t`Password`} Hold Ctrl to display your password temporarily. )} />
); };