diff -r 2a861fed6bde -r 06f609adfbf8 client/src/components/Register.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/components/Register.js Mon Jun 26 15:45:50 2017 +0200 @@ -0,0 +1,101 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; +import { Grid, Row, Col, Panel, FormGroup, ControlLabel, FormControl, Button, Alert, HelpBlock } from 'react-bootstrap'; +import '../App.css'; +import Navbar from './Navbar'; +import * as authActions from '../actions/authActions'; + +class Register extends Component { + + register = () => { + const username = this.username.value; + const email = this.email.value; + const password1 = this.password1.value; + const password2 = this.password2.value; + + this.props.authActions.registerSubmit(username, email, password1, password2); + } + + onClickLogin = (e) => { + e.preventDefault(); + this.props.history.push('/login'); + } + + renderError() { + return ( + Bad credentials + ) + } + + renderErrorMessage(errorMessages, fieldname) { + if (errorMessages && errorMessages.has(fieldname)) { + return errorMessages.get(fieldname).map((message, key) => + { message } + ); + } + } + + render() { + + const panelHeader = ( +

Register

+ ) + + const errorMessages = this.props.register.get('errorMessages'); + + return ( +
+ + + + + +
+ + Username + { this.username = ref; }} /> + { this.renderErrorMessage(errorMessages, 'username') } + + + Email + { this.email = ref; }} /> + { this.renderErrorMessage(errorMessages, 'email') } + + + Password + { this.password1 = ref; }} /> + { this.renderErrorMessage(errorMessages, 'password1') } + + + Confirm password + { this.password2 = ref; }} /> + { this.renderErrorMessage(errorMessages, 'password2') } + + +
+
+

+ Already registered? Sign in. +

+ +
+
+
+ ); + } +} + +function mapStateToProps(state, props) { + return { + register: state['register'] + }; +} + +function mapDispatchToProps(dispatch) { + return { + authActions: bindActionCreators(authActions, dispatch) + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(Register);