Notification channel Delete:
attempt to add the delete button to the notifications view
This commit is contained in:
3 files changed
+36
-5
No files matched your search
@@ -22,7 +22,10 @@ const ActionMenu = ({ notification, onDelete }) => {
|
|||||||
setAnchorEl(event.currentTarget);
|
setAnchorEl(event.currentTarget);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = (event) => {
|
||||||
|
if (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,7 +35,8 @@ const ActionMenu = ({ notification, onDelete }) => {
|
|||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleConfigure = () => {
|
const handleConfigure = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
navigate(`/notifications/${notification._id}`);
|
navigate(`/notifications/${notification._id}`);
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
@@ -40,8 +44,9 @@ const ActionMenu = ({ notification, onDelete }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="monitor actions"
|
aria-label="notification actions"
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
|
onMouseDown={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<SettingsOutlinedIcon />
|
<SettingsOutlinedIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -51,6 +56,8 @@ const ActionMenu = ({ notification, onDelete }) => {
|
|||||||
open={open}
|
open={open}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
onMouseDown={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<MenuItem onClick={handleConfigure}>Configure</MenuItem>
|
<MenuItem onClick={handleConfigure}>Configure</MenuItem>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ import {
|
|||||||
useGetNotificationById,
|
useGetNotificationById,
|
||||||
useEditNotification,
|
useEditNotification,
|
||||||
useTestNotification,
|
useTestNotification,
|
||||||
|
useDeleteNotification,
|
||||||
} from "../../../Hooks/useNotifications";
|
} from "../../../Hooks/useNotifications";
|
||||||
import { notificationValidation } from "../../../Validation/validation";
|
import { notificationValidation } from "../../../Validation/validation";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams, useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
NOTIFICATION_TYPES,
|
NOTIFICATION_TYPES,
|
||||||
TITLE_MAP,
|
TITLE_MAP,
|
||||||
@@ -33,15 +34,17 @@ import {
|
|||||||
|
|
||||||
const CreateNotifications = () => {
|
const CreateNotifications = () => {
|
||||||
const { notificationId } = useParams();
|
const { notificationId } = useParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [createNotification, isCreating, createNotificationError] =
|
const [createNotification, isCreating, createNotificationError] =
|
||||||
useCreateNotification();
|
useCreateNotification();
|
||||||
const [editNotification, isEditing, editNotificationError] = useEditNotification();
|
const [editNotification, isEditing, editNotificationError] = useEditNotification();
|
||||||
const [testNotification, isTesting, testNotificationError] = useTestNotification();
|
const [testNotification, isTesting, testNotificationError] = useTestNotification();
|
||||||
|
const [deleteNotification, isDeleting, deleteError] = useDeleteNotification();
|
||||||
|
|
||||||
const BREADCRUMBS = [
|
const BREADCRUMBS = [
|
||||||
{ name: "notifications", path: "/notifications" },
|
{ name: "notifications", path: "/notifications" },
|
||||||
{ name: "create", path: "/notifications/create" },
|
{ name: notificationId ? "edit" : "create", path: notificationId ? `/notifications/${notificationId}` : "/notifications/create" },
|
||||||
];
|
];
|
||||||
|
|
||||||
// Redux state
|
// Redux state
|
||||||
@@ -128,6 +131,14 @@ const CreateNotifications = () => {
|
|||||||
testNotification(form);
|
testNotification(form);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onDelete = () => {
|
||||||
|
if (notificationId) {
|
||||||
|
deleteNotification(notificationId, () => {
|
||||||
|
navigate("/notifications");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const type = NOTIFICATION_TYPES.find((type) => type._id === notification.type).value;
|
const type = NOTIFICATION_TYPES.find((type) => type._id === notification.type).value;
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(10)}>
|
<Stack gap={theme.spacing(10)}>
|
||||||
@@ -211,6 +222,16 @@ const CreateNotifications = () => {
|
|||||||
>
|
>
|
||||||
Test notification
|
Test notification
|
||||||
</Button>
|
</Button>
|
||||||
|
{notificationId && (
|
||||||
|
<Button
|
||||||
|
loading={isDeleting}
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
onClick={onDelete}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
loading={isCreating || isEditing || notificationIsLoading}
|
loading={isCreating || isEditing || notificationIsLoading}
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ const Notifications = () => {
|
|||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
content: "Actions",
|
content: "Actions",
|
||||||
|
onClick: (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
},
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
return (
|
return (
|
||||||
<ActionMenu
|
<ActionMenu
|
||||||
|
|||||||
Reference in new issue
Block a user