Merge pull request #3221 from bluewave-labs/feat/v2-notifications
Feat/v2 notifications
This commit is contained in:
7 files changed
+209
-206
No files matched your search
@@ -1,83 +0,0 @@
|
||||
// Components
|
||||
import Menu from "@mui/material/Menu";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Icon from "@/Components/v1/Icon";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
|
||||
// Utils
|
||||
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 = (event) => {
|
||||
if (event) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const handleRemove = (e) => {
|
||||
e.stopPropagation();
|
||||
onDelete(notification.id);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleConfigure = (e) => {
|
||||
e.stopPropagation();
|
||||
navigate(`/notifications/${notification.id}`);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconButton
|
||||
aria-label="notification actions"
|
||||
onClick={handleClick}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Icon
|
||||
name="Settings"
|
||||
size={20}
|
||||
/>
|
||||
</IconButton>
|
||||
|
||||
<Menu
|
||||
anchorEl={anchorEl}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onMouseDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<MenuItem onClick={handleConfigure}>{t("configure")}</MenuItem>
|
||||
<MenuItem
|
||||
onClick={handleRemove}
|
||||
sx={{ "&.MuiButtonBase-root": { color: theme.palette.error.main } }}
|
||||
>
|
||||
{t("delete")}
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
ActionMenu.propTypes = {
|
||||
notification: PropTypes.object,
|
||||
onDelete: PropTypes.func,
|
||||
};
|
||||
|
||||
export default ActionMenu;
|
||||
@@ -0,0 +1,96 @@
|
||||
import { ActionsMenu, type ActionMenuItem } from "@/Components/v2/actions-menu";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import type { Header } from "@/Components/v2/design-elements/Table";
|
||||
import { Table } from "@/Components/v2/design-elements";
|
||||
|
||||
import type { Notification } from "@/Types/Notification";
|
||||
import { useNavigate } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@mui/material";
|
||||
|
||||
interface NotificationsTableProps {
|
||||
notifications: Notification[];
|
||||
setSelectedChannel: Function;
|
||||
}
|
||||
|
||||
export const NotificationsTable = ({
|
||||
notifications,
|
||||
setSelectedChannel,
|
||||
}: NotificationsTableProps) => {
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
const getActions = (channel: Notification): ActionMenuItem[] => {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
label: t("pages.common.monitors.actions.configure"),
|
||||
action: () => {
|
||||
navigate(`/notifications/${channel.id}`);
|
||||
},
|
||||
closeMenu: true,
|
||||
},
|
||||
|
||||
{
|
||||
id: 7,
|
||||
label: (
|
||||
<Typography color={theme.palette.error.main}>
|
||||
{t("pages.common.monitors.actions.delete")}
|
||||
</Typography>
|
||||
),
|
||||
action: async () => {
|
||||
setSelectedChannel(channel);
|
||||
},
|
||||
closeMenu: true,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const getHeaders = () => {
|
||||
const headers: Header<Notification>[] = [
|
||||
{
|
||||
id: "name",
|
||||
content: t("common.table.headers.name"),
|
||||
render: (row) => {
|
||||
return <Typography>{row?.notificationName}</Typography>;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
id: "type",
|
||||
content: t("common.table.headers.type"),
|
||||
render: (row) => {
|
||||
return <Typography textTransform={"capitalize"}>{row?.type}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "destination",
|
||||
content: t("pages.notifications.table.headers.destination"),
|
||||
render: (row) => {
|
||||
return <Typography>{row?.address}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
content: t("common.table.headers.actions"),
|
||||
render: (row) => {
|
||||
return <ActionsMenu items={getActions(row)} />;
|
||||
},
|
||||
},
|
||||
];
|
||||
return headers;
|
||||
};
|
||||
|
||||
const headers = getHeaders();
|
||||
|
||||
return (
|
||||
<Table
|
||||
headers={headers}
|
||||
data={notifications}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/notifications/${row.id}`);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -1,121 +0,0 @@
|
||||
// Components
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
|
||||
import Button from "@mui/material/Button";
|
||||
import DataTable from "@/Components/v1/Table/index.jsx";
|
||||
import ActionMenu from "./components/ActionMenu.jsx";
|
||||
import PageStateWrapper from "@/Components/v1/PageStateWrapper/index.jsx";
|
||||
|
||||
// Utils
|
||||
import { useState } from "react";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import {
|
||||
useGetNotificationsByTeamId,
|
||||
useDeleteNotification,
|
||||
} from "../../Hooks/useNotifications.js";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const Notifications = () => {
|
||||
const navigate = useNavigate();
|
||||
const theme = useTheme();
|
||||
const BREADCRUMBS = [{ name: "notifications", path: "/notifications" }];
|
||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||
const [notifications, isLoading, error] = useGetNotificationsByTeamId(updateTrigger);
|
||||
const [deleteNotification, isDeleting, deleteError] = useDeleteNotification();
|
||||
const { t } = useTranslation();
|
||||
// Handlers
|
||||
const triggerUpdate = () => {
|
||||
setUpdateTrigger(!updateTrigger);
|
||||
};
|
||||
|
||||
const onDelete = (id) => {
|
||||
deleteNotification(id, triggerUpdate);
|
||||
};
|
||||
|
||||
const headers = [
|
||||
{
|
||||
id: "name",
|
||||
content: "Name",
|
||||
render: (row) => {
|
||||
return row.notificationName;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "target",
|
||||
content: "Target",
|
||||
render: (row) => {
|
||||
return row.address;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "platform",
|
||||
content: "Platform",
|
||||
render: (row) => {
|
||||
return row?.config?.platform || row.type;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
id: "actions",
|
||||
content: "Actions",
|
||||
onClick: (e) => {
|
||||
e.stopPropagation();
|
||||
},
|
||||
render: (row) => {
|
||||
return (
|
||||
<ActionMenu
|
||||
notification={row}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageStateWrapper
|
||||
networkError={error}
|
||||
isLoading={isLoading}
|
||||
items={notifications}
|
||||
type="notifications"
|
||||
fallbackLink="/notifications/create"
|
||||
>
|
||||
<Stack gap={theme.spacing(10)}>
|
||||
<Breadcrumbs list={BREADCRUMBS} />
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="flex-end"
|
||||
>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="accent"
|
||||
onClick={() => navigate("/notifications/create")}
|
||||
>
|
||||
{t("notifications.createButton")}
|
||||
</Button>
|
||||
</Stack>
|
||||
<Typography variant="h1">{t("notifications.createTitle")}</Typography>
|
||||
<DataTable
|
||||
config={{
|
||||
onRowClick: (row) => navigate(`/notifications/${row.id}`),
|
||||
rowSX: {
|
||||
cursor: "pointer",
|
||||
"&:hover td": {
|
||||
backgroundColor: theme.palette.tertiary.main,
|
||||
transition: "background-color .3s ease",
|
||||
},
|
||||
},
|
||||
}}
|
||||
headers={headers}
|
||||
data={notifications}
|
||||
/>
|
||||
</Stack>
|
||||
</PageStateWrapper>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Notifications;
|
||||
@@ -0,0 +1,65 @@
|
||||
import { BasePageWithStates } from "@/Components/v2/design-elements";
|
||||
import { NotificationsTable } from "@/Pages/Notifications/components/NotificationsTable";
|
||||
import { Dialog } from "@/Components/v2/inputs";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useGet, useDelete } from "@/Hooks/UseApi";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { Notification } from "@/Types/Notification";
|
||||
|
||||
const NotificationsPage = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [selectedChannel, setSelectedChannel] = useState<Notification | null>(null);
|
||||
const isDialogOpen = Boolean(selectedChannel);
|
||||
|
||||
const {
|
||||
data: notifications,
|
||||
isLoading,
|
||||
isValidating,
|
||||
error,
|
||||
refetch,
|
||||
} = useGet<Notification[]>("/notifications/team", {}, { keepPreviousData: true });
|
||||
|
||||
const { deleteFn, loading: isDeleting } = useDelete();
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!selectedChannel) return;
|
||||
await deleteFn(`/notifications/${selectedChannel.id}`);
|
||||
setSelectedChannel(null);
|
||||
refetch();
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
setSelectedChannel(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<BasePageWithStates
|
||||
page={t("pages.notifications.fallback.title")}
|
||||
bullets={
|
||||
t("pages.notifications.fallback.checks", { returnObjects: true }) as string[]
|
||||
}
|
||||
loading={isLoading || isValidating}
|
||||
error={!!error}
|
||||
items={notifications ?? []}
|
||||
actionButtonText={t("pages.notifications.fallback.actionButton")}
|
||||
actionLink="/notifications/create"
|
||||
>
|
||||
<NotificationsTable
|
||||
notifications={notifications ?? []}
|
||||
setSelectedChannel={setSelectedChannel}
|
||||
/>
|
||||
<Dialog
|
||||
open={isDialogOpen}
|
||||
title={t("common.dialogs.delete.title")}
|
||||
content={t("common.dialogs.delete.description")}
|
||||
onConfirm={handleConfirm}
|
||||
onCancel={handleCancel}
|
||||
loading={isDeleting}
|
||||
/>
|
||||
</BasePageWithStates>
|
||||
);
|
||||
};
|
||||
|
||||
export default NotificationsPage;
|
||||
@@ -43,7 +43,7 @@ import CreateStatus from "../Pages/StatusPage/Create/index.jsx";
|
||||
import StatusPages from "../Pages/StatusPage/StatusPages/index.jsx";
|
||||
import Status from "../Pages/StatusPage/Status/index.jsx";
|
||||
|
||||
import Notifications from "../Pages/Notifications/index.jsx";
|
||||
import Notifications from "../Pages/Notifications";
|
||||
import CreateNotifications from "../Pages/Notifications/create/index.jsx";
|
||||
|
||||
// Settings
|
||||
@@ -210,7 +210,13 @@ const Routes = () => {
|
||||
|
||||
<Route
|
||||
path="notifications"
|
||||
element={<Notifications />}
|
||||
element={
|
||||
<>
|
||||
<ThemeProvider theme={v2theme}>
|
||||
<Notifications />
|
||||
</ThemeProvider>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="notifications/create"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export const NotificationChannels = [
|
||||
"email",
|
||||
"slack",
|
||||
"discord",
|
||||
"webhook",
|
||||
"pager_duty",
|
||||
"matrix",
|
||||
] as const;
|
||||
export type NotificationChannel = (typeof NotificationChannels)[number];
|
||||
|
||||
export interface Notification {
|
||||
id: string;
|
||||
userId: string;
|
||||
teamId: string;
|
||||
type: NotificationChannel;
|
||||
notificationName: string;
|
||||
address?: string;
|
||||
phone?: string;
|
||||
homeserverUrl?: string;
|
||||
roomId?: string;
|
||||
accessToken?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
@@ -327,6 +327,22 @@
|
||||
"netBytesRecv": "{{name}} - Bytes Received"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notifications": {
|
||||
"fallback": {
|
||||
"actionButton": "Create a channel",
|
||||
"checks": [
|
||||
"Alert teams about downtime or performance issues",
|
||||
"Let engineers know when incidents happen",
|
||||
"Keep administrators informed of system changes"
|
||||
],
|
||||
"title": "Notification channles are used to:"
|
||||
},
|
||||
"table": {
|
||||
"headers": {
|
||||
"destination": "Destination"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"incidentsTableNoIncidents": "No incidents recorded",
|
||||
|
||||
Reference in new issue
Block a user