add form errors
This commit is contained in:
@@ -4,6 +4,7 @@ import React, {FormEvent, useState} from "react";
|
||||
import {useNavigate, useParams} from "react-router-dom";
|
||||
import useAuthUser from "../../hooks/AuthUser";
|
||||
import axios from "axios";
|
||||
import useAxiosTools from "../../hooks/AxiosTools";
|
||||
|
||||
const Reset = () => {
|
||||
|
||||
@@ -13,22 +14,26 @@ const Reset = () => {
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [samePassword, setSamePassword] = useState('')
|
||||
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/reset', {email, token, password, samePassword})
|
||||
cleanErrors()
|
||||
await axiosGet('/sanctum/csrf-cookie')
|
||||
const res = await axiosPost('/api/reset', {email, token, password, samePassword})
|
||||
setAuthUser(res.data.user)
|
||||
navigate('/connexion')
|
||||
} 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">Modifier voter mot de passe</h1>
|
||||
|
||||
{errorLabel()}
|
||||
|
||||
<Field type="email"
|
||||
name="email"
|
||||
|
||||
Reference in New Issue
Block a user