diff --git a/Client/src/App.jsx b/Client/src/App.jsx index ca3894c28..73015d3b0 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -19,6 +19,7 @@ import SetNewPassword from "./Pages/Auth/SetNewPassword"; import NewPasswordConfirmed from "./Pages/Auth/NewPasswordConfirmed"; import ProtectedRoute from "./Components/ProtectedRoute"; import Details from "./Pages/Monitors/Details"; +import AdvancedSettings from "./Pages/AdvancedSettings"; // import Maintenance from "./Pages/Maintenance"; import withAdminCheck from "./HOC/withAdminCheck"; import withAdminProp from "./HOC/withAdminProp"; @@ -33,7 +34,9 @@ import lightTheme from "./Utils/Theme/lightTheme"; import darkTheme from "./Utils/Theme/darkTheme"; import { useSelector } from "react-redux"; import { CssBaseline } from "@mui/material"; - +import { useEffect } from "react"; +import { useDispatch } from "react-redux"; +import { getAppSettings } from "./Features/Settings/settingsSlice"; function App() { const AdminCheckedRegister = withAdminCheck(Register); const MonitorsWithAdminProp = withAdminProp(Monitors); @@ -42,8 +45,14 @@ function App() { const PageSpeedDetailsWithAdminProp = withAdminProp(PageSpeedDetails); // const MaintenanceWithAdminProp = withAdminProp(Maintenance); const SettingsWithAdminProp = withAdminProp(Settings); - + const AdvancedSettingsWithAdminProp = withAdminProp(AdvancedSettings); const mode = useSelector((state) => state.ui.mode); + const { authToken } = useSelector((state) => state.auth); + const dispatch = useDispatch(); + + useEffect(() => { + dispatch(getAppSettings(authToken)); + }, [dispatch, authToken]); return ( @@ -96,6 +105,12 @@ function App() { path="settings" element={} /> + + } + /> } diff --git a/Client/src/Features/Settings/settingsSlice.js b/Client/src/Features/Settings/settingsSlice.js index 0a7cb52c1..3778ca801 100644 --- a/Client/src/Features/Settings/settingsSlice.js +++ b/Client/src/Features/Settings/settingsSlice.js @@ -23,10 +23,10 @@ const initialState = { export const getAppSettings = createAsyncThunk( "settings/getSettings", - async (data, thunkApi) => { + async (authToken, thunkApi) => { try { const res = await networkService.getAppSettings({ - authToken: data.authToken, + authToken: authToken, }); return res.data; } catch (error) { @@ -65,6 +65,7 @@ const handleGetSettingsFulfilled = (state, action) => { state.isLoading = false; state.success = action.payload.success; state.msg = action.payload.msg; + Object.assign(state, action.payload.data); }; const handleGetSettingsRejected = (state, action) => { state.isLoading = false; @@ -87,17 +88,7 @@ const handleUpdateSettingsRejected = (state, action) => { const settingsSlice = createSlice({ name: "settings", initialState, - reducers: { - clearAuthState: (state) => { - state.authToken = ""; - state.user = ""; - state.isLoading = false; - state.success = true; - state.msg = "Logged out successfully"; - }, - }, extraReducers: (builder) => { - // Register thunk builder .addCase(getAppSettings.pending, (state) => { state.isLoading = true; @@ -105,7 +96,6 @@ const settingsSlice = createSlice({ .addCase(getAppSettings.fulfilled, handleGetSettingsFulfilled) .addCase(getAppSettings.rejected, handleGetSettingsRejected); - // Login thunk builder .addCase(updateAppSettings.pending, (state) => { state.isLoading = true; @@ -116,4 +106,3 @@ const settingsSlice = createSlice({ }); export default settingsSlice.reducer; -export const { clearAuthState } = settingsSlice.actions; diff --git a/Client/src/Pages/AdvancedSettings/index.css b/Client/src/Pages/AdvancedSettings/index.css new file mode 100644 index 000000000..e69de29bb diff --git a/Client/src/Pages/AdvancedSettings/index.jsx b/Client/src/Pages/AdvancedSettings/index.jsx new file mode 100644 index 000000000..6d227ba5d --- /dev/null +++ b/Client/src/Pages/AdvancedSettings/index.jsx @@ -0,0 +1,155 @@ +import { useTheme } from "@emotion/react"; +import { Box, Stack, Typography, Button } from "@mui/material"; +import Field from "../../Components/Inputs/Field"; +import Link from "../../Components/Link"; +import { logger } from "../../Utils/Logger"; +import "./index.css"; +import { useDispatch, useSelector } from "react-redux"; +import { createToast } from "../../Utils/toastUtils"; +import PropTypes from "prop-types"; +import LoadingButton from "@mui/lab/LoadingButton"; +import { ConfigBox } from "../Settings/styled"; +import { useNavigate } from "react-router"; +import { getAppSettings } from "../../Features/Settings/settingsSlice"; +import { useEffect, useState } from "react"; +import Select from "../../Components/Inputs/Select"; +const AdvancedSettings = ({ isAdmin }) => { + const theme = useTheme(); + const { user, authToken } = useSelector((state) => state.auth); + const navigate = useNavigate(); + const settings = useSelector((state) => state.settings); + const [localSettings, setLocalSettings] = useState(settings); + + const logItems = [ + { _id: 1, name: "none" }, + { _id: 2, name: "debug" }, + { _id: 3, name: "error" }, + { _id: 4, name: "warn" }, + ]; + + const logItemLookup = { + none: 1, + debug: 2, + error: 3, + warn: 4, + }; + + const handleLogLevel = (e) => { + const id = e.target.value; + const newLogLevel = logItems.find((item) => item._id === id).name; + setLocalSettings({ ...localSettings, logLevel: newLogLevel }); + }; + + const handleChange = (event) => { + const { value, id } = event.target; + setLocalSettings({ ...localSettings, [id]: value }); + }; + + return ( + + + \{" "} + + + Client Settings + + Modify client settings here + + + + +