All files / web/modules/components UserDropdownMenu.tsx

71.43% Statements 15/21
0% Branches 0/1
0% Functions 0/2
75% Lines 15/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 571x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x                 1x                                     1x                   1x            
import Divider from 'antd/lib/divider';
import Icon from 'antd/lib/icon';
import { Push, push as pushAction } from 'connected-react-router';
import * as React from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { adminAvailablePermission } from '../../../shared/permissions';
import { IState } from '../../types';
import { AuthLogoutAction, authLogoutAction } from '../auth/actions';
import { selectHasPermission, selectUsername } from '../auth/reducer';
import { Routes } from '../router/routes';
import Button from './Button';
import Link from './Link';
 
interface IProps {
  logout: AuthLogoutAction;
  username: string;
  push: Push;
  hasPermission: (groups: string[]) => boolean;
}
 
const UserDropdownMenu = ({
  username,
  push,
  logout,
  hasPermission,
}: IProps) => (
  <React.Fragment>
    {hasPermission(adminAvailablePermission) && [
      <Link key="admin" to={Routes.admin}>
        admin
      </Link>,
      <Divider key="divider" type="vertical" />,
    ]}
    <Button onClick={logout}>
      Odhlásit <Icon type="logout" style={{ marginLeft: '5px' }} />
    </Button>
  </React.Fragment>
);
 
const mapStateToProps = (state: IState) => ({
  username: selectUsername(state),
  hasPermission: selectHasPermission(state),
});
 
const mapDispatchToProps = {
  logout: authLogoutAction,
  push: pushAction,
};
 
export default compose(
  connect(
    mapStateToProps,
    mapDispatchToProps,
  ),
)(UserDropdownMenu);