// - Import react components import React,{Component} from 'react' import {connect} from 'react-redux' import {push} from 'react-router-redux' import {NavLink, withRouter} from 'react-router-dom' import Paper from 'material-ui/Paper' import TextField from 'material-ui/TextField' import RaisedButton from 'material-ui/RaisedButton' import FlatButton from 'material-ui/FlatButton' // - Import actions import * as authorizeActions from 'authorizeActions' import * as globalActions from 'globalActions' // - Create Signup componet class export class Signup extends Component { /** * Component constructor * @param {object} props is an object properties of component */ constructor(props){ super(props); this.state = { fullNameInput: '', fullNameInputError: '', emailInput: '', emailInputError: '', passwordInput: '', passwordInputError: '', confirmInput: '', confirmInputError: '' } // Binding function to `this` this.handleForm = this.handleForm.bind(this) } /** * Handle data on input change * @param {event} evt is an event of inputs of element on change */ handleInputChange = (evt) => { const target = evt.target const value = target.type === 'checkbox' ? target.checked : target.value const name = target.name this.setState({ [name]: value }) switch (name) { case 'fullNameInput': this.setState({ fullNameInputError: '', }) break case 'emailInput': this.setState({ emailInputError: '' }) break case 'passwordInput': this.setState({ confirmInputError: '', passwordInputError: '' }) break case 'confirmInput': this.setState({ confirmInputError: '', passwordInputError: '' }) break case 'checkInput': this.setState({ checkInputError: '' }) break; default: } } /** * Handle register form */ handleForm = () => { var error = false if (this.state.fullNameInput === '') { this.setState({ fullNameInputError: 'This field is required' }) error = true } if (this.state.emailInput === '') { this.setState({ emailInputError: 'This field is required' }) error = true } if (this.state.passwordInput === '') { this.setState({ passwordInputError: 'This field is required' }) error = true } if (this.state.confirmInput === '') { this.setState({ confirmInputError: 'This field is required' }) error = true } else if(this.state.confirmInput !== this.state.passwordInput){ this.setState({ passwordInputError: 'This field sould be equal to confirm password', confirmInputError: 'This field sould be equal to password' }) error = true } if (!error) { this.props.register({ email: this.state.emailInput, password: this.state.passwordInput, fullName: this.state.fullNameInput }) } } /** * Reneder component DOM * @return {react element} return the DOM which rendered by component */ render() { const paperStyle = { minHeight: 500, width: 450, margin: 20, textAlign: 'center', display: 'block', margin: "auto" }; return (