import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import { Table, type Header, ValueLabel } from "@/Components/design-elements"; import { Pagination } from "@/Components/design-elements/Table"; import { ActionsMenu, type ActionMenuItem } from "@/Components/actions-menu"; import { useClientPagination } from "@/Hooks/useClientPagination"; import { ExternalLink } from "lucide-react"; import { useTranslation } from "react-i18next"; import { useTheme } from "@mui/material/styles"; import { useNavigate } from "react-router-dom"; import { getStatusPagePublicPath, getStatusPagePublicUrl } from "@/Utils/statusPageUrl"; import { type StatusPage } from "@/Types/StatusPage"; interface StatusPagesTableProps { data: StatusPage[]; setSelectedStatusPage: (statusPage: StatusPage | null) => void; } export const StatusPagesTable = ({ data, setSelectedStatusPage, }: StatusPagesTableProps) => { const { t } = useTranslation(); const theme = useTheme(); const navigate = useNavigate(); const { pagedRows, paginationProps } = useClientPagination(data); const getActions = (row: StatusPage): ActionMenuItem[] => { return [ { id: 1, label: t("common.buttons.configure"), action: () => { navigate(`/status/configure/${row.url}`); }, closeMenu: true, }, { id: 2, label: ( {t("common.buttons.delete")} ), action: () => setSelectedStatusPage(row), closeMenu: true, }, ]; }; const handleUrlClick = (e: React.MouseEvent, row: StatusPage) => { if (row.isPublished) { e.stopPropagation(); window.open(getStatusPagePublicUrl(row), "_blank", "noopener,noreferrer"); } }; const getHeaders = (): Header[] => { return [ { id: "name", content: t("pages.statusPages.table.headers.name"), render: (row) => row.companyName, }, { id: "url", content: t("pages.statusPages.table.headers.url"), render: (row) => { const content = row.isPublished ? row.customDomain ? getStatusPagePublicPath(row) : `/${row.url}` : t("pages.statusPages.table.unpublished"); return ( handleUrlClick(e, row)} sx={{ ...(row.isPublished && { display: "inline-flex", ":hover": { cursor: "pointer", borderBottom: 1, }, }), }} > {content} {row.isPublished && } ); }, }, { id: "type", content: t("common.table.headers.type"), render: (row) => row.type.join(", "), }, { id: "status", content: t("common.table.headers.status"), render: (row) => { return ( ); }, }, { id: "actions", content: t("common.table.headers.actions"), render: (row) => { return ; }, }, ]; }; const handleRowClick = (statusPage: StatusPage) => { navigate(`/status/${statusPage.url}`); }; return ( {data.length > 0 && } ); }; export default StatusPagesTable;