Files
ticcat/resources/js/pages/Auth/Reset.tsx
2024-02-10 14:59:46 +01:00

59 lines
2.1 KiB
TypeScript

import Field from "../../components/Field";
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 = () => {
let {token} = useParams()
const navigate = useNavigate()
const {setAuthUser} = useAuthUser()
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 {
cleanErrors()
await axiosGet('/sanctum/csrf-cookie')
const res = await axiosPost('/api/reset', {email, token, password, samePassword})
setAuthUser(res.data.user)
navigate('/connexion')
} catch (e) {
errorCatch(e)
}
}
return <div>
<form onSubmit={handleSubmit} className="w-96 mx-auto mt-10 border shadow p-3">
<h1 className="text-center">Modifier voter mot de passe</h1>
{errorLabel()}
<Field type="email"
name="email"
placeholder="Email"
value={email}
onChange={event => setEmail(event.target.value)}
autoFocus>Email</Field>
<Field type="password"
name="password"
placeholder="******"
value={password}
onChange={event => setPassword(event.target.value)}>Mot de passe</Field>
<Field type="password"
name="same_password"
placeholder="******"
value={samePassword}
onChange={event => setSamePassword(event.target.value)}>Confirmation du mot de passe</Field>
<button type="submit" className="mt-5 btn-primary w-full block text-lg">Valider</button>
</form>
</div>
}
export default Reset