Grégoire Delattre bcadc48d5a Launch prettier with the --fix option
They've changed their default settings, this changes a lot of stuff in
our code base.
2020-04-01 17:55:34 +02:00

101 lines
2.9 KiB
JavaScript

import React, { useState } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { Redirect } from "react-router-dom";
import { userSignUp } from "../../actions/users";
const mapStateToProps = (state) => ({
isLogged: state.userStore.get("isLogged"),
isLoading: state.userStore.get("loading"),
error: state.userStore.get("error"),
});
const mapDispatchToProps = { userSignUp };
const UserSignUp = (props) => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [passwordConfirm, setPasswordConfirm] = useState("");
if (props.isLogged) {
return <Redirect to="/" />;
}
const handleSubmit = (e) => {
e.preventDefault();
props.userSignUp({
username: username,
password: password,
password_confirm: passwordConfirm, // eslint-disable-line camelcase
});
};
return (
<div className="Row">
<div className="col-10 offset-1 col-md-6 offset-md-3">
<h2>Sign up</h2>
<hr />
{props.error && props.error !== "" && (
<div className="alert alert-danger">{props.error}</div>
)}
<form className="form-horizontal" onSubmit={(e) => handleSubmit(e)}>
<div className="form-group">
<label className="control-label">Username</label>
<input
autoFocus="autofocus"
className="form-control"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
</div>
<div className="form-group">
<label className="control-label">Password</label>
<input
className="form-control"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
<div className="form-group">
<label className="control-label">Password confirm</label>
<input
className="form-control"
type="password"
value={passwordConfirm}
onChange={(e) => setPasswordConfirm(e.target.value)}
/>
</div>
<div>
{props.isLoading && (
<button className="btn btn-primary pull-right">
<i className="fa fa-spinner fa-spin"></i>
</button>
)}
{props.isLoading || (
<span>
<input
className="btn btn-primary pull-right"
type="submit"
value="Sign up"
/>
</span>
)}
</div>
</form>
</div>
</div>
);
};
UserSignUp.propTypes = {
isLogged: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
userSignUp: PropTypes.func.isRequired,
error: PropTypes.string,
};
export default connect(mapStateToProps, mapDispatchToProps)(UserSignUp);