diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 567de0b68..91657f542 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -79,7 +79,6 @@ const MonitorDetailsAreaChart = ({ checks }) => { MonitorDetailsAreaChart.propTypes = { checks: PropTypes.array, - filter: PropTypes.string, }; CustomToolTip.propTypes = { diff --git a/Client/src/Pages/Incidents/IncidentTable/index.jsx b/Client/src/Pages/Incidents/IncidentTable/index.jsx new file mode 100644 index 000000000..bfcaed1e6 --- /dev/null +++ b/Client/src/Pages/Incidents/IncidentTable/index.jsx @@ -0,0 +1,125 @@ +import PropTypes from "prop-types"; +import { + TableContainer, + Table, + TableHead, + TableRow, + TableCell, + TableBody, + TableFooter, + TablePagination, +} from "@mui/material"; + +import { useState, useEffect } from "react"; +import { useSelector } from "react-redux"; +import axiosInstance from "../../../Utils/axiosConfig"; +import { StatusLabel } from "../../../Components/Label"; + +const IncidentTable = ({ monitorId, filter }) => { + const { authToken } = useSelector((state) => state.auth); + const [checks, setChecks] = useState([]); + const [checksCount, setChecksCount] = useState(0); + const [paginationController, setPaginationController] = useState({ + page: 0, + rowsPerPage: 5, + }); + + useEffect(() => { + const fetchPage = async () => { + try { + if (monitorId === "0") { + return; + } + const res = await axiosInstance.get( + `/checks/${monitorId}?sortOrder=desc&filter=${filter}&page=${paginationController.page}&rowsPerPage=${paginationController.rowsPerPage}`, + { + headers: { + Authorization: `Bearer ${authToken}`, + }, + } + ); + setChecks(res.data.data.checks); + setChecksCount(res.data.data.checksCount); + } catch (error) { + console.log(error); + } + }; + fetchPage(); + }, [ + authToken, + monitorId, + filter, + paginationController.page, + paginationController.rowsPerPage, + ]); + + const handlePageChange = (_, newPage) => { + setPaginationController({ + ...paginationController, + page: newPage, + }); + }; + + const handleChangeRowsPerPage = (event) => { + setPaginationController({ + ...paginationController, + rowsPerPage: parseInt(event.target.value, 10), + page: 0, + }); + }; + + return ( + + + + + Monitor Name + Status + Date & Time + Message + + + + {checks.map((check) => { + const status = check.status === true ? "up" : "down"; + + return ( + + + + + + {new Date(check.createdAt).toLocaleString()} + + {check.statusCode} + + ); + })} + + + + + + +
+
+ ); +}; + +IncidentTable.propTypes = { + monitorId: PropTypes.string.isRequired, + filter: PropTypes.string.isRequired, +}; + +export default IncidentTable; diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index d150b11ad..45237a0d1 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -9,7 +9,7 @@ import { StatusLabel } from "../../Components/Label"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router"; import Select from "../../Components/Inputs/Select"; - +import IncidentTable from "./IncidentTable"; import "./index.css"; /** @@ -76,99 +76,142 @@ const Incidents = () => { fetchMonitors(); }, [authState]); + useEffect(() => {}, []); + const handleSelect = (event) => { setSelectedMonitor(event.target.value); }; return ( - <> - - {loading ? ( - - ) : false ? ( - <> - - Incident history for: - + +