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 e19ccecae..d57ad931f 100644
--- a/client/src/Pages/Notifications/components/ActionMenu.jsx
+++ b/client/src/Pages/Notifications/components/ActionMenu.jsx
@@ -9,20 +9,24 @@ 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();
setAnchorEl(event.currentTarget);
};
- const handleClose = () => {
+ const handleClose = (event) => {
+ if (event) {
+ event.stopPropagation();
+ }
setAnchorEl(null);
};
@@ -32,7 +36,8 @@ const ActionMenu = ({ notification, onDelete }) => {
handleClose();
};
- const handleConfigure = () => {
+ const handleConfigure = (e) => {
+ e.stopPropagation();
navigate(`/notifications/${notification._id}`);
handleClose();
};
@@ -40,8 +45,9 @@ const ActionMenu = ({ notification, onDelete }) => {
return (
<>
e.stopPropagation()}
>
@@ -51,13 +57,15 @@ const ActionMenu = ({ notification, onDelete }) => {
open={open}
onClose={handleClose}
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
+ onClick={(e) => e.stopPropagation()}
+ onMouseDown={(e) => e.stopPropagation()}
>
-
+
>
diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx
index 0fb6cce08..9ef958abb 100644
--- a/client/src/Pages/Notifications/create/index.jsx
+++ b/client/src/Pages/Notifications/create/index.jsx
@@ -16,11 +16,12 @@ import {
useGetNotificationById,
useEditNotification,
useTestNotification,
+ useDeleteNotification,
} from "../../../Hooks/useNotifications";
import { notificationValidation } from "../../../Validation/validation";
import { createToast } from "../../../Utils/toastUtils";
import { useTranslation } from "react-i18next";
-import { useParams } from "react-router-dom";
+import { useParams, useNavigate } from "react-router-dom";
import {
NOTIFICATION_TYPES,
TITLE_MAP,
@@ -33,15 +34,19 @@ import {
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 [createNotification, isCreating] = useCreateNotification();
+ const [editNotification, isEditing] = useEditNotification();
+ const [testNotification, isTesting] = useTestNotification();
+ const [deleteNotification, isDeleting] = useDeleteNotification();
const BREADCRUMBS = [
{ name: "notifications", path: "/notifications" },
- { name: "create", path: "/notifications/create" },
+ {
+ name: notificationId ? "edit" : "create",
+ path: notificationId ? `/notifications/${notificationId}` : "/notifications/create",
+ },
];
// Redux state
@@ -55,7 +60,7 @@ const CreateNotifications = () => {
const [errors, setErrors] = useState({});
const { t } = useTranslation();
- const [notificationIsLoading, getNotificationError] = useGetNotificationById(
+ const [notificationIsLoading] = useGetNotificationById(
notificationId,
setNotification
);
@@ -128,6 +133,12 @@ const CreateNotifications = () => {
testNotification(form);
};
+ const onDelete = () => {
+ if (notificationId) {
+ deleteNotification(notificationId, () => navigate("/notifications"));
+ }
+ };
+
const type = NOTIFICATION_TYPES.find((type) => type._id === notification.type).value;
return (
@@ -209,15 +220,25 @@ const CreateNotifications = () => {
color="secondary"
onClick={onTestNotification}
>
- Test notification
+ {t("testNotification")}
+ {notificationId && (
+
+ )}
diff --git a/client/src/Pages/Notifications/index.jsx b/client/src/Pages/Notifications/index.jsx
index f744d31e8..28feb99ea 100644
--- a/client/src/Pages/Notifications/index.jsx
+++ b/client/src/Pages/Notifications/index.jsx
@@ -62,6 +62,9 @@ const Notifications = () => {
{
id: "actions",
content: "Actions",
+ onClick: (e) => {
+ e.stopPropagation();
+ },
render: (row) => {
return (