]>
Commit | Line | Data |
---|---|---|
1 | var Api = require('./api.js').Api; | |
2 | var App = require('./app.js'); | |
3 | var classNames = require('classnames'); | |
4 | ||
5 | module.exports.SignupForm = React.createClass({ | |
6 | getInitialState: function() { | |
7 | return {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''}; | |
8 | }, | |
9 | handleSubmit: function(e) { | |
10 | Api.Call('SIGNUP', | |
11 | { | |
12 | 'password': this.state.password, | |
13 | 'email': this.state.email | |
14 | }, | |
15 | function(err, status, data) { | |
16 | if (err) { | |
17 | console.error(err, data); | |
18 | this.displayMessage(App.errorCodeToMessage(err.code), false); | |
19 | return; | |
20 | } | |
21 | ||
22 | this.displayMessage('Thank You. Your account is being confirmed. Check your mailbox soon', true); | |
23 | this.props.onSuccess(data.token); | |
24 | ||
25 | }.bind(this)); | |
26 | e.preventDefault(); | |
27 | }, | |
28 | handlePasswordChange: function(event) { | |
29 | this.setState({'password': event.target.value}); | |
30 | }, | |
31 | handleEmailChange: function(event) { | |
32 | this.setState({'email': event.target.value}); | |
33 | }, | |
34 | hideMessage: function() { | |
35 | this.setState({'hideMsg': true}); | |
36 | }, | |
37 | displayMessage: function(msg, ok) { | |
38 | this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); | |
39 | }, | |
40 | render: function() { | |
41 | var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); | |
42 | return ( | |
43 | <div className='row justify-content-center sign-in'> | |
44 | <div className='col-lg-offset-4 col-lg-4 col-md-offset-4 col-md-4 col-sm-offset-4 col-sm-4 col-xs-offset-1 col-xs-10'> | |
45 | <form role='form' onSubmit={this.handleSubmit}> | |
46 | <input className='form-control' type='email' placeholder='email' onChange={this.handleEmailChange} /> | |
47 | <input className='form-control' type='password' placeholder='password' onChange={this.handlePasswordChange} /> | |
48 | <input className='form-control submit' type='submit' value='Sign Up' /> | |
49 | <div className={cName} ref='message'>{this.state.msg}</div> | |
50 | <a href='#' onClick={App.onInternNavigation.bind(this, '/signin')}><u>Sign In</u></a> | |
51 | </form> | |
52 | </div> | |
53 | </div> | |
54 | ); | |
55 | } | |
56 | }); |