From 7b4f78132d84da02868821039a93d8e678a0b304 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 6 Feb 2025 12:15:59 -0800 Subject: [PATCH] protect DU routes --- .../ProtectedDistributedUptimeRoute/index.jsx | 30 +++++++++++++++++++ Client/src/Routes/index.jsx | 20 +++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 Client/src/Components/ProtectedDistributedUptimeRoute/index.jsx diff --git a/Client/src/Components/ProtectedDistributedUptimeRoute/index.jsx b/Client/src/Components/ProtectedDistributedUptimeRoute/index.jsx new file mode 100644 index 000000000..4a59859fe --- /dev/null +++ b/Client/src/Components/ProtectedDistributedUptimeRoute/index.jsx @@ -0,0 +1,30 @@ +import { Navigate } from "react-router-dom"; +import { useSelector } from "react-redux"; +import PropTypes from "prop-types"; + +/** + * @param {Object} props - The props passed to the ProtectedDistributedUptimeRoute component. + * @param {React.ReactNode} props.children - The children to render if the user is authenticated. + * @returns {React.ReactElement} The children wrapped in a protected route or a redirect to the login page. + */ + +const ProtectedDistributedUptimeRoute = ({ children }) => { + const distributedUptimeEnabled = useSelector( + (state) => state.ui.distributedUptimeEnabled + ); + + return distributedUptimeEnabled === true ? ( + children + ) : ( + + ); +}; + +ProtectedDistributedUptimeRoute.propTypes = { + children: PropTypes.node.isRequired, +}; + +export default ProtectedDistributedUptimeRoute; diff --git a/Client/src/Routes/index.jsx b/Client/src/Routes/index.jsx index 8883a3212..3ace64ae1 100644 --- a/Client/src/Routes/index.jsx +++ b/Client/src/Routes/index.jsx @@ -48,6 +48,7 @@ import Settings from "../Pages/Settings"; import Maintenance from "../Pages/Maintenance"; import ProtectedRoute from "../Components/ProtectedRoute"; +import ProtectedDistributedUptimeRoute from "../Components/ProtectedDistributedUptimeRoute"; import CreateNewMaintenanceWindow from "../Pages/Maintenance/CreateMaintenance"; import withAdminCheck from "../Components/HOC/withAdminCheck"; @@ -86,15 +87,28 @@ const Routes = () => { /> } + element={ + + {" "} + + } /> + } + element={ + + + + } /> } + element={ + + + + } />