2025-06-10 11:13:19 +08:00
|
|
|
// Components
|
|
|
|
|
import Menu from "@mui/material/Menu";
|
|
|
|
|
import IconButton from "@mui/material/IconButton";
|
|
|
|
|
import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined";
|
|
|
|
|
import MenuItem from "@mui/material/MenuItem";
|
|
|
|
|
|
|
|
|
|
// Utils
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { useTheme } from "@emotion/react";
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
|
|
|
|
|
const ActionMenu = ({ notification, onDelete }) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
|
|
|
const open = Boolean(anchorEl);
|
|
|
|
|
|
|
|
|
|
// Handlers
|
|
|
|
|
const handleClick = (event) => {
|
2025-06-26 09:14:18 +08:00
|
|
|
event.stopPropagation();
|
2025-06-10 11:13:19 +08:00
|
|
|
setAnchorEl(event.currentTarget);
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-02 17:14:39 +01:00
|
|
|
const handleClose = (event) => {
|
|
|
|
|
if (event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
}
|
2025-06-10 11:13:19 +08:00
|
|
|
setAnchorEl(null);
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-26 11:46:50 +08:00
|
|
|
const handleRemove = (e) => {
|
|
|
|
|
e.stopPropagation();
|
2025-06-10 11:13:19 +08:00
|
|
|
onDelete(notification._id);
|
|
|
|
|
handleClose();
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-02 17:14:39 +01:00
|
|
|
const handleConfigure = (e) => {
|
|
|
|
|
e.stopPropagation();
|
2025-06-10 11:13:19 +08:00
|
|
|
navigate(`/notifications/${notification._id}`);
|
|
|
|
|
handleClose();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<IconButton
|
2025-07-02 17:14:39 +01:00
|
|
|
aria-label="notification actions"
|
2025-06-10 11:13:19 +08:00
|
|
|
onClick={handleClick}
|
2025-07-02 17:14:39 +01:00
|
|
|
onMouseDown={(e) => e.stopPropagation()}
|
2025-06-10 11:13:19 +08:00
|
|
|
>
|
|
|
|
|
<SettingsOutlinedIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
|
|
<Menu
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
2025-07-02 17:14:39 +01:00
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
onMouseDown={(e) => e.stopPropagation()}
|
2025-06-10 11:13:19 +08:00
|
|
|
>
|
|
|
|
|
<MenuItem onClick={handleConfigure}>Configure</MenuItem>
|
|
|
|
|
<MenuItem
|
|
|
|
|
onClick={handleRemove}
|
|
|
|
|
sx={{ "&.MuiButtonBase-root": { color: theme.palette.error.main } }}
|
|
|
|
|
>
|
|
|
|
|
Remove
|
|
|
|
|
</MenuItem>
|
|
|
|
|
</Menu>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ActionMenu.propTypes = {
|
|
|
|
|
notification: PropTypes.object,
|
|
|
|
|
onDelete: PropTypes.func,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActionMenu;
|