Merge branch 'master' into 14566-admin-modal
[arvados.git] / src / views-components / main-app-bar / account-menu.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { MenuItem } from "@material-ui/core";
7 import { User, getUserFullname } from "~/models/user";
8 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
9 import { UserPanelIcon } from "~/components/icon/icon";
10 import { DispatchProp, connect } from 'react-redux';
11 import { logout } from '~/store/auth/auth-action';
12 import { RootState } from "~/store/store";
13 import { openCurrentTokenDialog } from '~/store/current-token-dialog/current-token-dialog-actions';
14 import { openRepositoriesPanel } from "~/store/repositories/repositories-actions";
15 import { navigateToSshKeysUser, navigateToMyAccount } from '~/store/navigation/navigation-action';
16 import { openUserVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions";
17
18 interface AccountMenuProps {
19     user?: User;
20 }
21
22 const mapStateToProps = (state: RootState): AccountMenuProps => ({
23     user: state.auth.user
24 });
25
26 export const AccountMenu = connect(mapStateToProps)(
27     ({ user, dispatch }: AccountMenuProps & DispatchProp<any>) =>
28         user
29             ? <DropdownMenu
30                 icon={<UserPanelIcon />}
31                 id="account-menu"
32                 title="Account Management">
33                 <MenuItem>
34                     {getUserFullname(user)}
35                 </MenuItem>
36                 <MenuItem onClick={() => dispatch(openUserVirtualMachines())}>Virtual Machines</MenuItem>
37                 {!user.isAdmin && <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>}
38                 <MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
39                 <MenuItem onClick={() => dispatch(navigateToSshKeysUser)}>Ssh Keys</MenuItem>
40                 <MenuItem onClick={() => dispatch(navigateToMyAccount)}>My account</MenuItem>
41                 <MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>
42             </DropdownMenu>
43             : null);