first commit
This commit is contained in:
58
resources/js/pages/Auth/Register.tsx
Normal file
58
resources/js/pages/Auth/Register.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import React, {ChangeEvent, FormEvent, SyntheticEvent, useState} from "react"
|
||||
import Field from "../../components/Field";
|
||||
import axios from "axios";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import Card from "../../components/Card";
|
||||
import useAuthUser from "../../hooks/AuthUser";
|
||||
|
||||
const Register = () => {
|
||||
|
||||
const navigate = useNavigate()
|
||||
const {setAuthUser} = useAuthUser()
|
||||
const [name, setName] = useState('')
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
|
||||
const handleSubmit = async (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
try {
|
||||
await axios.get('/sanctum/csrf-cookie')
|
||||
const res = await axios.post('/api/register', {name, email, password})
|
||||
setAuthUser(res.data)
|
||||
navigate('/')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
return <div>
|
||||
<Card className="w-96 mx-auto mt-10 p-2 overflow-hidden">
|
||||
<form onSubmit={handleSubmit}>
|
||||
<h1 className="text-center bg-blue-500 -mx-2 -mt-1 text-lg font-bold px-2 py-1 mb-2">
|
||||
S'inscrire
|
||||
</h1>
|
||||
|
||||
<Field placeholder="Nom"
|
||||
name="name"
|
||||
value={name}
|
||||
onChange={event => setName(event.target.value)}
|
||||
autoFocus>Nom</Field>
|
||||
<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)}
|
||||
autoFocus>Mot de passe</Field>
|
||||
<button type="submit" className="mt-5 btn-primary w-full block text-lg">Valider</button>
|
||||
</form>
|
||||
</Card>
|
||||
</div>
|
||||
}
|
||||
|
||||
export default Register
|
||||
Reference in New Issue
Block a user