Advertisement
Guest User

Untitled

a guest
Jan 7th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { PropTypes } from 'react';
  2. import { get } from 'lodash';
  3. import Base from 'shared/components/base';
  4. import { Form, Input, Button, Container } from 'shared/components/basic';
  5. import { uiSize, colorStates } from 'shared/components/basic/constants';
  6. import './styles.scss';
  7. export default class LoginComponent extends Base {
  8.   constructor(props) {
  9.     super(props);
  10.     this.state = {
  11.       username: '',
  12.       password: '',
  13.     };
  14.   }
  15.   render() {
  16.     const { config } = this.context;
  17.     return (
  18.       <Container >
  19.         <div className="login-component">
  20.           <div className="logo" />
  21.           <Form
  22.             ref={(c) => { this.form = c; }}
  23.             className="col-md-5 mx-auto form clearfix"
  24.           >
  25.             <Input
  26.               name="username"
  27.               type="text"
  28.               value={this.state.username}
  29.               placeholder={this.translate('Login.loginInput')}
  30.               onChange={(e) => this._updateValues(e.target.value, 'username')}
  31.               rules={get(config, 'Login.validators.username', {})}
  32.             />
  33.             <Input
  34.               name="password"
  35.               type="password"
  36.               value={this.state.password}
  37.               placeholder={this.translate('Login.passwordInput')}
  38.               onChange={(e) => this._updateValues(e.target.value, 'password')}
  39.               rules={get(config, 'Login.validators.password', {})}
  40.             />
  41.             <Button
  42.               colorState={colorStates.PRIMARY}
  43.               size={uiSize.DEFAULT}
  44.               className="button float-xs-right"
  45.               loading={this.props.isLoading}
  46.               onClick={() => this._onEnterPress()}
  47.             >
  48.               {this.translate('Login.enter')} {this.translate('appName')}
  49.             </Button>
  50.           </Form>
  51.           <div className="need-help mx-auto">
  52.             {this.translate('Login.needHelp')}
  53.           </div>
  54.         </div>
  55.       </Container>
  56.     );
  57.   }
  58.   _updateValues(value, type) {
  59.     this.setState({ [type]: value });
  60.   }
  61.   _isValid() {
  62.     return this.form.validateAll();
  63.   }
  64.   _onEnterPress() {
  65.     if (this._isValid()) {
  66.       this.props.login(this.state.username, this.state.password);
  67.     }
  68.   }
  69. }
  70. LoginComponent.contextTypes = {
  71.   config: PropTypes.object.isRequired,
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement