From 85b13686a4ff299699f3c3e17ac0f742bcfc9122 Mon Sep 17 00:00:00 2001 From: Luis Sousa Date: Wed, 2 Jul 2025 17:14:39 +0100 Subject: [PATCH 1/6] 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 && ( + + )} {notificationId && ( )} From d5262a1968ff468486e32ff697e9df0bcd7003eb Mon Sep 17 00:00:00 2001 From: Luis Sousa Date: Wed, 2 Jul 2025 23:18:34 +0100 Subject: [PATCH 4/6] add i18n for the notifications dropdown menu in the list. --- client/src/Pages/Notifications/components/ActionMenu.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/Pages/Notifications/components/ActionMenu.jsx b/client/src/Pages/Notifications/components/ActionMenu.jsx index a26a9412d..fb971500b 100644 --- a/client/src/Pages/Notifications/components/ActionMenu.jsx +++ b/client/src/Pages/Notifications/components/ActionMenu.jsx @@ -9,13 +9,14 @@ import { useState } from "react"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; +import { useTranslation } from "react-i18next"; const ActionMenu = ({ notification, onDelete }) => { const theme = useTheme(); const navigate = useNavigate(); const [anchorEl, setAnchorEl] = useState(null); const open = Boolean(anchorEl); - + const { t } = useTranslation(); // Handlers const handleClick = (event) => { event.stopPropagation(); @@ -59,12 +60,12 @@ const ActionMenu = ({ notification, onDelete }) => { onClick={(e) => e.stopPropagation()} onMouseDown={(e) => e.stopPropagation()} > - Configure + {t("configure", "Configure")} - Remove + {t("delete", "Delete")} From 292c7fd7eadfb40807bfefc2ee075afc56400172 Mon Sep 17 00:00:00 2001 From: Luis Sousa Date: Fri, 4 Jul 2025 11:53:25 +0100 Subject: [PATCH 5/6] address PR feedback --- client/src/Hooks/useNotifications.js | 6 +++-- .../Notifications/components/ActionMenu.jsx | 4 ++-- .../src/Pages/Notifications/create/index.jsx | 23 +++++-------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/client/src/Hooks/useNotifications.js b/client/src/Hooks/useNotifications.js index cc6c3e875..7feebd44c 100644 --- a/client/src/Hooks/useNotifications.js +++ b/client/src/Hooks/useNotifications.js @@ -65,14 +65,16 @@ const useDeleteNotification = () => { const [error, setError] = useState(null); const { t } = useTranslation(); - const deleteNotification = async (id, triggerUpdate) => { + const deleteNotification = async (id, callback) => { try { setIsLoading(true); await networkService.deleteNotificationById({ id }); createToast({ body: t("notifications.delete.success"), }); - triggerUpdate(); + if (callback) { + callback(); + } } catch (error) { setError(error); createToast({ diff --git a/client/src/Pages/Notifications/components/ActionMenu.jsx b/client/src/Pages/Notifications/components/ActionMenu.jsx index fb971500b..d57ad931f 100644 --- a/client/src/Pages/Notifications/components/ActionMenu.jsx +++ b/client/src/Pages/Notifications/components/ActionMenu.jsx @@ -60,12 +60,12 @@ const ActionMenu = ({ notification, onDelete }) => { onClick={(e) => e.stopPropagation()} onMouseDown={(e) => e.stopPropagation()} > - {t("configure", "Configure")} + {t("configure")} - {t("delete", "Delete")} + {t("delete")} diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx index ec244db29..8b7c4ccf5 100644 --- a/client/src/Pages/Notifications/create/index.jsx +++ b/client/src/Pages/Notifications/create/index.jsx @@ -36,11 +36,10 @@ const CreateNotifications = () => { 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 [createNotification, isCreating] = useCreateNotification(); + const [editNotification, isEditing] = useEditNotification(); + const [testNotification, isTesting] = useTestNotification(); + const [deleteNotification, isDeleting] = useDeleteNotification(); const BREADCRUMBS = [ { name: "notifications", path: "/notifications" }, @@ -61,7 +60,7 @@ const CreateNotifications = () => { const [errors, setErrors] = useState({}); const { t } = useTranslation(); - const [notificationIsLoading, getNotificationError] = useGetNotificationById( + const [notificationIsLoading] = useGetNotificationById( notificationId, setNotification ); @@ -136,17 +135,7 @@ const CreateNotifications = () => { const onDelete = () => { if (notificationId) { - deleteNotification( - notificationId, - () => navigate("/notifications"), // Success callback - (error) => { - // Error handling - createToast({ - body: `Delete failed: ${error.message}`, - type: "error", - }); - } - ); + deleteNotification(notificationId, () => navigate("/notifications")); } }; From 9954a74dfdc601f7eb44201792699bc87efe7b66 Mon Sep 17 00:00:00 2001 From: Luis Sousa Date: Mon, 7 Jul 2025 20:08:34 +0100 Subject: [PATCH 6/6] bleep boop fix translations --- client/src/Pages/Notifications/create/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx index 8b7c4ccf5..9ef958abb 100644 --- a/client/src/Pages/Notifications/create/index.jsx +++ b/client/src/Pages/Notifications/create/index.jsx @@ -220,7 +220,7 @@ const CreateNotifications = () => { color="secondary" onClick={onTestNotification} > - {t("testNotification", "Test notification")} + {t("testNotification")} {notificationId && ( )}