import React, { useEffect, useState } from "react"; import { Alert, Box, Button, Paper, TextField, Typography } from "@mui/material"; import { useNavigate } from "react-router-dom"; import { api } from "../api"; import { useToast } from "../toast"; import { useI18n } from "../i18n/I18nProvider"; export default function ResetPasswordPage() { const { toast } = useToast(); const { t } = useI18n(); const navigate = useNavigate(); const [email, setEmail] = useState(""); const [token, setToken] = useState(""); const [newPassword, setNewPassword] = useState(""); const [loading, setLoading] = useState(false); useEffect(() => { const params = new URLSearchParams(window.location.search); setEmail(params.get("email") || ""); setToken(params.get("token") || ""); }, []); const missingResetInfo = !email || !token; return ( {t("resetPasswordTitle")} {t("resetPasswordBody")} { e.preventDefault(); if (missingResetInfo) { toast(t("missingResetLinkInfo"), "error"); return; } setLoading(true); api .post("/auth/reset-password", { email, token, newPassword }) .then(() => { toast(t("passwordResetSuccess"), "success"); navigate("/login", { replace: true }); }) .catch((e2: any) => { const msg = e2?.response?.data || e2?.message || t("resetFailed"); toast(String(msg), "error"); }) .finally(() => setLoading(false)); }} sx={{ display: "flex", flexDirection: "column", gap: 1.5 }} > {missingResetInfo ? {t("missingResetLinkInfo")} : null} setEmail(e.target.value)} disabled={!missingResetInfo} fullWidth /> setNewPassword(e.target.value)} fullWidth /> ); }