2020-03-25 18:22:03 +01:00
|
|
|
import { Fragment, useState } from 'react';
|
|
|
|
import htmlParser from 'html-react-parser';
|
2020-04-23 17:45:21 +02:00
|
|
|
import Loader from '../../components/Loader';
|
|
|
|
import HeadTag from '../../components/HeadTag';
|
|
|
|
import api from '../../utils/api';
|
|
|
|
import withoutAuth from '../../hoc/withoutAuth';
|
|
|
|
import '../../public/css/pages/register-login.css';
|
2020-03-25 18:22:03 +01:00
|
|
|
|
|
|
|
const Register = () => {
|
|
|
|
|
2020-04-22 20:44:06 +02:00
|
|
|
const [inputState, setInputState] = useState({ name: "", email: "", password: "" });
|
2020-03-25 18:22:03 +01:00
|
|
|
const [message, setMessage] = useState("");
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
2020-04-08 00:47:24 +02:00
|
|
|
const handleChange = (event) => {
|
2020-03-25 18:22:03 +01:00
|
|
|
const inputStateNew = { ...inputState };
|
|
|
|
inputStateNew[event.target.name] = event.target.value;
|
|
|
|
setInputState(inputStateNew);
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleSubmit = (event) => {
|
2020-03-25 18:46:23 +01:00
|
|
|
setIsLoading(true);
|
2020-03-25 18:22:03 +01:00
|
|
|
event.preventDefault();
|
|
|
|
api.post('/users/register', inputState)
|
|
|
|
.then(({ data }) => {
|
2020-04-22 20:44:06 +02:00
|
|
|
setInputState({ name: "", email: "", password: "" });
|
2020-03-25 18:22:03 +01:00
|
|
|
setMessage(`<p class="form-success"><b>Succès:</b> ${data.result}</p>`);
|
2020-03-25 18:46:23 +01:00
|
|
|
setIsLoading(false);
|
2020-03-25 18:22:03 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
setMessage(`<p class="form-error"><b>Erreur:</b> ${error.response.data.message}</p>`);
|
2020-03-25 18:46:23 +01:00
|
|
|
setIsLoading(false);
|
2020-03-25 18:22:03 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<HeadTag
|
2020-04-07 13:56:56 +02:00
|
|
|
title="S'inscrire - FunctionProject"
|
2020-03-25 18:22:03 +01:00
|
|
|
description="Créer un compte."
|
|
|
|
/>
|
|
|
|
<div className="container Register-Login__container">
|
|
|
|
<div className="row Register-Login__row justify-content-center">
|
|
|
|
<div className="col-20">
|
|
|
|
<h1 className="Register-Login__title">S'inscrire</h1>
|
2020-05-07 11:55:53 +02:00
|
|
|
<div className="text-center">
|
|
|
|
<p>En vous inscrivant, vous accéderez à de nombreuses fonctionnalités : publier des commentaires, ajouter des fonctions aux favoris, utiliser certaines fonctions disponibles qu'aux membres (exemple: La To Do list) etc.</p>
|
|
|
|
</div>
|
2020-03-25 18:22:03 +01:00
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<div className="form-group">
|
|
|
|
<label className="form-label" htmlFor="name">Nom :</label>
|
2020-04-22 20:44:06 +02:00
|
|
|
<input value={inputState.name} onChange={handleChange} type="text" name="name" id="name" className="form-control" placeholder="Divlo" />
|
2020-03-25 18:22:03 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="form-group">
|
|
|
|
<label className="form-label" htmlFor="name">Email :</label>
|
2020-04-22 20:44:06 +02:00
|
|
|
<input value={inputState.email} onChange={handleChange} type="email" name="email" id="email" className="form-control" placeholder="email@gmail.com" />
|
2020-03-25 18:22:03 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="form-group">
|
|
|
|
<label className="form-label" htmlFor="name">Mot de passe :</label>
|
2020-04-22 20:44:06 +02:00
|
|
|
<input value={inputState.password} onChange={handleChange} type="password" name="password" id="password" className="form-control" placeholder="******" />
|
2020-03-25 18:22:03 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="form-group text-center">
|
|
|
|
<button type="submit" className="btn btn-dark">Envoyer</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<div className="form-result text-center">
|
|
|
|
{
|
|
|
|
(isLoading) ?
|
|
|
|
<Loader />
|
|
|
|
:
|
|
|
|
htmlParser(message)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
2020-04-08 15:26:18 +02:00
|
|
|
export default withoutAuth(Register);
|