diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index e245e0b6c..4c328a364 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -1,6 +1,6 @@ import { useState, useEffect } from "react"; import { useSelector } from "react-redux"; -import { Typography, ButtonGroup, Stack, Box } from "@mui/material"; +import { Typography, ButtonGroup, Stack, Box, Skeleton } from "@mui/material"; import WestRoundedIcon from "@mui/icons-material/WestRounded"; import Button from "../../Components/Button"; import axiosInstance from "../../Utils/axiosConfig"; @@ -12,12 +12,39 @@ import Select from "../../Components/Inputs/Select"; import "./index.css"; +/** + * Renders a skeleton layout. + * + * @returns {JSX.Element} + */ +const SkeletonLayout = () => { + const theme = useTheme(); + + return ( + <> + + + + + + + + + ); +}; + const Incidents = () => { const theme = useTheme(); const navigate = useNavigate(); const authState = useSelector((state) => state.auth); const [monitors, setMonitors] = useState({}); const [selectedMonitor, setSelectedMonitor] = useState("0"); + const [loading, setLoading] = useState(false); // TODO do something with these filters const [filter, setFilter] = useState("all"); @@ -34,6 +61,7 @@ const Incidents = () => { useEffect(() => { const fetchIncidents = async () => { + setLoading(true); const res = await axiosInstance.get( `/monitors/user/${authState.user._id}?status=false`, { @@ -51,6 +79,7 @@ const Incidents = () => { }, {}); setMonitors(monitorLookup); } + setLoading(false); }; fetchIncidents(); @@ -92,8 +121,8 @@ const Incidents = () => { data: , }, { id: idx + 1, data: new Date(incident.createdAt).toLocaleString() }, - { id: idx + 2, data: incident.statusCode }, - { id: idx + 3, data: monitors[incident.monitorId].name }, + { id: idx + 2, data: monitors[incident.monitorId].name }, + { id: idx + 3, data: incident.statusCode }, ], }; }); @@ -102,7 +131,9 @@ const Incidents = () => { return ( <> - {hasAnyIncidents ? ( + {loading ? ( + + ) : hasAnyIncidents ? ( <> Incident history for: @@ -155,8 +186,7 @@ const Incidents = () => { )} ) : ( - - No incidents, yet. +