diff options
author | jloup <jean-loup.jamet@trainline.com> | 2018-02-14 14:19:09 +0100 |
---|---|---|
committer | jloup <jean-loup.jamet@trainline.com> | 2018-02-14 14:19:09 +0100 |
commit | 7a9e5112eaaea58d55f181d3e5296e4ff839921c (patch) | |
tree | 968ed193f42a1fad759cc89ad2f8ad5b0091291e /cmd/web/js/signup.jsx | |
download | Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.tar.gz Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.tar.zst Front-7a9e5112eaaea58d55f181d3e5296e4ff839921c.zip |
initial commit
Diffstat (limited to 'cmd/web/js/signup.jsx')
-rw-r--r-- | cmd/web/js/signup.jsx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cmd/web/js/signup.jsx b/cmd/web/js/signup.jsx new file mode 100644 index 0000000..149125a --- /dev/null +++ b/cmd/web/js/signup.jsx | |||
@@ -0,0 +1,56 @@ | |||
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 | }); | ||