diff --git a/Client/package-lock.json b/Client/package-lock.json index 2a7b9b7e1..44e276f63 100644 --- a/Client/package-lock.json +++ b/Client/package-lock.json @@ -18,7 +18,7 @@ "@mui/x-data-grid": "7.3.2", "@mui/x-date-pickers": "7.3.2", "@reduxjs/toolkit": "2.2.5", - "axios": "1.7.2", + "axios": "1.7.4", "chart.js": "^4.4.3", "dayjs": "1.11.11", "joi": "17.13.1", @@ -29,7 +29,7 @@ "react-router": "^6.23.0", "react-router-dom": "^6.23.1", "react-toastify": "^10.0.5", - "recharts": "2.12.7", + "recharts": "2.13.0-alpha.4", "redux-persist": "6.0.0", "vite-plugin-svgr": "^4.2.0" }, @@ -2655,9 +2655,9 @@ } }, "node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", @@ -5509,15 +5509,15 @@ } }, "node_modules/recharts": { - "version": "2.12.7", - "resolved": "https://registry.npmjs.org/recharts/-/recharts-2.12.7.tgz", - "integrity": "sha512-hlLJMhPQfv4/3NBSAyq3gzGg4h2v69RJh6KU7b3pXYNNAELs9kEoXOjbkxdXpALqKBoVmVptGfLpxdaVYqjmXQ==", + "version": "2.13.0-alpha.4", + "resolved": "https://registry.npmjs.org/recharts/-/recharts-2.13.0-alpha.4.tgz", + "integrity": "sha512-K9naL6F7pEcDYJE6yFQASSCQecSLPP0JagnvQ9hPtA/aHgsxsnIOjouLP5yrFZehxzfCkV5TEORr7/uNtSr7Qw==", "license": "MIT", "dependencies": { "clsx": "^2.0.0", "eventemitter3": "^4.0.1", "lodash": "^4.17.21", - "react-is": "^16.10.2", + "react-is": "^18.3.1", "react-smooth": "^4.0.0", "recharts-scale": "^0.4.4", "tiny-invariant": "^1.3.1", @@ -5540,12 +5540,6 @@ "decimal.js-light": "^2.4.1" } }, - "node_modules/recharts/node_modules/react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "license": "MIT" - }, "node_modules/redux": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz", diff --git a/Client/package.json b/Client/package.json index f711bff9a..769e1f4a6 100644 --- a/Client/package.json +++ b/Client/package.json @@ -20,7 +20,7 @@ "@mui/x-data-grid": "7.3.2", "@mui/x-date-pickers": "7.3.2", "@reduxjs/toolkit": "2.2.5", - "axios": "1.7.2", + "axios": "1.7.4", "chart.js": "^4.4.3", "dayjs": "1.11.11", "joi": "17.13.1", @@ -31,7 +31,7 @@ "react-router": "^6.23.0", "react-router-dom": "^6.23.1", "react-toastify": "^10.0.5", - "recharts": "2.12.7", + "recharts": "2.13.0-alpha.4", "redux-persist": "6.0.0", "vite-plugin-svgr": "^4.2.0" }, diff --git a/Client/src/Components/Avatar/index.jsx b/Client/src/Components/Avatar/index.jsx index 4f4351508..2a9f70a08 100644 --- a/Client/src/Components/Avatar/index.jsx +++ b/Client/src/Components/Avatar/index.jsx @@ -3,6 +3,27 @@ import PropTypes from "prop-types"; import { useSelector } from "react-redux"; import { useEffect, useState } from "react"; +/** + * Generates a color based on the input string. + * @param {string} string - The input string to generate the color from. + * @returns {string} + */ +const stringToColor = (string) => { + let hash = 0; + let i; + for (i = 0; i < string.length; i += 1) { + hash = string.charCodeAt(i) + ((hash << 5) - hash); + } + + let color = "#"; + for (i = 0; i < 3; i += 1) { + const value = (hash >> (i * 8)) & 0xff; + color += `00${value.toString(16)}`.slice(-2); + } + + return color; +}; + /** * @component * @param {Object} props @@ -18,7 +39,7 @@ import { useEffect, useState } from "react"; const Avatar = ({ src, small, sx }) => { const { user } = useSelector((state) => state.auth); - const style = small ? { width: 25, height: 25 } : { width: 64, height: 64 }; + const style = small ? { width: 32, height: 32 } : { width: 64, height: 64 }; const border = small ? 1 : 3; const [image, setImage] = useState(); @@ -35,8 +56,9 @@ const Avatar = ({ src, small, sx }) => { src ? src : user?.avatarImage ? image : "/static/images/avatar/2.jpg" } sx={{ - fontSize: small ? "13px" : "22px", + fontSize: small ? "16px" : "22px", fontWeight: 400, + backgroundColor: stringToColor(`${user?.firstName} ${user?.lastName}`), display: "inline-flex", "&::before": { content: `""`, @@ -52,7 +74,8 @@ const Avatar = ({ src, small, sx }) => { ...sx, }} > - {user.firstName?.charAt(0)}{user.lastName?.charAt(0)} + {user.firstName?.charAt(0)} + {user.lastName?.charAt(0)} ); }; diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 91657f542..c37e467f6 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -28,15 +28,6 @@ const CustomToolTip = ({ active, payload, label }) => { }; const MonitorDetailsAreaChart = ({ checks }) => { - // SQUASH ERROR, NOT PERMANENT SOLUTION - const error = console.error; - console.error = (...args) => { - if (/defaultProps/.test(args[0])) return; - error(...args); - }; - - // END SQUASH ERROR, NOT PERMANENT SOLUTION - const formatDate = (timestamp) => { const date = new Date(timestamp); return date.toLocaleTimeString("en-US", { diff --git a/Client/src/Components/NavBar/index.css b/Client/src/Components/NavBar/index.css deleted file mode 100644 index fcedc53a2..000000000 --- a/Client/src/Components/NavBar/index.css +++ /dev/null @@ -1,34 +0,0 @@ -/* NavBar Component Styles*/ -.MuiToolbar-root { - min-height: var(--env-var-nav-bar-height) !important; -} - -.icon-button-toggle-title { - font-size: var(--env-var-font-size-medium); - color: var(--env-var-color-5); -} - -.icon-button-toggle-pic { - width: 10px; - height: 5px; -} - -#icon-button { - -webkit-transition: none; - transition: none; - outline: none; - box-shadow: none; - background-color: transparent; -} - -#menu-appbar svg { - width: 16px; - height: 16px; - color: var(--env-var-color-25); -} - -#bw-uptime-logo-dashboard { - width: fit-content; - height: 16px; - margin-left: 15px; -} diff --git a/Client/src/Components/NavBar/index.jsx b/Client/src/Components/NavBar/index.jsx deleted file mode 100644 index 95123d975..000000000 --- a/Client/src/Components/NavBar/index.jsx +++ /dev/null @@ -1,203 +0,0 @@ -import "./index.css"; -import { cloneElement, useState } from "react"; -import AppBar from "@mui/material/AppBar"; -import Box from "@mui/material/Box"; -import Toolbar from "@mui/material/Toolbar"; -import IconButton from "@mui/material/IconButton"; -import Typography from "@mui/material/Typography"; -import Menu from "@mui/material/Menu"; -import Avatar from "../Avatar"; -import Tooltip from "@mui/material/Tooltip"; -import MenuItem from "@mui/material/MenuItem"; -import { useTheme } from "@mui/material/styles"; -import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; -import { clearAuthState } from "../../Features/Auth/authSlice"; -import { clearUptimeMonitorState } from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; - -import { useDispatch, useSelector } from "react-redux"; -import { useNavigate } from "react-router-dom"; -import LockSvg from "../../assets/icons/lock.svg?react"; -import UserSvg from "../../assets/icons/user.svg?react"; -import TeamSvg from "../../assets/icons/user-two.svg?react"; -import LogoutSvg from "../../assets/icons/logout.svg?react"; -import { Stack, useScrollTrigger } from "@mui/material"; -import axiosIntance from "../../Utils/axiosConfig"; -import axios from "axios"; - -const icons = { - Profile: , - Team: , - Password: , - Logout: , -}; - -function AddBorderOnScroll(props) { - const { children, window } = props; - const trigger = useScrollTrigger({ - target: window ? window() : undefined, - disableHysteresis: true, - threshold: 0, - }); - - return ( - - {children} - - ); -} - -/** - * NavBar component - * - * A responsive navigation bar component with a user menu. - * - * @component - * @example - * return ( - * - * ) - */ -function NavBar() { - const theme = useTheme(); - const [anchorElUser, setAnchorElUser] = useState(null); - const dispatch = useDispatch(); - const navigate = useNavigate(); - const authState = useSelector((state) => state.auth); - - // Initialize settings and update based on user role - let settings = ["Profile", "Password", "Team", "Logout"]; - if (authState.user?.role && !authState.user.role.includes("admin")) { - settings = ["Profile", "Password", "Logout"]; - } - - /** - * Handles opening the user menu. - * - * @param {React.MouseEvent} event - The event triggered by clicking the user menu button. - */ - const handleOpenUserMenu = (event) => { - setAnchorElUser(event.currentTarget); - }; - - /** - * Handles logging out the user - * - */ - const logout = async () => { - // Clear auth state - dispatch(clearAuthState()); - dispatch(clearUptimeMonitorState()); - // Make request to BE to remove JWT from user - await axiosIntance.post( - "/auth/logout", - { email: authState.user.email }, - { - headers: { - Authorization: `Bearer ${authState.authToken}`, - "Content-Type": "application/json", - }, - } - ); - navigate("/login"); - }; - - /** - * Handles closing the user menu. - */ - const handleCloseUserMenu = (setting) => { - setAnchorElUser(null); - switch (setting) { - case "Profile": - navigate("/account/profile"); - break; - case "Team": - navigate("/account/team"); - break; - case "Password": - navigate("/account/password"); - break; - case "Logout": - logout(); - break; - default: - break; - } - }; - - return ( - - - - - - - - {authState.user?.firstName} {authState.user?.lastName} - - - - - - - {settings.map((setting) => ( - handleCloseUserMenu(setting)} - sx={{ width: "150px" }} - > - {icons[setting]} - - {setting} - - - ))} - - - - ); -} - -export default NavBar; diff --git a/Client/src/Components/Sidebar/index.css b/Client/src/Components/Sidebar/index.css index 6fa9d2134..4840043c3 100644 --- a/Client/src/Components/Sidebar/index.css +++ b/Client/src/Components/Sidebar/index.css @@ -18,11 +18,14 @@ aside span.MuiTypography-root { color: var(--env-var-color-5); line-height: 1; } -aside .MuiStack-root:nth-last-child(2) { +aside .MuiStack-root:nth-last-child(3) { margin-top: auto; +} +aside .MuiStack-root:last-child, +aside .MuiStack-root:nth-last-child(3) { position: relative; } -aside .MuiStack-root:nth-last-child(2):before { +aside .MuiStack-root:last-child:before { content: ""; position: absolute; top: -10px; @@ -31,5 +34,35 @@ aside .MuiStack-root:nth-last-child(2):before { border-top: solid 1px var(--env-var-color-6); } aside .MuiStack-root:last-child { - margin-bottom: 10px; + margin-top: 15px; +} + +.sidebar-menu { + margin-top: -20px; +} +.sidebar-menu .MuiPaper-root { + box-shadow: var(--env-var-shadow-1); + border: solid 1px var(--env-var-color-6); + border-radius: var(--env-var-radius-1); + gap: 1px; +} +.sidebar-menu .MuiList-root { + min-width: 100px; + width: 150px; + padding-bottom: 0; +} +.sidebar-menu li.MuiButtonBase-root:last-child { + border-top: solid 1px var(--env-var-color-6); + padding: 12px 16px; +} +.sidebar-menu li.MuiButtonBase-root { + min-height: fit-content; +} +.sidebar-menu .MuiList-root svg { + width: 16px; + height: 16px; +} +.sidebar-menu span { + font-size: var(--env-var-font-size-medium); + color: var(--env-var-color-2); } diff --git a/Client/src/Components/Sidebar/index.jsx b/Client/src/Components/Sidebar/index.jsx index 3b2a32394..5a5b1d980 100644 --- a/Client/src/Components/Sidebar/index.jsx +++ b/Client/src/Components/Sidebar/index.jsx @@ -1,7 +1,17 @@ -import { Stack, Typography } from "@mui/material"; +import { useState } from "react"; +import { Menu, MenuItem, Stack, Tooltip, Typography } from "@mui/material"; import { useLocation, useNavigate } from "react-router"; import { useTheme } from "@emotion/react"; - +import { useDispatch, useSelector } from "react-redux"; +import { clearAuthState } from "../../Features/Auth/authSlice"; +import { clearUptimeMonitorState } from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; +import { createToast } from "../../Utils/toastUtils"; +import axiosInstance from "../../Utils/axiosConfig"; +import Avatar from "../Avatar"; +import LockSvg from "../../assets/icons/lock.svg?react"; +import UserSvg from "../../assets/icons/user.svg?react"; +import TeamSvg from "../../assets/icons/user-two.svg?react"; +import LogoutSvg from "../../assets/icons/logout.svg?react"; import BWULogo from "../../assets/Images/bwl-logo.svg?react"; import Support from "../../assets/icons/support.svg?react"; import StatusPages from "../../assets/icons/status-pages.svg?react"; @@ -11,16 +21,10 @@ import Incidents from "../../assets/icons/incidents.svg?react"; import Integrations from "../../assets/icons/integrations.svg?react"; import PageSpeed from "../../assets/icons/page-speed.svg?react"; import Settings from "../../assets/icons/settings.svg?react"; +import Arrow from "../../assets/icons/down-arrow.svg?react"; import "./index.css"; -/** - * @component - * Sidebar component serves as a sidebar containing a menu. - * - * @returns {JSX.Element} The JSX element representing the Sidebar component. - */ - const menu = [ { name: "Monitors", path: "monitors", icon: }, { name: "Incidents", path: "incidents", icon: }, @@ -32,10 +36,94 @@ const menu = [ { name: "Settings", path: "settings", icon: }, ]; +const icons = { + Profile: , + Team: , + Password: , + Logout: , +}; + +/** + * @component + * Sidebar component serves as a sidebar containing a menu. + * + * @returns {JSX.Element} The JSX element representing the Sidebar component. + */ + function Sidebar() { const theme = useTheme(); const navigate = useNavigate(); const location = useLocation(); + const dispatch = useDispatch(); + const [anchorElUser, setAnchorElUser] = useState(null); + const authState = useSelector((state) => state.auth); + + // Initialize settings and update based on user role + let settings = ["Profile", "Password", "Team", "Logout"]; + if (authState.user?.role && !authState.user.role.includes("admin")) { + settings = ["Profile", "Password", "Logout"]; + } + + /** + * Handles opening the user menu. + * + * @param {React.MouseEvent} event - The event triggered by clicking the user menu button. + */ + const handleOpenUserMenu = (event) => { + setAnchorElUser(event.currentTarget); + }; + + /** + * Handles logging out the user + * + */ + const logout = async () => { + try { + // Make request to BE to remove JWT from user + await axiosInstance.post( + "/auth/logout", + { email: authState.user.email }, + { + headers: { + Authorization: `Bearer ${authState.authToken}`, + "Content-Type": "application/json", + }, + } + ); + + // Clear auth state + dispatch(clearAuthState()); + dispatch(clearUptimeMonitorState()); + navigate("/login"); + } catch (error) { + createToast({ + body: error.message, + }); + } + }; + + /** + * Handles closing the user menu. + */ + const handleCloseUserMenu = (setting) => { + setAnchorElUser(null); + switch (setting) { + case "Profile": + navigate("/account/profile"); + break; + case "Team": + navigate("/account/team"); + break; + case "Password": + navigate("/account/password"); + break; + case "Logout": + logout(); + break; + default: + break; + } + }; return ( @@ -48,6 +136,8 @@ function Sidebar() { key={item.path} direction="row" alignItems="center" + py={theme.gap.small} + px={theme.gap.medium} gap={theme.gap.small} borderRadius={`${theme.shape.borderRadius}px`} onClick={() => @@ -59,12 +149,66 @@ function Sidebar() { ) : navigate(`/${item.path}`) } - sx={{ p: `${theme.gap.small} ${theme.gap.medium}` }} > {item.icon} {item.name} ))} + + + + + {authState.user?.firstName} {authState.user?.lastName} + + + + + + {settings.map((setting) => ( + handleCloseUserMenu(setting)}> + {icons[setting]} + + {setting} + + + ))} + ); } diff --git a/Client/src/Features/Auth/authSlice.js b/Client/src/Features/Auth/authSlice.js index a30c295d9..6da315fc4 100644 --- a/Client/src/Features/Auth/authSlice.js +++ b/Client/src/Features/Auth/authSlice.js @@ -20,7 +20,11 @@ export const register = createAsyncThunk( if (error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -33,7 +37,11 @@ export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } }); @@ -72,7 +80,11 @@ export const update = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -91,7 +103,11 @@ export const deleteUser = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -106,7 +122,11 @@ export const forgotPassword = createAsyncThunk( if (error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -128,7 +148,11 @@ export const setNewPassword = createAsyncThunk( if (error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); diff --git a/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js b/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js index 4377edb35..6af825a37 100644 --- a/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js +++ b/Client/src/Features/PageSpeedMonitor/pageSpeedMonitorSlice.js @@ -25,7 +25,11 @@ export const createPageSpeed = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -40,7 +44,11 @@ export const getPageSpeedMonitors = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -63,7 +71,11 @@ export const getPageSpeedByUserId = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -94,7 +106,11 @@ export const updatePageSpeed = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -115,7 +131,11 @@ export const deletePageSpeed = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); diff --git a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js index e69e6d41d..27d616e1e 100644 --- a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js +++ b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js @@ -25,7 +25,11 @@ export const createUptimeMonitor = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -40,7 +44,11 @@ export const getUptimeMonitors = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -63,7 +71,11 @@ export const getUptimeMonitorsByUserId = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -94,7 +106,11 @@ export const updateUptimeMonitor = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); @@ -115,7 +131,11 @@ export const deleteUptimeMonitor = createAsyncThunk( if (error.response && error.response.data) { return thunkApi.rejectWithValue(error.response.data); } - return thunkApi.rejectWithValue(error.message); + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); } } ); diff --git a/Client/src/Layouts/HomeLayout/index.css b/Client/src/Layouts/HomeLayout/index.css index 048700db6..a62016a60 100644 --- a/Client/src/Layouts/HomeLayout/index.css +++ b/Client/src/Layouts/HomeLayout/index.css @@ -1,55 +1,34 @@ -.home-layout { - display: grid; - position: relative; - grid-template-areas: - "aside header" - "aside main"; - grid-template-columns: var(--env-var-side-bar-width) auto; - grid-template-rows: var(--env-var-nav-bar-height) auto; +#root:has(.home-layout) { background-color: var(--env-var-color-30); +} + +.home-layout { + display: flex; + position: relative; + gap: var(--env-var-spacing-2); min-height: 100vh; + max-width: 1400px; + margin: 0 auto; + padding: var(--env-var-spacing-2); } .home-layout aside { - grid-area: aside; - position: fixed; - top: 0; - height: 100%; - width: var(--env-var-side-bar-width); + position: sticky; + top: var(--env-var-spacing-2); + left: 0; + + height: calc(100vh - var(--env-var-spacing-2) * 2); + max-width: var(--env-var-side-bar-width); + flex: 1; + + border: 1px solid var(--color-border-0); + border-radius: var(--env-var-radius-1); background-color: var(--env-var-color-8); - border-right: 1px solid var(--color-border-0); + padding: var(--env-var-spacing-1) var(--env-var-spacing-1-plus); } -.home-layout header { - grid-area: header; - background-color: var(--env-var-color-30); -} + .home-layout > div { - height: 100%; - grid-area: main; - padding: var(--env-var-spacing-2) calc(var(--env-var-spacing-4) * 2); - padding-bottom: var(--env-var-spacing-4); - max-width: 100%; -} -.home-layout > div:not(:has([class*="fallback"])) { - max-width: 1500px; -} - -@media (max-width: 600px) { - .home-layout { - grid-template-areas: - "header header" - "main main"; - grid-template-columns: 1fr; - grid-template-rows: 64px auto; - } - - aside { - display: none; - visibility: hidden; - } - - .home-layout > div { - padding: var(--env-var-spacing-1); - } + min-height: calc(100vh - var(--env-var-spacing-2) * 2); + flex: 1; } diff --git a/Client/src/Layouts/HomeLayout/index.jsx b/Client/src/Layouts/HomeLayout/index.jsx index 007fb7d05..81cb2fd9c 100644 --- a/Client/src/Layouts/HomeLayout/index.jsx +++ b/Client/src/Layouts/HomeLayout/index.jsx @@ -1,4 +1,3 @@ -import NavBar from "../../Components/NavBar"; import Sidebar from "../../Components/Sidebar"; import { Outlet } from "react-router"; import { Box } from "@mui/material"; @@ -9,7 +8,6 @@ const HomeLayout = () => { return ( - ); diff --git a/Client/src/Pages/Account/index.jsx b/Client/src/Pages/Account/index.jsx index db08ec3a2..82f37a969 100644 --- a/Client/src/Pages/Account/index.jsx +++ b/Client/src/Pages/Account/index.jsx @@ -29,7 +29,7 @@ const Account = ({ open = "profile" }) => { if (!user.role.includes("admin")) tabList = ["Profile", "Password"]; return ( - + { }; return ( - + {loading ? ( ) : ( diff --git a/Client/src/Pages/Integrations/index.jsx b/Client/src/Pages/Integrations/index.jsx index f7d693948..278754fea 100644 --- a/Client/src/Pages/Integrations/index.jsx +++ b/Client/src/Pages/Integrations/index.jsx @@ -108,7 +108,7 @@ const Integrations = () => { ]; return ( - + Integrations Connect BlueWave Uptime to your favorite service. diff --git a/Client/src/Pages/Monitors/Configure/index.css b/Client/src/Pages/Monitors/Configure/index.css index a594348ab..ac9cd8a0d 100644 --- a/Client/src/Pages/Monitors/Configure/index.css +++ b/Client/src/Pages/Monitors/Configure/index.css @@ -75,7 +75,7 @@ .configure-monitor-form { display: flex; flex-direction: column; - gap: var(--env-var-spacing-4); + gap: var(--env-var-spacing-2); } body:has(.configure-monitor) .select-dropdown .MuiMenuItem-root, diff --git a/Client/src/Pages/Monitors/CreateMonitor/index.css b/Client/src/Pages/Monitors/CreateMonitor/index.css index 1eb542a44..3fa38f14a 100644 --- a/Client/src/Pages/Monitors/CreateMonitor/index.css +++ b/Client/src/Pages/Monitors/CreateMonitor/index.css @@ -59,7 +59,7 @@ .create-monitor-form { display: flex; flex-direction: column; - gap: var(--env-var-spacing-4); + gap: var(--env-var-spacing-2); } .create-monitor .MuiStack-root .MuiButtonGroup-root button { diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx index e56be39b2..f8efd7fa3 100644 --- a/Client/src/Pages/Monitors/index.jsx +++ b/Client/src/Pages/Monitors/index.jsx @@ -120,12 +120,11 @@ const Monitors = () => { }; const closeMenu = () => { setAnchorEl(null); - setActions({}); }; const [isOpen, setIsOpen] = useState(false); const openRemove = () => { - setAnchorEl(null); + closeMenu(); setIsOpen(true); }; const handleRemove = async (event) => { @@ -220,7 +219,11 @@ const Monitors = () => { aria-label="monitor actions" onClick={(event) => { event.stopPropagation(); - openMenu(event, monitor._id, monitor.url); + openMenu( + event, + monitor._id, + monitor.type === "ping" ? null : monitor.url + ); }} sx={{ "&:focus": { @@ -240,7 +243,7 @@ const Monitors = () => { let loading = monitorState.isLoading && monitorState.monitors.length === 0; return ( - + {loading ? ( ) : ( @@ -250,7 +253,10 @@ const Monitors = () => { justifyContent="space-between" alignItems="center" > - + Hello, {authState.user.firstName} {monitorState.monitors?.length !== 0 && ( @@ -299,7 +305,8 @@ const Monitors = () => { { open={Boolean(anchorEl)} onClose={closeMenu} > - { - window.open(actions.url, "_blank", "noreferrer"); - }} - > - Open site - + {actions.url !== null ? ( + { + window.open(actions.url, "_blank", "noreferrer"); + }} + > + Open site + + ) : ( + "" + )} navigate(`/monitors/${actions.id}`)}> Details diff --git a/Client/src/Pages/PageSpeed/CreatePageSpeed/index.jsx b/Client/src/Pages/PageSpeed/CreatePageSpeed/index.jsx index cb82310c4..e9b271326 100644 --- a/Client/src/Pages/PageSpeed/CreatePageSpeed/index.jsx +++ b/Client/src/Pages/PageSpeed/CreatePageSpeed/index.jsx @@ -106,7 +106,7 @@ const CreatePageSpeed = () => { onClick={() => navigate("/pagespeed")} sx={{ backgroundColor: theme.palette.otherColors.fillGray, - mb: theme.gap.large, + mb: theme.gap.medium, px: theme.gap.ml, "& svg.MuiSvgIcon-root": { mr: theme.gap.small, @@ -122,8 +122,6 @@ const CreatePageSpeed = () => { display: "flex", flexDirection: "column", gap: theme.gap.large, - // TODO - maxWidth: "1000px", }} > Create a page speed monitor diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 963b0b31f..006f2acf3 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -299,7 +299,7 @@ const PageSpeedDetails = () => { const [expand, setExpand] = useState(false); let loading = Object.keys(monitor).length === 0; - + const data = monitor?.checks ? [...monitor.checks].reverse() : []; return ( {loading ? ( @@ -363,7 +363,7 @@ const PageSpeedDetails = () => { { Score history - + Performance report - + { let isActuallyLoading = isLoading && monitors.length === 0; return ( - + {isActuallyLoading ? ( ) : monitors?.length !== 0 ? ( diff --git a/Client/src/Utils/Theme.js b/Client/src/Utils/Theme.js index c065798d2..c4faa2d1f 100644 --- a/Client/src/Utils/Theme.js +++ b/Client/src/Utils/Theme.js @@ -96,9 +96,10 @@ const theme = createTheme({ ml: "16px", mlplus: "20px", large: "24px", + lgplus: "32px", xl: "40px", xxl: "60px", - triplexl: "120px" + triplexl: "120px", }, alert: { info: { diff --git a/Client/src/assets/icons/down-arrow.svg b/Client/src/assets/icons/down-arrow.svg new file mode 100644 index 000000000..7c6a715ed --- /dev/null +++ b/Client/src/assets/icons/down-arrow.svg @@ -0,0 +1,3 @@ + + + diff --git a/README.md b/README.md index 7c4ed8c25..2d0db36fc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ ![](https://img.shields.io/github/issues-pr/bluewave-labs/bluewave-uptime) ![](https://img.shields.io/github/issues/bluewave-labs/bluewave-uptime) -

