Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UserMenu from 'app/components/user-menu';
  2. import { IAppState } from 'app/typings';
  3. import * as React from 'react';
  4. import { connect } from 'react-redux';
  5. import { AnyAction, bindActionCreators, Dispatch } from 'redux';
  6. import { execLoginAction, execLogoutAction } from '../actions';
  7. import selectors from '../selectors';
  8. import { IAuthDispatchProps, IAuthPopupProps } from '../typings';
  9. import LoginForm from './login-form';
  10.  
  11. class Auth extends React.Component<IAuthPopupProps & IAuthDispatchProps> {
  12.     render () {
  13.         const auth = this.props.auth;
  14.  
  15.         if (!auth.authenticated) {
  16.             return <LoginForm auth={ this.props.auth } login={ this.props.login } />;
  17.         }
  18.  
  19.         const userDisplayName = auth.firstname + ' ' + auth.lastname;
  20.  
  21.         return <UserMenu currentUser={ userDisplayName } logoutButtonClick={ this.props.logoutButtonClick } />;
  22.     }
  23. }
  24.  
  25. const mapStateToProps = (state: IAppState): IAuthPopupProps => ({ auth: selectors.getAuth(state) });
  26.  
  27. const mapDispatchToProps = (dispatch: Dispatch<AnyAction>): IAuthDispatchProps => (
  28.     bindActionCreators({ login: execLoginAction, logoutButtonClick: execLogoutAction }, dispatch)
  29. );
  30.  
  31. export default connect(mapStateToProps, mapDispatchToProps)(PopoverContent);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement