From a3620f720e9c1215356b4ac065856f12e9797af7 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 10 Feb 2025 13:45:01 -0800 Subject: [PATCH] Add basic status pages page --- .../StatusPages/Hooks/useStatusPagesFetch.jsx | 30 ++++++++ .../Pages/StatusPage/StatusPages/index.jsx | 77 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 Client/src/Pages/StatusPage/StatusPages/Hooks/useStatusPagesFetch.jsx create mode 100644 Client/src/Pages/StatusPage/StatusPages/index.jsx diff --git a/Client/src/Pages/StatusPage/StatusPages/Hooks/useStatusPagesFetch.jsx b/Client/src/Pages/StatusPage/StatusPages/Hooks/useStatusPagesFetch.jsx new file mode 100644 index 000000000..df5950930 --- /dev/null +++ b/Client/src/Pages/StatusPage/StatusPages/Hooks/useStatusPagesFetch.jsx @@ -0,0 +1,30 @@ +import { useState, useEffect } from "react"; +import { networkService } from "../../../../main"; +import { useSelector } from "react-redux"; +import { createToast } from "../../../../Utils/toastUtils"; + +const useStatusPagesFetch = () => { + const { authToken, user } = useSelector((state) => state.auth); + + const [isLoading, setIsLoading] = useState(true); + const [networkError, setNetworkError] = useState(false); + const [statusPages, setStatusPages] = useState(undefined); + + useEffect(() => { + try { + networkService + .getStatusPagesByTeamId({ authToken, teamId: user.teamId }) + .then((res) => { + setStatusPages(res.data.data); + }); + } catch (error) { + setNetworkError(true); + createToast(error.message, "error"); + } finally { + setIsLoading(false); + } + }, [authToken, user]); + return [isLoading, networkError, statusPages]; +}; + +export { useStatusPagesFetch }; diff --git a/Client/src/Pages/StatusPage/StatusPages/index.jsx b/Client/src/Pages/StatusPage/StatusPages/index.jsx new file mode 100644 index 000000000..0f9ba0aa5 --- /dev/null +++ b/Client/src/Pages/StatusPage/StatusPages/index.jsx @@ -0,0 +1,77 @@ +// Components +import { Stack, Typography } from "@mui/material"; +import Breadcrumbs from "../../../Components/Breadcrumbs"; +import Fallback from "../../../Components/Fallback"; +import GenericFallback from "../../../Components/GenericFallback"; +// Utils +import { useTheme } from "@emotion/react"; +import { useStatusPagesFetch } from "./Hooks/useStatusPagesFetch"; +import { useIsAdmin } from "../../../Hooks/useIsAdmin"; +import { useNavigate } from "react-router"; +const BREADCRUMBS = [{ name: `Status Pages`, path: "/distributed-uptime/status-pages" }]; + +const StatusPages = () => { + // Utils + const theme = useTheme(); + const isAdmin = useIsAdmin(); + const [isLoading, networkError, statusPages] = useStatusPagesFetch(); + const navigate = useNavigate(); + + // Handlers + const handleStatusPageClick = (statusPage) => { + if (statusPage.type === "distributed") { + navigate(`/status/distributed/${statusPage.url}`); + } else if (statusPage.type === "uptime") { + navigate(`/status/uptime/${statusPage.url}`); + } + }; + + if (!isLoading && typeof statusPages === "undefined") { + return ( + + ); + } + + if (networkError === true) { + return ( + + + Network error + + Please check your connection + + ); + } + return ( + + + {statusPages?.map((statusPage) => { + return ( + handleStatusPageClick(statusPage)} + sx={{ cursor: "pointer" }} + > + Company Name: {statusPage.companyName} + Status page URL: {statusPage.url} + Type: {statusPage.type} + + ); + })} + + ); +}; + +export default StatusPages;