-
-
Notifications
You must be signed in to change notification settings - Fork 658
/
GroupCardActions.tsx
129 lines (122 loc) · 4.06 KB
/
GroupCardActions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { FC, useState } from 'react';
import {
IconButton,
ListItemIcon,
ListItemText,
MenuItem,
MenuList,
Popover,
styled,
Tooltip,
Typography,
} from '@mui/material';
import Delete from '@mui/icons-material/Delete';
import Edit from '@mui/icons-material/Edit';
import GroupRounded from '@mui/icons-material/GroupRounded';
import MoreVert from '@mui/icons-material/MoreVert';
import { Link } from 'react-router-dom';
const StyledActions = styled('div')(({ theme }) => ({
display: 'flex',
justifyContent: 'center',
transform: 'translate3d(8px, -6px, 0)',
}));
const StyledPopover = styled(Popover)(({ theme }) => ({
borderRadius: theme.shape.borderRadiusLarge,
padding: theme.spacing(1, 1.5),
}));
interface IGroupCardActions {
groupId: number;
onEditUsers: () => void;
onRemove: () => void;
}
export const GroupCardActions: FC<IGroupCardActions> = ({
groupId,
onEditUsers,
onRemove,
}) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const id = `feature-${groupId}-actions`;
const menuId = `${id}-menu`;
return (
<StyledActions
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
>
<Tooltip title='Group actions' arrow describeChild>
<IconButton
id={id}
aria-controls={open ? menuId : undefined}
aria-haspopup='true'
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
type='button'
>
<MoreVert />
</IconButton>
</Tooltip>
<StyledPopover
id={menuId}
anchorEl={anchorEl}
open={open}
onClose={handleClose}
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
disableScrollLock={true}
>
<MenuList aria-labelledby={id}>
<MenuItem
onClick={handleClose}
component={Link}
to={`/admin/groups/${groupId}/edit`}
>
<ListItemIcon>
<Edit />
</ListItemIcon>
<ListItemText>
<Typography variant='body2'>Edit group</Typography>
</ListItemText>
</MenuItem>
<MenuItem
onClick={() => {
onEditUsers();
handleClose();
}}
>
<ListItemIcon>
<GroupRounded />
</ListItemIcon>
<ListItemText>
<Typography variant='body2'>
Edit group users
</Typography>
</ListItemText>
</MenuItem>
<MenuItem
onClick={() => {
onRemove();
handleClose();
}}
>
<ListItemIcon>
<Delete />
</ListItemIcon>
<ListItemText>
<Typography variant='body2'>
Delete group
</Typography>
</ListItemText>
</MenuItem>
</MenuList>
</StyledPopover>
</StyledActions>
);
};