Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { observer, inject } from 'mobx-react';
  3. import { configure, observable } from 'mobx';
  4. import Form from './common/Form';
  5. //import {loginRequest} from '../actions'
  6. interface Props {
  7.     data?: any;
  8.     dispatch?: any;
  9.     history?: any;
  10.     postStore?: any;
  11. }
  12. configure({ enforceActions: 'observed' });
  13. @inject('postStore')
  14. @observer
  15. class Login extends Component<Props> {
  16.     @observable username = '';
  17.     @observable password = '';
  18.     handleChange = (obj: any) => {
  19.         if (obj.type === 'password') {
  20.             this.password = obj.field;
  21.         } else this.username = obj.field;
  22.     };
  23.     onSubmit = () => {
  24.         console.log('here');
  25.         this.props.postStore.Login(this.username, this.password);
  26.     };
  27.     render() {
  28.         if (this.props.postStore.LogIn.success) {
  29.             this.props.history.push('/');
  30.         }
  31.         return (
  32.             <div className="form-page__wrapper">
  33.                 <div className="form-page__form-wrapper">
  34.                     <div className="form-page__form-header">
  35.                         <h2 className="form-page__form-heading">Login</h2>
  36.                     </div>
  37.                     <Form
  38.                         data={{}}
  39.                         onSubmit={this.onSubmit}
  40.                         btnText={'Login'}
  41.                         error={this.props.postStore.LogIn.error}
  42.                         onChange={this.handleChange}
  43.                         currentlySending={false}
  44.                     />
  45.                 </div>
  46.             </div>
  47.         );
  48.     }
  49. }
  50.  
  51. // Which props do we want to inject, given the global state?
  52.  
  53. // Wrap the component to inject dispatch and state into it
  54. export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement