Add admin guard to settings route, conditionally render config option

This commit is contained in:
Alex Holliday committed 2024-08-30 10:09:38 -07:00
1 parent eedf2879ee
commit 0a11de47d7
2 files changed
+9 -2

No files matched your search

+2 -1
View File
@@ -39,6 +39,7 @@ function App() {
const DetailsWithAdminProp = withAdminProp(Details); const DetailsWithAdminProp = withAdminProp(Details);
const PageSpeedWithAdminProp = withAdminProp(PageSpeed); const PageSpeedWithAdminProp = withAdminProp(PageSpeed);
const MaintenanceWithAdminProp = withAdminProp(Maintenance); const MaintenanceWithAdminProp = withAdminProp(Maintenance);
const SettingsWithAdminProp = withAdminProp(Settings);
const mode = useSelector((state) => state.ui.mode); const mode = useSelector((state) => state.ui.mode);
@@ -90,7 +91,7 @@ function App() {
/> />
<Route <Route
path="settings" path="settings"
element={<ProtectedRoute Component={Settings} />} element={<ProtectedRoute Component={SettingsWithAdminProp} />}
/> />
<Route <Route
path="account/profile" path="account/profile"
+7 -1
View File
@@ -10,7 +10,8 @@ import "./index.css";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { createToast } from "../../Utils/toastUtils"; import { createToast } from "../../Utils/toastUtils";
import { deleteMonitorChecksByTeamId } from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; import { deleteMonitorChecksByTeamId } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
const Settings = () => { import PropTypes from "prop-types";
const Settings = ({ isAdmin }) => {
const theme = useTheme(); const theme = useTheme();
const { user, authToken } = useSelector((state) => state.auth); const { user, authToken } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
@@ -102,6 +103,7 @@ const Settings = () => {
/> />
</Stack> </Stack>
</ConfigBox> </ConfigBox>
{isAdmin && (
<ConfigBox> <ConfigBox>
<Box> <Box>
<Typography component="h1">History and monitoring</Typography> <Typography component="h1">History and monitoring</Typography>
@@ -133,6 +135,7 @@ const Settings = () => {
</Box> </Box>
</Stack> </Stack>
</ConfigBox> </ConfigBox>
)}
<ConfigBox> <ConfigBox>
<Box> <Box>
<Typography component="h1">About</Typography> <Typography component="h1">About</Typography>
@@ -163,4 +166,7 @@ const Settings = () => {
); );
}; };
Settings.propTypes = {
isAdmin: PropTypes.bool,
};
export default Settings; export default Settings;