import React, { useState } from 'react'; import MainToobar from '../MainToolbar'; import { useHistory } from 'react-router-dom'; 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'; const useStyles = makeStyles(theme => ({ root: { height: '100%', }, columnAction: { width: theme.spacing(1), padding: theme.spacing(0, 1), }, fab: { position: 'absolute', bottom: theme.spacing(2), right: theme.spacing(2), }, })); 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'); if (response.ok) { setData(await response.json()); } }, []); 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 (
{t('sharedName')} {t('userEmail')} {t('userAdmin')} {t('sharedDisabled')} {data.map((item) => ( handleMenuOpen(event, item.id)}> {formatter(item, 'name')} {formatter(item, 'email')} {formatter(item, 'administrator')} {formatter(item, 'disabled')} ))}
{t('sharedEdit')} {t('sharedRemove')}
); } export default UsersPage;