]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blob - cmd/web/js/signup.jsx
Factorize Header/Footer code.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / cmd / web / js / signup.jsx
1 import Api from './api.js';
2 import App from './app.js';
3 import classNames from 'classnames';
4 import React from 'react';
5
6 class SignupForm extends React.Component {
7 constructor(props) {
8 super(props);
9 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''};
10 }
11
12 handleSubmit = (e) => {
13 Api.Call(
14 'SIGNUP',
15 {
16 'password': this.state.password,
17 'email': this.state.email
18 },
19 function(err, status, data) {
20 if (err) {
21 console.error(err, data);
22 this.displayMessage(App.errorCodeToMessage(err.code), false);
23 return;
24 }
25
26 this.displayMessage('Thank You. Your account is being confirmed. Check your mailbox soon', true);
27 this.props.onSuccess(data.token);
28
29 }.bind(this)
30 );
31 e.preventDefault();
32 }
33
34 handlePasswordChange = (event) => {
35 this.setState({'password': event.target.value});
36 }
37
38 handleEmailChange = (event) => {
39 this.setState({'email': event.target.value});
40 }
41
42 hideMessage = () => {
43 this.setState({'hideMsg': true});
44 }
45
46 displayMessage = (msg, ok) => {
47 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
48 }
49
50 render = () => {
51 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
52 return (
53 <div className="row sign-in">
54 <div className="offset-1 col-10 offset-md-4 col-md-4 text-center">
55 <form role="form" onSubmit={this.handleSubmit}>
56 <input className="form-control" type="email" placeholder="email" onChange={this.handleEmailChange} />
57 <input className="form-control" type="password" placeholder="password" onChange={this.handlePasswordChange} />
58 <input className="form-control submit" type="submit" value="Sign Up" />
59 <div className={cName}>{this.state.msg}</div>
60 <a href="#" onClick={App.onInternNavigation.bind(this, '/signin')}><u>Sign In</u></a>
61 </form>
62 </div>
63 </div>
64 );
65 }
66 }
67
68 export default SignupForm;