import { h, Component } from 'preact'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { Redirect } from 'react-router-dom'; import * as actions from './auth.actions'; import { Group, Param, TextInput, Button } from '../common'; class Signup extends Component { state = { username: '', password: '', password2: '', } constructor() { super() this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) } handleChange(value, name) { this.setState({ [name]: value, }) } validate(){ if (!this.state.password || this.state.password !== this.state.password2) { return false } return true } handleSubmit(e) { e.preventDefault() if (!this.validate) { return this.props.actions.setError('bad password') } let { ...user } = this.state this.props.actions.signup(user) } render(){ if (this.props.auth.isAuthenticated) { return } return (

New account


{this.renderAuthError()}
) } renderAuthError(){ if (this.props.auth.error) { return (
{"Please doublecheck the form"}
) } return null } } const mapStateToProps = (state) => ({ auth: state.auth, }); const mapDispatchToProps = (dispatch) => ({ actions: bindActionCreators({ ...actions }, dispatch) }); export default connect(mapStateToProps, mapDispatchToProps)(Signup);