-
Notifications
You must be signed in to change notification settings - Fork 2
/
MoreActionsButton.tsx
78 lines (75 loc) · 2.07 KB
/
MoreActionsButton.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
import * as React from "react";
import {
useDeleteWithConfirmController,
useRecordContext,
Confirm,
} from "react-admin";
import { IconButton, Menu, MenuItem, ListItemIcon } from "@mui/material";
import MoreVertIcon from "@mui/icons-material/MoreVert";
import DeleteIcon from "@mui/icons-material/Delete";
import type { Composition } from "./types";
export const MoreActionsButton = () => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const menuOpen = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const record = useRecordContext<Composition>();
const { open, isLoading, handleDialogOpen, handleDialogClose, handleDelete } =
useDeleteWithConfirmController({
record,
onClick: handleClose,
redirect: "list",
});
return (
<>
<IconButton
aria-controls={open ? "basic-menu" : undefined}
aria-haspopup="true"
aria-expanded={open ? "true" : undefined}
onClick={handleClick}
size="small"
>
<MoreVertIcon fontSize="small" />
</IconButton>
<Menu
id="basic-menu"
anchorEl={anchorEl}
open={menuOpen}
onClose={handleClose}
MenuListProps={{
"aria-labelledby": "basic-button",
}}
>
<MenuItem
onClick={(e) => {
handleClose();
handleDialogOpen(e);
}}
sx={{ color: "error.main" }}
>
<ListItemIcon>
<DeleteIcon color="error" />
</ListItemIcon>
Delete
</MenuItem>
</Menu>
<Confirm
isOpen={open}
loading={isLoading}
title={"ra.message.delete_title"}
content={"ra.message.delete_content"}
confirmColor={"primary"}
translateOptions={{
name: "composition",
id: record?.id,
}}
onConfirm={handleDelete}
onClose={handleDialogClose}
/>
</>
);
};