2026-02-20 18:13:39 +00:00
|
|
|
import { ActionsMenu, type ActionMenuItem } from "@/Components/actions-menu";
|
2026-04-26 00:13:23 -04:00
|
|
|
import Box from "@mui/material/Box";
|
2026-01-29 18:14:23 +00:00
|
|
|
import Typography from "@mui/material/Typography";
|
2026-02-20 18:13:39 +00:00
|
|
|
import type { Header } from "@/Components/design-elements/Table";
|
|
|
|
|
import { Table } from "@/Components/design-elements";
|
2026-04-26 00:13:23 -04:00
|
|
|
import { Pagination } from "@/Components/design-elements/Table";
|
2026-01-29 18:14:23 +00:00
|
|
|
|
2026-04-26 00:13:23 -04:00
|
|
|
import { useState } from "react";
|
2026-01-29 18:14:23 +00:00
|
|
|
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();
|
2026-04-26 00:13:23 -04:00
|
|
|
const [page, setPage] = useState(0);
|
|
|
|
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
2026-01-29 18:14:23 +00:00
|
|
|
|
|
|
|
|
const getActions = (channel: Notification): ActionMenuItem[] => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
label: t("pages.common.monitors.actions.configure"),
|
|
|
|
|
action: () => {
|
2026-01-29 21:08:26 +00:00
|
|
|
navigate(`/notifications/configure/${channel.id}`);
|
2026-01-29 18:14:23 +00:00
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
|
|
2026-04-26 00:13:23 -04:00
|
|
|
const handlePageChange = (
|
|
|
|
|
_e: React.MouseEvent<HTMLButtonElement> | null,
|
|
|
|
|
newPage: number
|
|
|
|
|
) => {
|
|
|
|
|
setPage(newPage);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRowsPerPageChange = (
|
|
|
|
|
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
|
|
|
|
) => {
|
|
|
|
|
setPage(0);
|
|
|
|
|
setRowsPerPage(Number(e.target.value));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const pagedNotifications = notifications.slice(
|
|
|
|
|
page * rowsPerPage,
|
|
|
|
|
page * rowsPerPage + rowsPerPage
|
|
|
|
|
);
|
|
|
|
|
|
2026-01-29 18:14:23 +00:00
|
|
|
return (
|
2026-04-26 00:13:23 -04:00
|
|
|
<Box>
|
|
|
|
|
<Table
|
|
|
|
|
headers={headers}
|
|
|
|
|
data={pagedNotifications}
|
|
|
|
|
onRowClick={(row) => {
|
|
|
|
|
navigate(`/notifications/configure/${row.id}`);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{notifications.length > 0 && (
|
|
|
|
|
<Pagination
|
|
|
|
|
component="div"
|
|
|
|
|
count={notifications.length}
|
|
|
|
|
page={page}
|
|
|
|
|
rowsPerPage={rowsPerPage}
|
|
|
|
|
onPageChange={handlePageChange}
|
|
|
|
|
onRowsPerPageChange={handleRowsPerPageChange}
|
|
|
|
|
itemsOnPage={pagedNotifications.length}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2026-01-29 18:14:23 +00:00
|
|
|
);
|
|
|
|
|
};
|