From 85b13686a4ff299699f3c3e17ac0f742bcfc9122 Mon Sep 17 00:00:00 2001 From: Luis Sousa Date: Wed, 2 Jul 2025 17:14:39 +0100 Subject: [PATCH] Notification channel Delete: attempt to add the delete button to the notifications view --- .../Notifications/components/ActionMenu.jsx | 13 +++++++--- .../src/Pages/Notifications/create/index.jsx | 25 +++++++++++++++++-- client/src/Pages/Notifications/index.jsx | 3 +++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/client/src/Pages/Notifications/components/ActionMenu.jsx b/client/src/Pages/Notifications/components/ActionMenu.jsx index e19ccecae..a26a9412d 100644 --- a/client/src/Pages/Notifications/components/ActionMenu.jsx +++ b/client/src/Pages/Notifications/components/ActionMenu.jsx @@ -22,7 +22,10 @@ const ActionMenu = ({ notification, onDelete }) => { setAnchorEl(event.currentTarget); }; - const handleClose = () => { + const handleClose = (event) => { + if (event) { + event.stopPropagation(); + } setAnchorEl(null); }; @@ -32,7 +35,8 @@ const ActionMenu = ({ notification, onDelete }) => { handleClose(); }; - const handleConfigure = () => { + const handleConfigure = (e) => { + e.stopPropagation(); navigate(`/notifications/${notification._id}`); handleClose(); }; @@ -40,8 +44,9 @@ const ActionMenu = ({ notification, onDelete }) => { return ( <> e.stopPropagation()} > @@ -51,6 +56,8 @@ const ActionMenu = ({ notification, onDelete }) => { open={open} onClose={handleClose} anchorOrigin={{ vertical: "bottom", horizontal: "right" }} + onClick={(e) => e.stopPropagation()} + onMouseDown={(e) => e.stopPropagation()} > Configure { const { notificationId } = useParams(); + const navigate = useNavigate(); const theme = useTheme(); const [createNotification, isCreating, createNotificationError] = useCreateNotification(); const [editNotification, isEditing, editNotificationError] = useEditNotification(); const [testNotification, isTesting, testNotificationError] = useTestNotification(); + const [deleteNotification, isDeleting, deleteError] = useDeleteNotification(); const BREADCRUMBS = [ { name: "notifications", path: "/notifications" }, - { name: "create", path: "/notifications/create" }, + { name: notificationId ? "edit" : "create", path: notificationId ? `/notifications/${notificationId}` : "/notifications/create" }, ]; // Redux state @@ -128,6 +131,14 @@ const CreateNotifications = () => { testNotification(form); }; + const onDelete = () => { + if (notificationId) { + deleteNotification(notificationId, () => { + navigate("/notifications"); + }); + } + }; + const type = NOTIFICATION_TYPES.find((type) => type._id === notification.type).value; return ( @@ -211,6 +222,16 @@ const CreateNotifications = () => { > Test notification + {notificationId && ( + + )}