Files
Checkmate/src/Pages/StatusPage/StatusPages/Components/StatusPagesTable/index.jsx
T

110 lines
2.6 KiB
React
Raw Normal View History

2025-02-10 16:17:35 -08:00
import DataTable from "../../../../../Components/Table";
import { useTheme } from "@emotion/react";
import { useNavigate } from "react-router-dom";
import { StatusLabel } from "../../../../../Components/Label";
2025-02-10 16:17:35 -08:00
import ArrowOutwardIcon from "@mui/icons-material/ArrowOutward";
import { Stack, Typography } from "@mui/material";
2025-03-17 01:16:42 +05:30
import { useTranslation } from "react-i18next";
2025-02-10 16:17:35 -08:00
const StatusPagesTable = ({ data }) => {
const theme = useTheme();
2025-03-17 01:16:42 +05:30
const { t } = useTranslation();
2025-02-10 16:17:35 -08:00
const navigate = useNavigate();
const headers = [
{
id: "name",
2025-03-17 01:16:42 +05:30
content: t("statusPageName"),
2025-02-10 16:17:35 -08:00
render: (row) => {
return row.companyName;
},
},
{
id: "url",
2025-03-17 01:16:42 +05:30
content: t("publicURL"),
2025-02-27 11:27:20 -08:00
onClick: (e, row) => {
if (row.isPublished) {
e.stopPropagation();
const url =
row.type === "distributed"
? `/status/distributed/public/${row.url}`
: `/status/uptime/public/${row.url}`;
2025-03-11 13:00:30 +05:30
window.open(url, "_blank", "noopener,noreferrer")
2025-02-27 11:27:20 -08:00
}
},
2025-02-10 16:17:35 -08:00
render: (row) => {
2025-02-27 11:27:20 -08:00
const content = row.isPublished ? `/${row.url}` : "Unpublished";
2025-02-10 16:17:35 -08:00
return (
<Stack
direction="row"
alignItems="center"
2025-02-27 14:21:32 -08:00
justifyContent="center"
2025-02-10 16:17:35 -08:00
gap={theme.spacing(2)}
2025-02-27 14:15:52 -08:00
paddingLeft={theme.spacing(2)}
paddingRight={theme.spacing(2)}
borderRadius={theme.spacing(4)}
sx={{
...(row.isPublished && {
":hover": {
backgroundColor: `${theme.palette.primary.light}`,
cursor: "pointer",
borderRadius: 1,
},
}),
}}
2025-02-10 16:17:35 -08:00
>
2025-02-27 11:27:20 -08:00
<Typography>{content}</Typography>
{row.isPublished && <ArrowOutwardIcon />}
2025-02-10 16:17:35 -08:00
</Stack>
);
},
},
{
id: "type",
2025-03-17 01:16:42 +05:30
content: t("type"),
2025-02-10 16:17:35 -08:00
render: (row) => {
return row.type;
},
},
{
id: "status",
2025-03-17 01:16:42 +05:30
content: t("status"),
2025-02-10 16:17:35 -08:00
render: (row) => {
2025-03-09 09:50:05 +01:00
const status = row.isPublished ? "published" : "unpublished";
2025-02-10 16:17:35 -08:00
return (
<StatusLabel
status={status}
text={row.isPublished ? "Published" : "Unpublished"}
2025-02-10 16:17:35 -08:00
/>
);
},
},
];
const handleRowClick = (statusPage) => {
if (statusPage.type === "distributed") {
navigate(`/status/distributed/${statusPage.url}`);
} else if (statusPage.type === "uptime") {
navigate(`/status/uptime/${statusPage.url}`);
}
};
return (
<DataTable
config={{
rowSX: {
cursor: "pointer",
"&:hover td": {
backgroundColor: theme.palette.tertiary.main,
transition: "background-color .3s ease",
},
},
onRowClick: (row) => {
handleRowClick(row);
},
}}
headers={headers}
data={data}
/>
);
};
export default StatusPagesTable;