|
| 1 | +import React from 'react'; |
| 2 | +import { useTranslation } from 'react-i18next'; |
| 3 | +import Divider from '@mui/material/Divider'; |
| 4 | +import ProfileIcon from '@mui/icons-material/AccountCircle'; |
| 5 | +import List from '@mui/material/List'; |
| 6 | +import ListItemButton from '@mui/material/ListItemButton'; |
| 7 | +import ListItemIcon from '@mui/material/ListItemIcon'; |
| 8 | +import ListItemText from '@mui/material/ListItemText'; |
| 9 | +import Collapse from '@mui/material/Collapse'; |
| 10 | +import ExpandLess from '@mui/icons-material/ExpandLess'; |
| 11 | +import ExpandMore from '@mui/icons-material/ExpandMore'; |
| 12 | +import RepoIcon from '@mui/icons-material/FolderOutlined'; |
| 13 | +import OrgIcon from '@mui/icons-material/AccountBalance'; |
| 14 | +import BookmarkIcon from '@mui/icons-material/BookmarkBorder'; |
| 15 | +import LanguageIcon from '@mui/icons-material/Language'; |
| 16 | +import find from 'lodash/find'; |
| 17 | +import { getCurrentUser, logoutUser } from '../../common/utils' |
| 18 | +import { LANGUAGES } from '../../common/constants'; |
| 19 | +import Button from '../common/Button'; |
| 20 | +import Drawer from '../common/Drawer'; |
| 21 | +import UserProfileButton from './UserProfileButton'; |
| 22 | +import CloseIconButton from '../common/CloseIconButton'; |
| 23 | + |
| 24 | +const UserMenu = ({ isOpen, onClose }) => { |
| 25 | + const { t, i18n } = useTranslation() |
| 26 | + const [languageOpen, setLanguageOpen] = React.useState(false) |
| 27 | + const selectedLanguage = find(LANGUAGES, {locale: i18n.language}) |
| 28 | + const user = getCurrentUser() |
| 29 | + const onLanguageSelect = locale => { |
| 30 | + i18n.changeLanguage(locale) |
| 31 | + setLanguageOpen(false) |
| 32 | + } |
| 33 | + return ( |
| 34 | + <Drawer isOpen={isOpen} onClose={onClose}> |
| 35 | + <div className='col-xs-12' style={{padding: '15px'}}> |
| 36 | + <div className='col-xs-12 padding-0'> |
| 37 | + <div className='col-xs-2 padding-0'> |
| 38 | + <UserProfileButton /> |
| 39 | + </div> |
| 40 | + <div className='col-xs-9 padding-0'> |
| 41 | + <div className='col-xs-12 padding-0'> |
| 42 | + <b>{user?.username}</b> |
| 43 | + </div> |
| 44 | + <div className='col-xs-12 padding-0'> |
| 45 | + {user?.name} |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + <div className='col-xs-1 padding-0'> |
| 49 | + <CloseIconButton onClick={onClose} /> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + <div className='col-xs-12 padding-0'> |
| 53 | + <List> |
| 54 | + <ListItemButton sx={{p: 1}}> |
| 55 | + <ListItemIcon sx={{minWidth: 'auto', paddingRight: '14px'}}> |
| 56 | + <ProfileIcon /> |
| 57 | + </ListItemIcon> |
| 58 | + <ListItemText primary={t('user.my_profile')} /> |
| 59 | + </ListItemButton> |
| 60 | + </List> |
| 61 | + </div> |
| 62 | + <Divider style={{width: '100%'}} /> |
| 63 | + <div className='col-xs-12 padding-0'> |
| 64 | + <List> |
| 65 | + <ListItemButton sx={{p: 1}}> |
| 66 | + <ListItemIcon sx={{minWidth: 'auto', paddingRight: '14px'}}> |
| 67 | + <RepoIcon /> |
| 68 | + </ListItemIcon> |
| 69 | + <ListItemText primary={t('user.my_repositories')} /> |
| 70 | + <span>0</span> |
| 71 | + </ListItemButton> |
| 72 | + <ListItemButton sx={{p: 1}}> |
| 73 | + <ListItemIcon sx={{minWidth: 'auto', paddingRight: '14px'}}> |
| 74 | + <OrgIcon /> |
| 75 | + </ListItemIcon> |
| 76 | + <ListItemText primary={t('user.my_organizations')} /> |
| 77 | + <span>0</span> |
| 78 | + </ListItemButton> |
| 79 | + <ListItemButton sx={{p: 1}}> |
| 80 | + <ListItemIcon sx={{minWidth: 'auto', paddingRight: '14px'}}> |
| 81 | + <BookmarkIcon /> |
| 82 | + </ListItemIcon> |
| 83 | + <ListItemText primary={t('user.my_bookmarks')} /> |
| 84 | + <span>0</span> |
| 85 | + </ListItemButton> |
| 86 | + </List> |
| 87 | + </div> |
| 88 | + <Divider style={{width: '100%'}} /> |
| 89 | + <div className='col-xs-12 padding-0'> |
| 90 | + <List> |
| 91 | + <ListItemButton sx={{p: 1}} onClick={() => setLanguageOpen(!languageOpen)}> |
| 92 | + <ListItemIcon sx={{minWidth: 'auto', paddingRight: '14px'}}> |
| 93 | + <LanguageIcon /> |
| 94 | + </ListItemIcon> |
| 95 | + <ListItemText primary={selectedLanguage.name} secondary={t('common.language')} /> |
| 96 | + {languageOpen ? <ExpandLess /> : <ExpandMore />} |
| 97 | + </ListItemButton> |
| 98 | + <Collapse in={languageOpen} timeout="auto" unmountOnExit> |
| 99 | + <List component="div" disablePadding> |
| 100 | + { |
| 101 | + LANGUAGES.map(lang => ( |
| 102 | + <ListItemButton sx={{ pl: 5.75 }} selected={lang.locale === selectedLanguage.locale} key={lang.locale} onClick={() => onLanguageSelect(lang.locale)}> |
| 103 | + <ListItemText primary={lang.locale.toUpperCase()} secondary={lang.name} /> |
| 104 | + </ListItemButton> |
| 105 | + )) |
| 106 | + } |
| 107 | + </List> |
| 108 | + </Collapse> |
| 109 | + </List> |
| 110 | + </div> |
| 111 | + <Divider style={{width: '100%'}} /> |
| 112 | + <div className='col-xs-12 padding-0' style={{marginTop: '24px'}}> |
| 113 | + <Button label={t('auth.sign_out')} sx={{ bgcolor: 'primary.light', maxWidth: '100%' }} onClick={() => logoutUser()} /> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </Drawer> |
| 117 | + ) |
| 118 | +} |
| 119 | + |
| 120 | +export default UserMenu |
0 commit comments