Files
Checkmate/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx
T

121 lines
3.2 KiB
React
Raw Normal View History

2024-09-04 16:15:14 -07:00
import PropTypes from "prop-types";
import {
TableContainer,
Table,
TableHead,
TableRow,
TableCell,
TableBody,
Pagination,
PaginationItem,
Paper,
Box,
} from "@mui/material";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
import { useState, useEffect } from "react";
import { logger } from "../../../../Utils/Logger";
import Host from "../host";
import { StatusLabel } from "../../../../Components/Label";
2024-09-04 17:37:30 -07:00
import { jwtDecode } from "jwt-decode";
import { useSelector } from "react-redux";
import { networkService } from "../../../../main";
2024-09-04 16:15:14 -07:00
const MonitorTable = ({ teamId }) => {
const [paginationController, setPaginationController] = useState({
page: 0,
rowsPerPage: 14,
});
const [monitors, setMonitors] = useState([]);
const [monitorCount, setMonitorCount] = useState(0);
2024-09-04 17:37:30 -07:00
const authState = useSelector((state) => state.auth);
2024-09-04 16:15:14 -07:00
const handlePageChange = (_, newPage) => {
setPaginationController({
...paginationController,
page: newPage - 1, // 0-indexed
});
};
useEffect(() => {
const fetchPage = async () => {
try {
2024-09-04 17:37:30 -07:00
const { authToken } = authState;
const user = jwtDecode(authToken);
2024-09-04 16:15:14 -07:00
const res = await networkService.getMonitorsByTeamId(
2024-09-04 17:37:30 -07:00
authToken,
2024-09-04 16:15:14 -07:00
user.teamId,
25,
["http", "ping"],
null,
"desc",
2024-09-04 17:37:30 -07:00
true,
paginationController.page,
paginationController.rowsPerPage
2024-09-04 16:15:14 -07:00
);
2024-09-04 17:37:30 -07:00
console.log(res.data.data);
2024-09-04 16:15:14 -07:00
setMonitors([]);
setMonitorCount(0);
} catch (error) {
logger.error(error);
}
};
fetchPage();
2024-09-04 17:37:30 -07:00
}, []);
2024-09-04 16:15:14 -07:00
let paginationComponent = <></>;
if (monitorCount > paginationController.rowsPerPage) {
paginationComponent = (
<Pagination
count={Math.ceil(monitorCount / paginationController.rowsPerPage)}
page={paginationController.page + 1} //0-indexed
onChange={handlePageChange}
shape="rounded"
renderItem={(item) => (
<PaginationItem
slots={{
previous: ArrowBackRoundedIcon,
next: ArrowForwardRoundedIcon,
}}
{...item}
/>
)}
/>
);
}
return (
<>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell>Host</TableCell>
<TableCell>
{" "}
<Box width="max-content">
Status
<span>
<ArrowDownwardRoundedIcon />
</span>
</Box>
</TableCell>
<TableCell>Response Time</TableCell>
<TableCell>Type</TableCell>
<TableCell>Actions</TableCell>
</TableRow>
</TableHead>
<TableBody></TableBody>
</Table>
</TableContainer>
{paginationComponent}
</>
);
};
MonitorTable.propTypes = {
teamId: PropTypes.string,
};
export default MonitorTable;