aboutsummaryrefslogblamecommitdiff
path: root/cmd/web/js/signup.jsx
blob: b7d92875e81bb205395f34c8bc8820e3cb1a8622 (plain) (tree)





























                                                                                                       
                       


                                     
                                                    


                                  
                                                 


                       
                                     


                                 
                                                               


                  

                                                                                                           
                                     
                                                                            





                                                                                                                            




                   


                          
import Api from './api.js';
import App from './app.js';
import classNames from 'classnames';
import React from 'react';

class SignupForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''};
  }

  handleSubmit = (e) => {
    Api.Call(
    'SIGNUP',
    {
      'password': this.state.password,
      'email': this.state.email
    },
    function(err, status, data) {
      if (err) {
        console.error(err, data);
        this.displayMessage(App.errorCodeToMessage(err.code), false);
        return;
      }

      this.displayMessage('Thank You. Your account is being confirmed. Check your mailbox soon', true);
      this.props.onSuccess(data.token);

    }.bind(this)
);
    e.preventDefault();
  }

  handlePasswordChange = (event) => {
    this.setState({'password': event.target.value});
  }

  handleEmailChange = (event) => {
    this.setState({'email': event.target.value});
  }

  hideMessage = () => {
    this.setState({'hideMsg': true});
  }

  displayMessage = (msg, ok) => {
    this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
  }

  render = () => {
    var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
    return (
        <div className="row sign-in">
          <div className="offset-1 col-10 offset-md-4 col-md-4 text-center">
            <form role="form" onSubmit={this.handleSubmit}>
              <input className="form-control" type="email" placeholder="email" onChange={this.handleEmailChange} />
              <input className="form-control" type="password" placeholder="password" onChange={this.handlePasswordChange} />
              <input className="form-control submit" type="submit" value="Sign Up" />
              <div className={cName}>{this.state.msg}</div>
              <a href="#" onClick={App.onInternNavigation.bind(this, '/signin')}><u>Sign In</u></a>
            </form>
          </div>
        </div>
       );
  }
}

export default SignupForm;