diff --git a/nextjs/actions/user.js b/nextjs/actions/user.js
index 398ad6d15..8474b2bb9 100644
--- a/nextjs/actions/user.js
+++ b/nextjs/actions/user.js
@@ -23,8 +23,9 @@ export const fetchCurrentUserFailure = user => ({
user
});
-export const registerUserRequest = () => ({
- type: REQUEST_REGISTER
+export const registerUserRequest = (payload) => ({
+ type: REQUEST_REGISTER,
+ payload
});
export const registerUserSuccess = () => ({
diff --git a/nextjs/components/organisms/Register.js b/nextjs/components/organisms/Register.js
index a3f5699dd..8ef76f874 100644
--- a/nextjs/components/organisms/Register.js
+++ b/nextjs/components/organisms/Register.js
@@ -1,8 +1,15 @@
-import React from 'react';
-import { TextField, FormGroup, FormControlLabel, Checkbox, Button, Typography, Link } from '@material-ui/core';
+import React, {Fragment} from 'react';
+import { connect } from "react-redux";
+import Validator from "validator";
+import {FormLabel, FormHelperText,InputLabel, Input,TextField, FormGroup, FormControlLabel, Checkbox, Button, Typography, Link } from '@material-ui/core';
+import Visibility from '@material-ui/icons/Visibility';
+import VisibilityOff from '@material-ui/icons/VisibilityOff';
+import IconButton from '@material-ui/core/IconButton';
+import InputAdornment from '@material-ui/core/InputAdornment';
+import FormControl from '@material-ui/core/FormControl';
import { withStyles } from '@material-ui/core/styles';
-
+import { registerUserRequest, subscribeToNewsletterRequest } from "../../actions/user"
const styles = theme => ({
container: {
@@ -20,22 +27,84 @@ const styles = theme => ({
input50: {
width: '50%',
},
+ checkboxError:{
+ color:'red'
+ }
});
class Register extends React.Component {
state = {
- prenom:'',
- nom:'',
- email:'',
- password:'',
- checkNewsletter:false,
- checkCGU:false
-
+ data: {
+ prenom: '',
+ nom: '',
+ email: '',
+ password: '',
+ checkNewsletter: false,
+ checkCGU: false,
+ },
+ errors: {},
+ loading: false,
+ showPassword:false
}
+ validate = data => {
+ const errors = {};
+ if (!Validator.isEmail(data.email)) errors.email = "Email invalide";
+ if (!!!data.password) errors.password = "Requis";
+ if (!!!data.prenom) errors.prenom = "Requis";
+ if (!!!data.nom) errors.nom = "Requis";
+ if (!data.checkCGU) errors.checkCGU = "Requis";
+
+ return errors;
+ };
+
+ onRegister = e => {
+ e.preventDefault();
+ const errors = this.validate(this.state.data);
+ console.log('onSubmit')
+ console.log(errors)
+ this.setState({ errors: errors });
+
+ if (Object.keys(errors).length === 0) {
+ this.setState({ loading: true });
+
+ this.props.registerUserRequest(this.state.data)
+
+ if (this.state.data.checkNewsletter)
+ this.props.subscribeToNewsletterRequest({ email: this.state.data.email })
+ }
+
+ };
+
+ componentWillReceiveProps(nextProps) {
+ this.setState({
+ errors: nextProps.errors,
+ loading: nextProps.loading
+ })
+ }
+ onChange = e =>
+ this.setState({
+ data: { ...this.state.data, [e.target.name]: e.target.value }
+ });
+ handleCheckBoxChange = name => event => {
+ this.setState({data:{ ...this.state.data, [name]: event.target.checked }});
+ };
+
+ handleChangePasswordVisibility = prop => event => {
+ this.setState({ [prop]: event.target.value });
+ };
+
+ handleClickShowPassword = () => {
+ this.setState({ showPassword: !this.state.showPassword });
+ };
+
render() {
const { classes } = this.props;
+ const { data, errors } = this.state;
+ console.log('render errors');
+ console.log(errors);
+ console.log(this.state);
return (
@@ -43,77 +112,86 @@ class Register extends React.Component {
-