From b318cfd66ee2fa9918797fc0e0226a01983da746 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 20 Sep 2020 23:13:11 -0700 Subject: Implement users editing --- modern/src/admin/UsersPage.js | 114 ++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 72 deletions(-) (limited to 'modern/src/admin') diff --git a/modern/src/admin/UsersPage.js b/modern/src/admin/UsersPage.js index 85ee2488..529cdc64 100644 --- a/modern/src/admin/UsersPage.js +++ b/modern/src/admin/UsersPage.js @@ -1,12 +1,12 @@ 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 { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton } from '@material-ui/core'; import MoreVertIcon from '@material-ui/icons/MoreVert'; import t from '../common/localization'; import formatter from '../common/formatter'; import { useEffectAsync } from '../reactHelper'; +import EditCollectionView from '../EditCollectionView'; const useStyles = makeStyles(theme => ({ root: { @@ -16,90 +16,60 @@ const useStyles = makeStyles(theme => ({ 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 UsersView = ({ updateTimestamp, onMenuClick }) => { const classes = useStyles(); - const [data, setData] = useState([]); - const [menuItemId, setMenuItemId] = useState(null); - const [menuAnchorEl, setMenuAnchorEl] = useState(null); + + const [items, setItems] = useState([]); useEffectAsync(async () => { const response = await fetch('/api/users'); if (response.ok) { - setData(await response.json()); + setItems(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(); - } + }, [updateTimestamp]); - const handleMenuRemove = () => { - //setRemoveDialogOpen(true); - handleMenuClose(); - } + return ( + + + + + + {t('sharedName')} + {t('userEmail')} + {t('userAdmin')} + {t('sharedDisabled')} + + + + {items.map((item) => ( + + + onMenuClick(event.currentTarget, item.id)}> + + + + {formatter(item, 'name')} + {formatter(item, 'email')} + {formatter(item, 'administrator')} + {formatter(item, 'disabled')} + + ))} + +
+
+ ); +} - const handleAdd = () => { - history.push('/user'); - //handleMenuClose(); - } +const UsersPage = () => { + const history = useHistory(); + const classes = useStyles(); 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')} - +
); } -- cgit v1.2.3