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

108 lines
2.4 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";
const StatusPagesTable = ({ data }) => {
const theme = useTheme();
const navigate = useNavigate();
const headers = [
{
id: "name",
content: "Status page name",
render: (row) => {
return row.companyName;
},
},
{
id: "url",
2025-02-27 11:27:20 -08:00
content: "Public URL",
onClick: (e, row) => {
if (row.isPublished) {
e.stopPropagation();
const url =
row.type === "distributed"
? `/status/distributed/public/${row.url}`
: `/status/uptime/public/${row.url}`;
navigate(url);
}
},
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",
content: "Type",
render: (row) => {
return row.type;
},
},
{
id: "status",
content: "Status",
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;