diff -r f0f83f5530a6 -r c78d579f4b55 client/src/components/Reset.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/components/Reset.js Tue Dec 18 02:27:22 2018 +0100 @@ -0,0 +1,128 @@ +import React, { Component } from 'react'; +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 Reset extends Component { + + constructor(props) { + super(props); + + this.state = { + email: '' + } + + + } + + reset = () => { + const { email } = this.state; + + this.props.authActions.resetSubmit(email); + } + + handleChange = (event) => { + const newState = {}; + newState[event.target.name] = event.target.value; + this.setState(newState); + } + + submit = (e) => { + e.preventDefault(); + + this.reset(); + } + + onClickLogin = (e) => { + e.preventDefault(); + this.props.history.push('/login'); + } + + renderErrorMessage(errorMessages, fieldname) { + 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.error ? this.props.register.errorMessages : false ; + + return ( +
+ {/* */} +
+
+
+
+
+

IRI Notes

+
+
+ + + { errorMessages && this.renderErrorMessage(errorMessages.data, 'email') } +
+ { this.renderNonFieldErrors(errorMessages) } +
+ +
+
+
+
+

+ Déjà inscrit ? Se connecter. +

+
+
+
+
+ ); + } +} + +function mapStateToProps(state, props) { + return { + register: state.register + }; +} + +function mapDispatchToProps(dispatch) { + return { + authActions: bindActionCreators(authActions, dispatch) + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(Reset);