From 44e753b794513c5c9c1f550d685461e6c5bb0d11 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 20 Sep 2020 19:10:16 -0700 Subject: Add users context menu --- modern/src/MainToolbar.js | 7 +++--- modern/src/admin/UsersPage.js | 58 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index 338e961b..60731967 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -44,6 +44,7 @@ const MainToolbar = () => { const classes = useStyles(); const history = useHistory(); const adminEnabled = useSelector(state => state.session.user && state.session.user.administrator); + const userId = useSelector(state => state.session.user && state.session.user.id); const openDrawer = () => { setDrawer(true) } const closeDrawer = () => { setDrawer(false) } @@ -94,7 +95,7 @@ const MainToolbar = () => { {t('reportTitle')} }> - { history.push('/reports/route') }}> + history.push('/reports/route')}> @@ -138,7 +139,7 @@ const MainToolbar = () => { {t('settingsTitle')} }> - + history.push(`/user/${userId}`)}> @@ -166,7 +167,7 @@ const MainToolbar = () => { {t('userAdmin')} }> - { history.push('/admin/users') }}> + history.push('/admin/users')}> diff --git a/modern/src/admin/UsersPage.js b/modern/src/admin/UsersPage.js index 15368c75..30268e3e 100644 --- a/modern/src/admin/UsersPage.js +++ b/modern/src/admin/UsersPage.js @@ -1,7 +1,9 @@ import React, { useState } from 'react'; import MainToobar from '../MainToolbar'; import { useHistory } from 'react-router-dom'; -import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles } from '@material-ui/core'; +import { Fab, TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton, Menu, MenuItem } from '@material-ui/core'; +import AddIcon from '@material-ui/icons/Add'; +import MoreVertIcon from '@material-ui/icons/MoreVert'; import t from '../common/localization'; import formatter from '../common/formatter'; import { useEffectAsync } from '../reactHelper'; @@ -9,16 +11,14 @@ import { useEffectAsync } from '../reactHelper'; const useStyles = makeStyles(theme => ({ root: { height: '100%', - display: 'flex', - flexDirection: 'column', }, - content: { - flex: 1, - overflow: 'auto', - padding: theme.spacing(2), + columnAction: { + width: theme.spacing(8), }, - form: { - padding: theme.spacing(1, 2, 2), + fab: { + position: 'absolute', + bottom: theme.spacing(2), + right: theme.spacing(2), }, })); @@ -26,6 +26,8 @@ const UsersPage = () => { const history = useHistory(); const classes = useStyles(); const [data, setData] = useState([]); + const [menuItemId, setMenuItemId] = useState(null); + const [menuAnchorEl, setMenuAnchorEl] = useState(null); useEffectAsync(async () => { const response = await fetch('/api/users'); @@ -34,6 +36,31 @@ const UsersPage = () => { } }, []); + const handleMenuOpen = (event, itemId) => { + setMenuItemId(itemId); + setMenuAnchorEl(event.currentTarget); + } + + const handleMenuClose = () => { + setMenuItemId(null); + setMenuAnchorEl(null); + } + + const handleMenuEdit = () => { + history.push(`/user/${menuItemId}`); + handleMenuClose(); + } + + const handleMenuRemove = () => { + //setRemoveDialogOpen(true); + handleMenuClose(); + } + + const handleAdd = () => { + history.push('/user'); + //handleMenuClose(); + } + return (
@@ -45,6 +72,7 @@ const UsersPage = () => { {t('userEmail')} {t('userAdmin')} {t('sharedDisabled')} + @@ -54,11 +82,23 @@ const UsersPage = () => { {formatter(item, 'email')} {formatter(item, 'administrator')} {formatter(item, 'disabled')} + + handleMenuOpen(event, item.id)}> + + + ))} + + + + + {t('sharedEdit')} + {t('sharedRemove')} +
); } -- cgit v1.2.3