Merge pull request #2573 from luismsousa/feat/notifications-delete

Notification channel Delete:
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-07-07 15:25:55 -07:00
commit 961c398690
4 files changed
+51 -17

No files matched your search

+4 -2
View File
@@ -65,14 +65,16 @@ const useDeleteNotification = () => {
const [error, setError] = useState(null); const [error, setError] = useState(null);
const { t } = useTranslation(); const { t } = useTranslation();
const deleteNotification = async (id, triggerUpdate) => { const deleteNotification = async (id, callback) => {
try { try {
setIsLoading(true); setIsLoading(true);
await networkService.deleteNotificationById({ id }); await networkService.deleteNotificationById({ id });
createToast({ createToast({
body: t("notifications.delete.success"), body: t("notifications.delete.success"),
}); });
triggerUpdate(); if (callback) {
callback();
}
} catch (error) { } catch (error) {
setError(error); setError(error);
createToast({ createToast({
@@ -9,20 +9,24 @@ import { useState } from "react";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
const ActionMenu = ({ notification, onDelete }) => { const ActionMenu = ({ notification, onDelete }) => {
const theme = useTheme(); const theme = useTheme();
const navigate = useNavigate(); const navigate = useNavigate();
const [anchorEl, setAnchorEl] = useState(null); const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl); const open = Boolean(anchorEl);
const { t } = useTranslation();
// Handlers // Handlers
const handleClick = (event) => { const handleClick = (event) => {
event.stopPropagation(); event.stopPropagation();
setAnchorEl(event.currentTarget); setAnchorEl(event.currentTarget);
}; };
const handleClose = () => { const handleClose = (event) => {
if (event) {
event.stopPropagation();
}
setAnchorEl(null); setAnchorEl(null);
}; };
@@ -32,7 +36,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 +45,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,13 +57,15 @@ 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}>{t("configure")}</MenuItem>
<MenuItem <MenuItem
onClick={handleRemove} onClick={handleRemove}
sx={{ "&.MuiButtonBase-root": { color: theme.palette.error.main } }} sx={{ "&.MuiButtonBase-root": { color: theme.palette.error.main } }}
> >
Remove {t("delete")}
</MenuItem> </MenuItem>
</Menu> </Menu>
</> </>
@@ -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,19 @@ 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] = useCreateNotification();
useCreateNotification(); const [editNotification, isEditing] = useEditNotification();
const [editNotification, isEditing, editNotificationError] = useEditNotification(); const [testNotification, isTesting] = useTestNotification();
const [testNotification, isTesting, testNotificationError] = useTestNotification(); const [deleteNotification, isDeleting] = 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
@@ -55,7 +60,7 @@ const CreateNotifications = () => {
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const { t } = useTranslation(); const { t } = useTranslation();
const [notificationIsLoading, getNotificationError] = useGetNotificationById( const [notificationIsLoading] = useGetNotificationById(
notificationId, notificationId,
setNotification setNotification
); );
@@ -128,6 +133,12 @@ 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)}>
@@ -209,15 +220,25 @@ const CreateNotifications = () => {
color="secondary" color="secondary"
onClick={onTestNotification} onClick={onTestNotification}
> >
Test notification {t("testNotification")}
</Button> </Button>
{notificationId && (
<Button
loading={isDeleting}
variant="contained"
color="error"
onClick={onDelete}
>
{t("delete")}
</Button>
)}
<Button <Button
loading={isCreating || isEditing || notificationIsLoading} loading={isCreating || isEditing || notificationIsLoading}
type="submit" type="submit"
variant="contained" variant="contained"
color="accent" color="accent"
> >
Submit {t("submit")}
</Button> </Button>
</Stack> </Stack>
</Stack> </Stack>
+3
View File
@@ -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