]>
Commit | Line | Data |
---|---|---|
989fb5c7 | 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); | |
6bf174a9 | 27 | this.props.onSuccess(data.token, data.isAdmin); |
989fb5c7 | 28 | |
29 | }.bind(this) | |
30 | ); | |
7a9e5112 | 31 | e.preventDefault(); |
989fb5c7 | 32 | } |
33 | ||
34 | handlePasswordChange = (event) => { | |
7a9e5112 | 35 | this.setState({'password': event.target.value}); |
989fb5c7 | 36 | } |
37 | ||
38 | handleEmailChange = (event) => { | |
7a9e5112 | 39 | this.setState({'email': event.target.value}); |
989fb5c7 | 40 | } |
41 | ||
42 | hideMessage = () => { | |
7a9e5112 | 43 | this.setState({'hideMsg': true}); |
989fb5c7 | 44 | } |
45 | ||
46 | displayMessage = (msg, ok) => { | |
7a9e5112 | 47 | this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); |
989fb5c7 | 48 | } |
49 | ||
50 | render = () => { | |
7a9e5112 | 51 | var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); |
52 | return ( | |
989fb5c7 | 53 | <div className="row sign-in"> |
a6820180 | 54 | <div className="offset-1 box col-10 offset-md-4 col-md-4 text-center"> |
989fb5c7 | 55 | <form role="form" onSubmit={this.handleSubmit}> |
a6820180 | 56 | <label className="w-100 text-left"><strong>Email address</strong></label> |
57 | <input className="form-control" type="email" onChange={this.handleEmailChange} /> | |
58 | <label className="w-100 text-left"><strong>Password</strong></label> | |
59 | <input className="form-control" type="password" onChange={this.handlePasswordChange} /> | |
989fb5c7 | 60 | <input className="form-control submit" type="submit" value="Sign Up" /> |
61 | <div className={cName}>{this.state.msg}</div> | |
7a9e5112 | 62 | </form> |
63 | </div> | |
64 | </div> | |
65 | ); | |
66 | } | |
989fb5c7 | 67 | } |
68 | ||
69 | export default SignupForm; |