BlueWave Uptime

An open source server monitoring application

@@ -26,29 +25,31 @@ BlueWave Uptime is an open source server monitoring application used to track th - [ ] Scheduled maintenance (in the works) **Roadmap (short term):** + - [ ] Memory, disk and CPU monitoring - [ ] 3rd party integrations - [ ] DNS monitoring - [ ] SSL monitoring **Roadmap (long term):** + - [ ] Status pages ## Tech stack -* [ReactJs](https://react.dev/) -* [MUI (React framework)](https://mui.com/) -* [Node.js](https://nodejs.org/en) -* [MongoDB](https://mongodb.com) +- [ReactJs](https://react.dev/) +- [MUI (React framework)](https://mui.com/) +- [Node.js](https://nodejs.org/en) +- [MongoDB](https://mongodb.com) ## Contributing We love contributors. Here's how you can contribute: -* Check [Contributor's guideline](https://github.com/bluewave-labs/bluewave-uptime/blob/master/CONTRIBUTING.md). -* Have a look at our Figma designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgDUV/Uptime-Genie?node-id=0-1&t=WqOFv9jqNTFGItpL-1). We encourage you to copy to your own Figma page, then work on it as it is read-only. -* Open an issue if you believe you've encountered a bug -* Make a pull request to add new features/make quality-of-life improvements/fix bugs. +- Check [Contributor's guideline](https://github.com/bluewave-labs/bluewave-uptime/blob/master/CONTRIBUTING.md). +- Have a look at our Figma designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgDUV/Uptime-Genie?node-id=0-1&t=WqOFv9jqNTFGItpL-1). We encourage you to copy to your own Figma page, then work on it as it is read-only. +- Open an issue if you believe you've encountered a bug +- Make a pull request to add new features/make quality-of-life improvements/fix bugs. @@ -58,12 +59,12 @@ Made with [contrib.rocks](https://contrib.rocks). ![Alt](https://repobeats.axiom.co/api/embed/c35d999c82dbb31e967427ea4166c14da4172e73.svg "Repobeats analytics image") - ## Getting Started - Clone this repository to your local machine -1. [Docker Quickstart](#docker-quickstart) +1. [Quickstart for Developers](#dev-quickstart) +1. [Docker Compose](#docker-compose) 1. [Installation (Client)](#client) 1. [Configuration(Client)](#config-client) - [Environment](#env-vars-client) @@ -117,9 +118,41 @@ Made with [contrib.rocks](https://contrib.rocks). --- -### Docker Quick Start +#### Quickstart for Developers -#### Docker Quickstart +MAKE SURE YOU CD TO THE SPECIFIED DIRECTORIES AS PATHS IN COMMANDS ARE RELATIVE + +##### Cloning and Initial Setup + +1. Clone this repository +2. Checkout the `develop` branch `git checkout develop` + +##### Docker Images Setup + +3. CD to the `Docker` directory +4. Run `docker run -d -p 6379:6379 -v $(pwd)/redis/data:/data --name uptime_redis uptime_redis` +5. Run `docker run -d -p 27017:27017 -v $(pwd)/mongo/data:/data/db --name uptime_database_mongo uptime_database_mongo` + +##### Server Setup + +6. CD to `Server` directory, run `npm install` +7. While in `Server` directory, create a `.env` file with the [required environmental variables](#env-vars-server) +8. While in the `Server` directory, run `npm run dev` + +##### Client Setup + +9. CD to `Client` directory `run npm install` +10. While in the `Client` directory, create a `.env` file with the [required environmental variables](#env-vars-client) +11. While in the `Client` cirectory run `npm run dev` + +##### Access Application + +12. Client is running at `localhost:5173` +13. Server is running at `localhost:5000` + +--- + +#### Docker Compose The fastest way to start the application is to use our Dockerfiles and [Docker Compose](https://docs.docker.com/compose/). @@ -143,7 +176,7 @@ SYSTEM_EMAIL_ADDRESS= SYSTEM_EMAIL_PASSWORD= ``` -3. In the `Docker` directory, create a `client.env` file with the [required environtmental variables](#env-vars-client) for the client. Sample file: +3. In the `Client` directory, create a `client.env` file with the [required environtmental variables](#env-vars-client) for the client. Sample file: ``` VITE_APP_API_BASE_URL="http://localhost:5000/api/v1" @@ -151,7 +184,7 @@ VITE_APP_API_BASE_URL="http://localhost:5000/api/v1" 4. In the `Docker` directory run `docker compose up` to run the `docker-compose.yaml` file and start all four images. -That's it, the application is ready to use on port 5173. +That's it, the application is ready to use on port 80.
### Client @@ -2112,4 +2145,3 @@ const myRoute = async(req, res, next) => { ``` Errors should not be handled at the controller level and should be left to the middleware to handle. - diff --git a/Server/models/Check.js b/Server/models/Check.js index 66984d545..a9ac7f288 100644 --- a/Server/models/Check.js +++ b/Server/models/Check.js @@ -85,43 +85,38 @@ CheckSchema.pre("save", async function (next) { }); // Check if there are any notifications - if (notifications && notifications.length > 0) { - // Only send email if monitor status has changed - if (monitor.status !== this.status) { - const emailService = new EmailService(); - if (monitor.status === true && this.status === false) { - // Notify users that the monitor is down - for (const notification of notifications) { - if (notification.type === "email") { - await emailService.buildAndSendEmail( - "serverIsDownTemplate", - { monitorName: monitor.name, monitorUrl: monitor.url }, - notification.address, - `Monitor ${monitor.name} is down` - ); - } - } - } + // Only send email if monitor status has changed + if (monitor.status !== this.status) { + const emailService = new EmailService(); - if (monitor.status === false && this.status === true) { - // Notify users that the monitor is up - for (const notification of notifications) { - if (notification.type === "email") { - await emailService.buildAndSendEmail( - "serverIsUpTemplate", - { monitorName: monitor.name, monitorUrl: monitor.url }, - notification.address, - `Monitor ${monitor.name} is back up` - ); - } - } - } - - // Update monitor status - monitor.status = this.status; - await monitor.save(); + let template = ""; + let status = ""; + if (monitor.status === true && this.status === false) { + template = "serverIsDownTemplate"; + status = "down"; } + + if (monitor.status === false && this.status === true) { + // Notify users that the monitor is up + template = "serverIsUpTemplate"; + status = "up"; + } + + for (const notification of notifications) { + if (notification.type === "email") { + await emailService.buildAndSendEmail( + template, + { monitorName: monitor.name, monitorUrl: monitor.url }, + notification.address, + `Monitor ${monitor.name} is ${status}` + ); + } + } + + // Update monitor status + monitor.status = this.status; + await monitor.save(); } } } catch (error) { diff --git a/Server/package-lock.json b/Server/package-lock.json index 6f11e3a2e..d2ad88cff 100644 --- a/Server/package-lock.json +++ b/Server/package-lock.json @@ -984,10 +984,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", - "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", - "license": "MIT", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0",