import { Alert, Box, Button, CircularProgress, TextField, Typography, } from "@mui/material"; import React from "react"; import { useLocation } from "react-router-dom"; import { AuthApi, CheckResetTokenResponse } from "../../api/AuthApi"; import { ServerApi } from "../../api/ServerApi"; import { AsyncWidget } from "../../widgets/AsyncWidget"; import { AuthSingleMessage } from "../../widgets/AuthSingleMessage"; import { PasswordInput } from "../../widgets/PasswordInput"; export function ResetPasswordRoute(): React.ReactElement { const [error, setError] = React.useState(null); const [loading, setLoading] = React.useState(false); const [success, setSuccess] = React.useState(false); const [password, setPassword] = React.useState(""); const [confirmPassword, setConfirmPassword] = React.useState(""); const { hash } = useLocation(); const token = hash.substring(1); const [info, setInfo] = React.useState(null); const canSubmit = ServerApi.CheckPassword(password) === null && password === confirmPassword; const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!canSubmit) return; setLoading(true); try { await AuthApi.ResetPassword(token, password); setSuccess(true); } catch (e) { console.error(e); setError("Echec de la réinitialisation du mot de passe !"); } setLoading(false); }; if (loading) return ( <> ); if (success) return ( ); return ( setInfo(await AuthApi.CheckResetPasswordToken(token))} errMsg="Echec de validation du jeton de réinitialisation de mot de passe !" build={() => ( <> {error && ( {error} )} Bonjour {info!.name}, veuillez définir votre nouveau mot de passe : { setPassword(n); }} /> setConfirmPassword(e.target.value)} label="Confirmer le mot de passe" type="password" id="password" autoComplete="current-password" /> )} /> ); }