| author | Riwad Salim |
| Wed, 15 Aug 2018 23:39:02 +0200 | |
| changeset 145 | 5d2bc8c877ea |
| parent 143 | cfcbf4bc66f1 |
| child 151 | 57d63a248f0d |
| permissions | -rw-r--r-- |
| 89 | 1 |
import React, { Component } from 'react'; |
2 |
import { connect } from 'react-redux'; |
|
3 |
import { bindActionCreators } from 'redux'; |
|
4 |
import '../App.css'; |
|
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
5 |
import './Register.css'; |
| 89 | 6 |
import Navbar from './Navbar'; |
7 |
import * as authActions from '../actions/authActions'; |
|
8 |
||
9 |
class Register extends Component { |
|
10 |
||
11 |
register = () => { |
|
12 |
const username = this.username.value; |
|
13 |
const email = this.email.value; |
|
14 |
const password1 = this.password1.value; |
|
15 |
const password2 = this.password2.value; |
|
16 |
||
17 |
this.props.authActions.registerSubmit(username, email, password1, password2); |
|
18 |
} |
|
19 |
||
| 94 | 20 |
submit = (e) => { |
21 |
e.preventDefault(); |
|
22 |
||
23 |
this.register(); |
|
24 |
} |
|
25 |
||
| 89 | 26 |
onClickLogin = (e) => { |
27 |
e.preventDefault(); |
|
28 |
this.props.history.push('/login'); |
|
29 |
} |
|
30 |
||
31 |
renderErrorMessage(errorMessages, fieldname) { |
|
32 |
if (errorMessages && errorMessages.has(fieldname)) { |
|
33 |
return errorMessages.get(fieldname).map((message, key) => |
|
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
34 |
<p className="help-block" key={ key }>{ message }</p> |
| 89 | 35 |
); |
36 |
} |
|
37 |
} |
|
38 |
||
39 |
render() { |
|
40 |
||
41 |
const errorMessages = this.props.register.get('errorMessages'); |
|
42 |
||
43 |
return ( |
|
44 |
<div> |
|
45 |
<Navbar history={this.props.history} /> |
|
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
46 |
<div className="container-fluid"> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
47 |
<div className="row"> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
48 |
<div className="col-md-6 col-md-offset-3"> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
49 |
<div className="panel-login panel panel-default"> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
50 |
<div className="panel-heading"> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
51 |
<h4 className="text-center panel-title">IRI Notes</h4> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
52 |
<form onSubmit={this.submit}> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
53 |
<div className="form-group" validationState={ errorMessages && errorMessages.has('username') ? 'error' : null }> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
54 |
<label className="control-label">Nom d'utilisateur</label> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
55 |
<input className="form-control" type="text" inputRef={ref => { this.username = ref; }} /> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
56 |
{ this.renderErrorMessage(errorMessages, 'username') } |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
57 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
58 |
<div className="form-group" validationState={ errorMessages && errorMessages.has('email') ? 'error' : null }> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
59 |
<label className="control-label">Email</label> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
60 |
<input className="form-control" type="email" inputRef={ref => { this.email = ref; }} /> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
61 |
{ this.renderErrorMessage(errorMessages, 'email') } |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
62 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
63 |
<div className="form-group" validationState={ errorMessages && errorMessages.has('password1') ? 'error' : null }> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
64 |
<label className="control-label">Mot de passe</label> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
65 |
<input className="form-control" type="password" inputRef={ref => { this.password1 = ref; }} /> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
66 |
{ this.renderErrorMessage(errorMessages, 'password1') } |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
67 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
68 |
<div className="form-group" validationState={ errorMessages && errorMessages.has('password2') ? 'error' : null }> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
69 |
<label className="control-label">Confirmer le mot de passe</label> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
70 |
<input className="form-control" type="password" inputRef={ref => { this.password2 = ref; }} /> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
71 |
{ this.renderErrorMessage(errorMessages, 'password2') } |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
72 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
73 |
<button type="submit" className="btn btn-primary btn-lg">S'inscrire</button> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
74 |
</form> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
75 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
76 |
</div> |
| 89 | 77 |
<p className="text-center"> |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
78 |
<a className="text-muted" href="/login" onClick={ this.onClickLogin }>Déjà inscrit ? Se connecter.</a> |
| 89 | 79 |
</p> |
|
143
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
80 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
81 |
</div> |
|
cfcbf4bc66f1
Remove react-bootstrap from components except Modal, Collapse and Dropdown
salimr <riwad.salim@yahoo.fr>
parents:
129
diff
changeset
|
82 |
</div> |
| 89 | 83 |
</div> |
84 |
); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
function mapStateToProps(state, props) { |
|
89 |
return { |
|
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
94
diff
changeset
|
90 |
register: state.get('register') |
| 89 | 91 |
}; |
92 |
} |
|
93 |
||
94 |
function mapDispatchToProps(dispatch) { |
|
95 |
return { |
|
96 |
authActions: bindActionCreators(authActions, dispatch) |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
export default connect(mapStateToProps, mapDispatchToProps)(Register); |