diff --git a/Client/src/App.jsx b/Client/src/App.jsx index 8fb4bf932..d6fca146f 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -71,7 +71,7 @@ function App() { element={} /> } /> diff --git a/Client/src/Components/Charts/BarChart/index.jsx b/Client/src/Components/Charts/BarChart/index.jsx index 54a9524af..e2d8c7b45 100644 --- a/Client/src/Components/Charts/BarChart/index.jsx +++ b/Client/src/Components/Charts/BarChart/index.jsx @@ -1,12 +1,14 @@ import { useTheme } from "@emotion/react"; import { Box, Stack, Tooltip, Typography } from "@mui/material"; -import { formatDate } from "../../../Utils/timeUtils"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; import { useEffect, useState } from "react"; import "./index.css"; +import { useSelector } from "react-redux"; const BarChart = ({ checks = [] }) => { const theme = useTheme(); const [animate, setAnimate] = useState(false); + const uiTimezone = useSelector((state) => state.ui.timezone); useEffect(() => { setAnimate(true); @@ -51,7 +53,11 @@ const BarChart = ({ checks = [] }) => { title={ <> - {formatDate(new Date(check.createdAt), { year: undefined })} + {formatDateWithTz( + check.createdAt, + "ddd, MMMM D, YYYY, HH:mm A", + uiTimezone + )} { - const theme = useTheme(); + const uiTimezone = useSelector((state) => state.ui.timezone); + const theme = useTheme(); if (active && payload && payload.length) { return ( { fontWeight: 500, }} > - {new Date(label).toLocaleDateString("en-US", { - weekday: "short", // Mon - month: "long", // July - day: "numeric", // 17 - }) + - ", " + - new Date(label).toLocaleTimeString("en-US", { - hour: "numeric", // 12 - minute: "2-digit", // 15 - hour12: true, // AM/PM format - })} + {formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)} { return null; }; -const MonitorDetailsAreaChart = ({ checks }) => { - const formatDate = (timestamp) => { - const date = new Date(timestamp); - return date.toLocaleTimeString("en-US", { - hour: "numeric", - minute: "2-digit", - hour12: true, - }); - }; - - const memoizedChecks = useMemo(() => checks, [checks[0]]); - +const CustomTick = ({ x, y, payload, index }) => { const theme = useTheme(); + const uiTimezone = useSelector((state) => state.ui.timezone); + + // Render nothing for the first tick + if (index === 0) return null; + return ( + + {formatDateWithTz(payload?.value, "h:mm a", uiTimezone)} + + ); +}; + +CustomTick.propTypes = { + x: PropTypes.number, + y: PropTypes.number, + payload: PropTypes.object, + index: PropTypes.number, +}; + +const MonitorDetailsAreaChart = ({ checks }) => { + const theme = useTheme(); + const memoizedChecks = useMemo(() => checks, [checks[0]]); + const [isHovered, setIsHovered] = useState(false); + return ( { left: 0, bottom: 0, }} + onMouseMove={() => setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} > { } + minTickGap={0} + axisLine={false} tickLine={false} - height={18} + height={20} + interval="equidistantPreserveStart" /> } + wrapperStyle={{ pointerEvents: "none" }} /> diff --git a/Client/src/Components/Charts/PagespeedLineChart/index.css b/Client/src/Components/Charts/PagespeedLineChart/index.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/Client/src/Components/Charts/PagespeedLineChart/index.jsx b/Client/src/Components/Charts/PagespeedLineChart/index.jsx deleted file mode 100644 index 270cbaca0..000000000 --- a/Client/src/Components/Charts/PagespeedLineChart/index.jsx +++ /dev/null @@ -1,71 +0,0 @@ -import { LineChart } from "@mui/x-charts/LineChart"; -import PropTypes from "prop-types"; - -const PageSpeedLineChart = ({ pageSpeedChecks = [] }) => { - const keyToLabel = { - performance: "Performance", - seo: "SEO", - bestPractices: "Best practices", - accessibility: "Accessibility", - }; - - const colors = { - performance: "#2aa02b", - seo: "#9467bd", - bestPractices: "#ff7f0e", - accessibility: "#1f76b3", - }; - - const customize = { - legend: { position: { vertical: "bottom", horizontal: "middle" } }, - margin: { bottom: 75 }, - }; - - const xLabels = pageSpeedChecks.map((check) => { - return check.createdAt; - }); - - return ( - ({ - dataKey: key, - label: keyToLabel[key], - color: colors[key], - showMark: false, - }))} - yAxis={[{ min: 0, max: 100 }]} - xAxis={[ - { - scaleType: "point", - data: xLabels, - valueFormatter: (val) => new Date(val).toLocaleDateString(), - }, - ]} - dataset={pageSpeedChecks} - {...customize} - grid={{ vertical: true, horizontal: true }} - tooltip={{ trigger: "none" }} - slotProps={{ - legend: { - direction: "row", - position: { vertical: "bottom", horizontal: "middle" }, - padding: 2, - itemMarkWidth: 8, - itemMarkHeight: 8, - markGap: 5, - itemGap: 15, - labelStyle: { - fontSize: 13, - color: "#344054" - } - }, - }} - /> - ); -}; - -PageSpeedLineChart.propTypes = { - pageSpeedChecks: PropTypes.array, -}; - -export default PageSpeedLineChart; diff --git a/Client/src/Components/Inputs/Autocomplete/index.jsx b/Client/src/Components/Inputs/Autocomplete/index.jsx deleted file mode 100644 index 5256efccc..000000000 --- a/Client/src/Components/Inputs/Autocomplete/index.jsx +++ /dev/null @@ -1,116 +0,0 @@ -import { Autocomplete, TextField } from "@mui/material"; -import React from "react"; -import PropTypes from "prop-types"; -import { useTheme } from "@emotion/react"; - -/** - * @example - * - * const options = [ - * { _id: "66d6119ef959cbc681e034f0", name: "Googler" }, - * { _id: "66d6119ef959cbc681e034f0", name: "CNN" }, - * { _id: "66d61a1bf959cbc681e0353f", name: "X Corp." }, - * ]; - * - * - * - */ - -/** - * AutoCompleteField component. - * - * @component - * @param {Object} props - The component props. - * @param {string} props.id - The ID of the autocomplete field. - * @param {string} props.type - The type of the input field (text or number). - * @param {Array} props.options - The options for the autocomplete field. - * @param {string} props.placeholder - The placeholder text for the input field. - * @param {boolean} props.disabled - Indicates if the field is disabled. - * @returns {JSX.Element} The AutoCompleteField component. - */ - -const AutoCompleteField = ({ - id, - type, - options, - placeholder = "Type to search", - disabled, -}) => { - const [value, setValue] = React.useState(); - const [inputValue, setInputValue] = React.useState(""); - const theme = useTheme(); - - return ( - { - setValue(newValue); - }} - inputValue={inputValue} - onInputChange={(event, newInputValue) => { - setInputValue(newInputValue); - }} - options={options} - getOptionLabel={(option) => option.name} - renderInput={(params) => ( - - )} - renderOption={(props, option) => { - const { key, ...optionProps } = props; - return ( -
  • -
    {{option.name}}
    -
  • - ); - }} - slotProps={{ - popper: { - sx: { - "& ul": { p: 0 }, - "& li": { borderRadius: theme.shape.borderRadius }, - }, - }, - paper: { - sx: { - p: 2, - fontSize: 13, - }, - }, - }} - /> - ); -}; - -AutoCompleteField.displayName = "AutoCompleteField"; - -AutoCompleteField.propTypes = { - id: PropTypes.string, - type: PropTypes.oneOf(["text", "number"]), - options: PropTypes.array, - placeholder: PropTypes.string, - disabled: PropTypes.bool, - setWidth: PropTypes.string, -}; - -export default AutoCompleteField; diff --git a/Client/src/Components/Inputs/Field/index.jsx b/Client/src/Components/Inputs/Field/index.jsx index 62c50eeff..e7326ec41 100644 --- a/Client/src/Components/Inputs/Field/index.jsx +++ b/Client/src/Components/Inputs/Field/index.jsx @@ -121,8 +121,9 @@ const Field = forwardRef( sx: { color: theme.palette.text.secondary, "&:-webkit-autofill": { - WebkitBoxShadow: `0 0 0 100px ${theme.palette.background.fill} inset`, + WebkitBoxShadow: `0 0 0 100px ${theme.palette.other.autofill} inset`, WebkitTextFillColor: theme.palette.text.secondary, + borderRadius: "0 5px 5px 0", }, }, }} diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx new file mode 100644 index 000000000..f4d931fd1 --- /dev/null +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -0,0 +1,150 @@ +import PropTypes from "prop-types"; +import { Box, ListItem, Autocomplete, TextField } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import SearchIcon from "../../../assets/icons/search.svg?react"; + +/** + * Search component using Material UI's Autocomplete. + * + * @param {Object} props + * @param {string} props.id - Unique identifier for the Autocomplete component + * @param {Array} props.options - Options to display in the Autocomplete dropdown + * @param {string} props.filteredBy - Key to access the option label from the options + * @param {string} props.value - Current input value for the Autocomplete + * @param {Function} props.handleChange - Function to call when the input changes + * @param {Object} props.sx - Additional styles to apply to the component + * @returns {JSX.Element} The rendered Search component + */ +const Search = ({ + id, + options, + filteredBy, + value, + handleInputChange, + handleChange, + sx, +}) => { + const theme = useTheme(); + + return ( + { + handleInputChange(newValue); + }} + onChange={(_, newValue) => { + handleChange && handleChange(newValue); + }} + fullWidth + freeSolo + disableClearable + options={options} + getOptionLabel={(option) => option[filteredBy]} + renderInput={(params) => ( + + + + ), + }} + sx={{ + "& fieldset": { + borderColor: theme.palette.border.light, + borderRadius: theme.shape.borderRadius, + }, + "& .MuiOutlinedInput-root:hover:not(:has(input:focus)):not(:has(textarea:focus)) fieldset": + { + borderColor: theme.palette.border.light, + }, + }} + /> + )} + filterOptions={(options, { inputValue }) => { + const filtered = options.filter((option) => + option[filteredBy].toLowerCase().includes(inputValue.toLowerCase()) + ); + + if (filtered.length === 0) { + return [{ [filteredBy]: "No monitors found", noOptions: true }]; + } + return filtered; + }} + renderOption={(props, option) => { + const { key, ...optionProps } = props; + return ( + + {option[filteredBy]} + + ); + }} + slotProps={{ + popper: { + keepMounted: true, + sx: { + "& ul": { p: 2 }, + "& li.MuiAutocomplete-option": { + color: theme.palette.text.secondary, + px: 4, + borderRadius: theme.shape.borderRadius, + }, + "& .MuiAutocomplete-listbox .MuiAutocomplete-option[aria-selected='true'], & .MuiAutocomplete-listbox .MuiAutocomplete-option[aria-selected='true'].Mui-focused, & .MuiAutocomplete-listbox .MuiAutocomplete-option[aria-selected='true']:hover": + { + backgroundColor: theme.palette.background.fill, + }, + "& .MuiAutocomplete-noOptions": { + px: theme.spacing(6), + py: theme.spacing(5), + }, + }, + }, + }} + sx={{ + height: 34, + "&.MuiAutocomplete-root .MuiAutocomplete-input": { p: 0 }, + ...sx, + }} + /> + ); +}; + +Search.propTypes = { + id: PropTypes.string, + options: PropTypes.array.isRequired, + filteredBy: PropTypes.string.isRequired, + value: PropTypes.string.isRequired, + handleInputChange: PropTypes.func.isRequired, + handleChange: PropTypes.func, + sx: PropTypes.object, +}; + +export default Search; diff --git a/Client/src/Components/Search/index.css b/Client/src/Components/Search/index.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/Client/src/Components/Search/index.jsx b/Client/src/Components/Search/index.jsx deleted file mode 100644 index 391b95c02..000000000 --- a/Client/src/Components/Search/index.jsx +++ /dev/null @@ -1,49 +0,0 @@ -import Autocomplete from '@mui/material/Autocomplete'; -import TextField from '@mui/material/TextField'; -import Chip from '@mui/material/Chip'; -import Box from '@mui/material/Box'; -import { useTheme } from "@mui/material"; - -const teamMembers = [ - { title: 'John Doe'}, - { title: 'Jane Smith'}, - { title: 'Alex Johnson'}, -]; - -/** - * @component - * @returns {JSX.Element} - */ - -export default function Search() - { - const theme = useTheme(); - return ( - {/* Add padding to the container */} - option.title} - filterSelectedOptions - renderInput={(params) => ( - - )} - renderTags={(value, getTagProps) => - value.map((option) => ( - - )) - } - /> - - ); -} diff --git a/Client/src/Features/Auth/authSlice.js b/Client/src/Features/Auth/authSlice.js index f12758715..f6d40c38a 100644 --- a/Client/src/Features/Auth/authSlice.js +++ b/Client/src/Features/Auth/authSlice.js @@ -67,7 +67,7 @@ export const update = createAsyncThunk( fd.append("deleteProfileImage", form.deleteProfileImage); const res = await networkService.updateUser(token, user._id, fd); - + console.log(res); return res.data; } catch (error) { if (error.response && error.response.data) { diff --git a/Client/src/Features/UI/uiSlice.js b/Client/src/Features/UI/uiSlice.js index 947055ddc..2b6a08e8d 100644 --- a/Client/src/Features/UI/uiSlice.js +++ b/Client/src/Features/UI/uiSlice.js @@ -14,6 +14,7 @@ const initialState = { }, mode: "light", greeting: { index: 0, lastUpdate: null }, + timezone: "America/Toronto", }; const uiSlice = createSlice({ @@ -36,9 +37,17 @@ const uiSlice = createSlice({ state.greeting.index = action.payload.index; state.greeting.lastUpdate = action.payload.lastUpdate; }, + setTimezone(state, action) { + state.timezone = action.payload.timezone; + }, }, }); export default uiSlice.reducer; -export const { setRowsPerPage, toggleSidebar, setMode, setGreeting } = - uiSlice.actions; +export const { + setRowsPerPage, + toggleSidebar, + setMode, + setGreeting, + setTimezone, +} = uiSlice.actions; diff --git a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js index ac3ce1d6f..a8b1ea737 100644 --- a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js +++ b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js @@ -164,6 +164,44 @@ export const deleteMonitorChecksByTeamId = createAsyncThunk( } } ); +export const addDemoMonitors = createAsyncThunk( + "monitors/addDemoMonitors", + async (data, thunkApi) => { + try { + const { authToken } = data; + const res = await networkService.addDemoMonitors(authToken); + return res.data; + } catch (error) { + if (error.response && error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); + } + } +); +export const deleteAllMonitors = createAsyncThunk( + "monitors/deleteAllMonitors", + async (data, thunkApi) => { + try { + const { authToken } = data; + const res = await networkService.deleteAllMonitors(authToken); + return res.data; + } catch (error) { + if (error.response && error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); + } + } +); const uptimeMonitorsSlice = createSlice({ name: "uptimeMonitors", @@ -306,6 +344,42 @@ const uptimeMonitorsSlice = createSlice({ state.msg = action.payload ? action.payload.msg : "Failed to pause uptime monitor"; + }) + // ***************************************************** + // Add Demo Monitors + // ***************************************************** + .addCase(addDemoMonitors.pending, (state) => { + state.isLoading = true; + }) + .addCase(addDemoMonitors.fulfilled, (state, action) => { + state.isLoading = false; + state.success = action.payload.success; + state.msg = action.payload.msg; + }) + .addCase(addDemoMonitors.rejected, (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to add demo uptime monitors"; + }) + // ***************************************************** + // Delete all Monitors + // ***************************************************** + .addCase(deleteAllMonitors.pending, (state) => { + state.isLoading = true; + }) + .addCase(deleteAllMonitors.fulfilled, (state, action) => { + state.isLoading = false; + state.success = action.payload.success; + state.msg = action.payload.msg; + }) + .addCase(deleteAllMonitors.rejected, (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to delete all monitors"; }); }, }); diff --git a/Client/src/Pages/Incidents/IncidentTable/index.jsx b/Client/src/Pages/Incidents/IncidentTable/index.jsx index d10c79c68..6ca18a1e9 100644 --- a/Client/src/Pages/Incidents/IncidentTable/index.jsx +++ b/Client/src/Pages/Incidents/IncidentTable/index.jsx @@ -21,9 +21,16 @@ import { networkService } from "../../../main"; import { StatusLabel } from "../../../Components/Label"; import { logger } from "../../../Utils/Logger"; import { useTheme } from "@emotion/react"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; +import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react"; +import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react"; + const IncidentTable = ({ monitors, selectedMonitor, filter }) => { + const uiTimezone = useSelector((state) => state.ui.timezone); + const theme = useTheme(); const { authToken, user } = useSelector((state) => state.auth); + const mode = useSelector((state) => state.ui.mode); const [checks, setChecks] = useState([]); const [checksCount, setChecksCount] = useState(0); const [paginationController, setPaginationController] = useState({ @@ -109,6 +116,7 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { {...item} /> )} + sx={{ mt: "auto" }} /> ); } @@ -125,12 +133,18 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { <> {checks?.length === 0 && selectedMonitor === "0" ? ( + + {mode === "light" ? : } + No incidents recorded yet. ) : checks?.length === 0 ? ( + + {mode === "light" ? : } + The monitor you have selected has no recorded incidents yet. @@ -151,6 +165,11 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { {checks.map((check) => { const status = check.status === true ? "up" : "down"; + const formattedDate = formatDateWithTz( + check.createdAt, + "YYYY-MM-DD HH:mm:ss A", + uiTimezone + ); return ( @@ -162,9 +181,7 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { customStyles={{ textTransform: "capitalize" }} /> - - {new Date(check.createdAt).toLocaleString()} - + {formattedDate} {check.statusCode ? check.statusCode : "N/A"} diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index 1fd91c10a..10ab30ad5 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -1,16 +1,19 @@ import { useState, useEffect } from "react"; import { useSelector } from "react-redux"; import { ButtonGroup, Stack, Typography, Button } from "@mui/material"; +import { useParams } from "react-router-dom"; + import { networkService } from "../../main"; import { useTheme } from "@emotion/react"; import Select from "../../Components/Inputs/Select"; import IncidentTable from "./IncidentTable"; -import "./index.css"; import SkeletonLayout from "./skeleton"; +import "./index.css"; const Incidents = () => { const theme = useTheme(); const authState = useSelector((state) => state.auth); + const { monitorId } = useParams(); const [monitors, setMonitors] = useState({}); const [selectedMonitor, setSelectedMonitor] = useState("0"); @@ -22,17 +25,20 @@ const Incidents = () => { useEffect(() => { const fetchMonitors = async () => { setLoading(true); - const res = await networkService.getMonitorsByTeamId( - authState.authToken, - authState.user.teamId, - 1, - null, - null, - null, - null, - null, - null - ); + const res = await networkService.getMonitorsByTeamId({ + authToken: authState.authToken, + teamId: authState.user.teamId, + limit: -1, + types: null, + status: null, + checkOrder: null, + normalize: null, + page: null, + rowsPerPage: null, + filter: null, + field: null, + order: null, + }); // Reduce to a lookup object for 0(1) lookup if (res?.data?.data?.monitors?.length > 0) { const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => { @@ -40,6 +46,7 @@ const Incidents = () => { return acc; }, {}); setMonitors(monitorLookup); + monitorId !== undefined && setSelectedMonitor(monitorId); } setLoading(false); }; @@ -54,7 +61,7 @@ const Incidents = () => { }; return ( - + {loading ? ( ) : ( diff --git a/Client/src/Pages/Monitors/Configure/index.css b/Client/src/Pages/Monitors/Configure/index.css index 032833924..c59936d46 100644 --- a/Client/src/Pages/Monitors/Configure/index.css +++ b/Client/src/Pages/Monitors/Configure/index.css @@ -1,6 +1,3 @@ -.configure-monitor h1.MuiTypography-root + span.MuiTypography-root { - font-size: var(--env-var-font-size-small-plus); -} .configure-monitor button.MuiButtonBase-root { height: var(--env-var-height-2); } diff --git a/Client/src/Pages/Monitors/Configure/index.jsx b/Client/src/Pages/Monitors/Configure/index.jsx index 34076dd89..cd55837a7 100644 --- a/Client/src/Pages/Monitors/Configure/index.jsx +++ b/Client/src/Pages/Monitors/Configure/index.jsx @@ -223,12 +223,7 @@ const Configure = () => { > - + {monitor.name} { /> - + {monitor.url?.replace(/^https?:\/\//, "") || "..."} { ]; return ( - + { gap={theme.spacing(12)} mt={theme.spacing(6)} > - - + + Create your{" "} - + monitor @@ -262,7 +256,7 @@ const CreateMonitor = () => { onChange={(event) => handleChange(event)} /> {monitor.type === "http" ? ( - +