diff -r f0f83f5530a6 -r c78d579f4b55 client/src/components/Register.js --- a/client/src/components/Register.js Thu Dec 06 01:35:30 2018 +0100 +++ b/client/src/components/Register.js Tue Dec 18 02:27:22 2018 +0100 @@ -2,18 +2,40 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import * as authActions from '../actions/authActions'; +import { Trans } from 'react-i18next'; +import * as R from 'ramda'; class Register extends Component { + constructor(props) { + super(props); + + this.state = { + username: '', + email: '', + password1: '', + password2: '' + } + + + } + register = () => { - const username = this.username.value; - const email = this.email.value; - const password1 = this.password1.value; - const password2 = this.password2.value; + const { + username, + email, + password1, + password2 } = this.state; this.props.authActions.registerSubmit(username, email, password1, password2); } + handleChange = (event) => { + const newState = {}; + newState[event.target.name] = event.target.value; + this.setState(newState); + } + submit = (e) => { e.preventDefault(); @@ -26,16 +48,44 @@ } renderErrorMessage(errorMessages, fieldname) { - if (errorMessages && errorMessages.has(fieldname)) { - return errorMessages.get(fieldname).map((message, key) => -

{ message }

+ if (errorMessages && fieldname in errorMessages) { + return errorMessages[fieldname].map((message, key) => +

{ message }

); } } + renderNonFieldErrors(errorMessages) { + + if (errorMessages && errorMessages.error) { + return ( +
+ Unable to log in. +
+ ) + } + + const errors = R.reduce( + (acc, p) => R.concat(acc, R.ifElse(Array.isArray, R.identity, v => [v,])(R.pathOr([], ['data', p], errorMessages))), + [], + ['non_field_errors', 'detail'] + ); + if (errors && errors.length > 0 ) { + return ( +
+ { errors.map((message, key) => +

{ message }

+ ) } +
+ ) + } + + } + + render() { - // const errorMessages = this.props.register.errorMessages; + const errorMessages = this.props.register.error ? this.props.register.errorMessages : false ; return (
@@ -47,34 +97,35 @@

IRI Notes

-
- - { this.username = ref; }}*/ /> - {/* { this.renderErrorMessage(errorMessages, 'username') } */} +
+ + + { errorMessages && this.renderErrorMessage(errorMessages.data, 'username') }
-
- - { this.email = ref; }}*/ /> - {/* { this.renderErrorMessage(errorMessages, 'email') } */} +
+ + + { errorMessages && this.renderErrorMessage(errorMessages.data, 'email') }
-
- - { this.password1 = ref; }}*/ /> - {/* { this.renderErrorMessage(errorMessages, 'password1') } */} +
+ + + { errorMessages && this.renderErrorMessage(errorMessages.data, 'password1') }
-
- - { this.password2 = ref; }}*/ /> - {/* { this.renderErrorMessage(errorMessages, 'password2') } */} +
+ + + { errorMessages && this.renderErrorMessage(errorMessages.data, 'password2') }
+ { this.renderNonFieldErrors(errorMessages) }
- +

- Déjà inscrit ? Se connecter. + Déjà inscrit ? Se connecter.