add form errors
This commit is contained in:
@@ -3,29 +3,34 @@ import Field from "../../components/Field";
|
||||
import axios from "axios";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import useAuthUser from "../../hooks/AuthUser";
|
||||
import useAxiosTools from "../../hooks/AxiosTools";
|
||||
|
||||
const ForgotPassword = () => {
|
||||
|
||||
const [email, setEmail] = useState('')
|
||||
const [message, setMessage] = useState(false)
|
||||
const {errorCatch, errorLabel, cleanErrors, axiosGet, axiosPost} = useAxiosTools()
|
||||
|
||||
const handleSubmit = async (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
try {
|
||||
await axios.get('/sanctum/csrf-cookie')
|
||||
const res = await axios.post('/api/forgot', {email})
|
||||
cleanErrors()
|
||||
await axiosGet('/sanctum/csrf-cookie')
|
||||
const res = await axiosPost('/api/forgot', {email})
|
||||
setMessage(true)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
errorCatch(e)
|
||||
}
|
||||
}
|
||||
|
||||
return <div>
|
||||
<form onSubmit={handleSubmit} className="w-96 mx-auto mt-10 border shadow p-3">
|
||||
<h1 className="text-center">Connexion</h1>
|
||||
<h1 className="text-center">Mot de passe oublié</h1>
|
||||
|
||||
{message && <p className="bg-green-600">Un email vous a été envoyer pour modifier le mot de passe.</p>}
|
||||
|
||||
{errorLabel()}
|
||||
|
||||
<Field type="email"
|
||||
name="email"
|
||||
placeholder="Email"
|
||||
|
||||
Reference in New Issue
Block a user