add form errors

This commit is contained in:
Romulus21
2023-09-17 10:01:31 +02:00
parent 1e39c1b79f
commit 9b7a11dbd0
7 changed files with 87 additions and 14 deletions

View File

@@ -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"