address PR feedback

This commit is contained in:
Luis Sousa
2025-07-04 11:53:25 +01:00
parent d5262a1968
commit 292c7fd7ea
3 changed files with 12 additions and 21 deletions

View File

@@ -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({

View File

@@ -60,12 +60,12 @@ const ActionMenu = ({ notification, onDelete }) => {
onClick={(e) => e.stopPropagation()}
onMouseDown={(e) => e.stopPropagation()}
>
<MenuItem onClick={handleConfigure}>{t("configure", "Configure")}</MenuItem>
<MenuItem onClick={handleConfigure}>{t("configure")}</MenuItem>
<MenuItem
onClick={handleRemove}
sx={{ "&.MuiButtonBase-root": { color: theme.palette.error.main } }}
>
{t("delete", "Delete")}
{t("delete")}
</MenuItem>
</Menu>
</>

View File

@@ -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"));
}
};