70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
import React from "react"
|
|
import { connect } from "react-redux"
|
|
import { bindActionCreators } from "redux"
|
|
|
|
import { userSignUp } from "../../actions/users"
|
|
|
|
function mapStateToProps(state) {
|
|
return {
|
|
isLogged: state.userStore.get("isLogged"),
|
|
};
|
|
}
|
|
|
|
const mapDispatchToProps = (dispatch) =>
|
|
bindActionCreators({ userSignUp }, dispatch)
|
|
|
|
class UserSignUp extends React.PureComponent {
|
|
constructor(props) {
|
|
super(props);
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
}
|
|
handleSubmit(e) {
|
|
e.preventDefault();
|
|
this.props.userSignUp({
|
|
"username": this.refs.username.value,
|
|
"password": this.refs.password.value,
|
|
"password_confirm": this.refs.passwordConfirm.value,
|
|
});
|
|
}
|
|
componentWillReceiveProps(nextProps) {
|
|
if (!nextProps.isLogged) {
|
|
return
|
|
}
|
|
// Redirect home
|
|
nextProps.router.push("/");
|
|
}
|
|
render() {
|
|
return (
|
|
<div className="container">
|
|
<div className="content-fluid">
|
|
<div className="col-md-6 col-md-offset-3 col-xs-12">
|
|
<h2>Sign up</h2>
|
|
<hr />
|
|
|
|
<form ref="userSignUpForm" className="form-horizontal" onSubmit={(e) => this.handleSubmit(e)}>
|
|
<div className="form-group">
|
|
<label className="control-label">Username</label>
|
|
<input autoFocus="autofocus" className="form-control" type="text" ref="username" />
|
|
</div>
|
|
|
|
<div className="form-group">
|
|
<label className="control-label">Password</label>
|
|
<input className="form-control" ref="password" type="password" />
|
|
</div>
|
|
|
|
<div className="form-group">
|
|
<label className="control-label">Password confirm</label>
|
|
<input className="form-control" ref="passwordConfirm" type="password" />
|
|
</div>
|
|
<div>
|
|
<input className="btn btn-primary pull-right" type="submit" value="Sign up"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(UserSignUp);
|