Merge pull request #2434 from bluewave-labs/fix/redux-removal-action-menu
fix: remove redux from action menu
This commit is contained in:
28 files changed
+132
-1379
No files matched your search
@@ -1,17 +1,18 @@
|
|||||||
|
// Components
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import Menu from "@mui/material/Menu";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import Settings from "../../assets/icons/settings-bold.svg?react";
|
||||||
|
import Dialog from "../../Components/Dialog";
|
||||||
|
|
||||||
|
// Utils
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { createToast } from "../../Utils/toastUtils";
|
import { createToast } from "../../Utils/toastUtils";
|
||||||
import { logger } from "../../Utils/Logger";
|
|
||||||
import { IconButton, Menu, MenuItem } from "@mui/material";
|
|
||||||
import {
|
|
||||||
deleteUptimeMonitor,
|
|
||||||
pauseUptimeMonitor,
|
|
||||||
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
import Settings from "../../assets/icons/settings-bold.svg?react";
|
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import Dialog from "../../Components/Dialog";
|
import { usePauseMonitor, useDeleteMonitor } from "../../Hooks/monitorHooks";
|
||||||
|
|
||||||
const ActionsMenu = ({
|
const ActionsMenu = ({
|
||||||
monitor,
|
monitor,
|
||||||
@@ -23,38 +24,27 @@ const ActionsMenu = ({
|
|||||||
const [anchorEl, setAnchorEl] = useState(null);
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
const [actions, setActions] = useState({});
|
const [actions, setActions] = useState({});
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const dispatch = useDispatch();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
const [pauseMonitor, isPausing, error] = usePauseMonitor();
|
||||||
|
const [deleteMonitor, isDeleting] = useDeleteMonitor();
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
let monitor = { _id: actions.id };
|
let monitor = { _id: actions.id };
|
||||||
const action = await dispatch(deleteUptimeMonitor({ monitor }));
|
await deleteMonitor({ monitor });
|
||||||
if (action.meta.requestStatus === "fulfilled") {
|
updateRowCallback();
|
||||||
setIsOpen(false); // close modal
|
|
||||||
updateRowCallback();
|
|
||||||
createToast({ body: "Monitor deleted successfully." });
|
|
||||||
} else {
|
|
||||||
createToast({ body: "Failed to delete monitor." });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePause = async () => {
|
const handlePause = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const action = await dispatch(pauseUptimeMonitor({ monitorId: monitor._id }));
|
await pauseMonitor({ monitorId: monitor._id });
|
||||||
if (pauseUptimeMonitor.fulfilled.match(action)) {
|
pauseCallback();
|
||||||
const state = action?.payload?.data.isActive === false ? "resumed" : "paused";
|
|
||||||
createToast({ body: `Monitor ${state} successfully.` });
|
|
||||||
pauseCallback();
|
|
||||||
} else {
|
|
||||||
throw new Error(action?.error?.message ?? "Failed to pause monitor.");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error pausing monitor:", monitor._id, error);
|
|
||||||
createToast({ body: "Failed to pause monitor." });
|
createToast({ body: "Failed to pause monitor." });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -210,7 +200,7 @@ const ActionsMenu = ({
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
handleRemove(e);
|
handleRemove(e);
|
||||||
}}
|
}}
|
||||||
isLoading={isLoading}
|
isLoading={isDeleting}
|
||||||
modelTitle="modal-delete-monitor"
|
modelTitle="modal-delete-monitor"
|
||||||
modelDescription="delete-monitor-confirmation"
|
modelDescription="delete-monitor-confirmation"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ Dialog.propTypes = {
|
|||||||
onCancel: PropTypes.func.isRequired,
|
onCancel: PropTypes.func.isRequired,
|
||||||
confirmationButtonLabel: PropTypes.string.isRequired,
|
confirmationButtonLabel: PropTypes.string.isRequired,
|
||||||
onConfirm: PropTypes.func.isRequired,
|
onConfirm: PropTypes.func.isRequired,
|
||||||
isLoading: PropTypes.bool.isRequired,
|
isLoading: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dialog;
|
export default Dialog;
|
||||||
@@ -49,7 +49,6 @@ import { useDispatch, useSelector } from "react-redux";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { clearAuthState } from "../../Features/Auth/authSlice";
|
import { clearAuthState } from "../../Features/Auth/authSlice";
|
||||||
import { toggleSidebar } from "../../Features/UI/uiSlice";
|
import { toggleSidebar } from "../../Features/UI/uiSlice";
|
||||||
import { clearUptimeMonitorState } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
|
|
||||||
const getMenu = (t) => [
|
const getMenu = (t) => [
|
||||||
{ name: t("menu.uptime"), path: "uptime", icon: <Monitors /> },
|
{ name: t("menu.uptime"), path: "uptime", icon: <Monitors /> },
|
||||||
@@ -197,7 +196,6 @@ function Sidebar() {
|
|||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
// Clear auth state
|
// Clear auth state
|
||||||
dispatch(clearAuthState());
|
dispatch(clearAuthState());
|
||||||
dispatch(clearUptimeMonitorState());
|
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ const StatBox = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
StatBox.propTypes = {
|
StatBox.propTypes = {
|
||||||
heading: PropTypes.string.isRequired,
|
heading: PropTypes.string,
|
||||||
subHeading: PropTypes.node.isRequired,
|
subHeading: PropTypes.node,
|
||||||
gradient: PropTypes.bool,
|
gradient: PropTypes.bool,
|
||||||
status: PropTypes.string,
|
status: PropTypes.string,
|
||||||
sx: PropTypes.object,
|
sx: PropTypes.object,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import ImageUpload from "../../Inputs/ImageUpload";
|
|||||||
import { newOrChangedCredentials } from "../../../Validation/validation";
|
import { newOrChangedCredentials } from "../../../Validation/validation";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { clearAuthState, deleteUser, update } from "../../../Features/Auth/authSlice";
|
import { clearAuthState, deleteUser, update } from "../../../Features/Auth/authSlice";
|
||||||
import { clearUptimeMonitorState } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
import { GenericDialog } from "../../Dialog/genericDialog";
|
import { GenericDialog } from "../../Dialog/genericDialog";
|
||||||
@@ -162,7 +161,6 @@ const ProfilePanel = () => {
|
|||||||
const action = await dispatch(deleteUser());
|
const action = await dispatch(deleteUser());
|
||||||
if (action.payload.success) {
|
if (action.payload.success) {
|
||||||
dispatch(clearAuthState());
|
dispatch(clearAuthState());
|
||||||
dispatch(clearUptimeMonitorState());
|
|
||||||
} else {
|
} else {
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
// dispatch errors
|
// dispatch errors
|
||||||
|
|||||||
@@ -1,389 +0,0 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
||||||
import { networkService } from "../../main";
|
|
||||||
const initialState = {
|
|
||||||
isLoading: false,
|
|
||||||
monitorsSummary: [],
|
|
||||||
success: null,
|
|
||||||
msg: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/createMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.createMonitor({ monitor: monitor });
|
|
||||||
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 checkInfrastructureEndpointResolution = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/CheckEndpoint",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorURL } = data;
|
|
||||||
const res = await networkService.checkEndpointResolution({
|
|
||||||
monitorURL: monitorURL,
|
|
||||||
});
|
|
||||||
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 getInfrastructureMonitorById = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/getMonitorById",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
|
||||||
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 getInfrastructureMonitorsByTeamId = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/getMonitorsByTeamId",
|
|
||||||
async (_, thunkApi) => {
|
|
||||||
const user = thunkApi.getState().auth.user;
|
|
||||||
try {
|
|
||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
|
||||||
teamId: user.teamId,
|
|
||||||
types: ["hardware"],
|
|
||||||
limit: 1,
|
|
||||||
rowsPerPage: 0,
|
|
||||||
});
|
|
||||||
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 updateInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/updateMonitor",
|
|
||||||
async ({ monitorId, monitor }, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const updatedFields = {
|
|
||||||
name: monitor.name,
|
|
||||||
description: monitor.description,
|
|
||||||
interval: monitor.interval,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
thresholds: monitor.thresholds,
|
|
||||||
secret: monitor.secret,
|
|
||||||
};
|
|
||||||
const res = await networkService.updateMonitor({
|
|
||||||
monitorId,
|
|
||||||
monitor,
|
|
||||||
updatedFields,
|
|
||||||
});
|
|
||||||
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 deleteInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/deleteMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.deleteMonitorById({ monitorId: monitor._id });
|
|
||||||
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 pauseInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/pauseMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.pauseMonitorById({ monitorId: monitorId });
|
|
||||||
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 deleteInfrastructureMonitorChecksByTeamId = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/deleteChecksByTeamId",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { teamId } = data;
|
|
||||||
const res = await networkService.deleteChecksByTeamId({ teamId: teamId });
|
|
||||||
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 deleteAllInfrastructureMonitors = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/deleteAllMonitors",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const res = await networkService.deleteAllMonitors();
|
|
||||||
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 infrastructureMonitorsSlice = createSlice({
|
|
||||||
name: "infrastructureMonitors",
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
clearInfrastructureMonitorState: (state) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.monitorsSummary = [];
|
|
||||||
state.success = null;
|
|
||||||
state.msg = null;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
// *****************************************************
|
|
||||||
// Monitors by teamId
|
|
||||||
// *****************************************************
|
|
||||||
|
|
||||||
.addCase(getInfrastructureMonitorsByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorsByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.msg;
|
|
||||||
state.monitorsSummary = action.payload.data;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorsByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Getting infrastructure monitors failed";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Create Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(createInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(createInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(createInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to create infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Resolve Endpoint
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(checkInfrastructureEndpointResolution.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(checkInfrastructureEndpointResolution.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(checkInfrastructureEndpointResolution.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to check endpoint resolution";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Get Monitor By Id
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(getInfrastructureMonitorById.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorById.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorById.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to get infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// update Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(updateInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(updateInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(updateInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to update infrastructure monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor checks by Team ID
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteInfrastructureMonitorChecksByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitorChecksByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitorChecksByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete monitor checks";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Pause Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(pauseInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(pauseInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(pauseInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to pause infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Delete all Monitors
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteAllInfrastructureMonitors.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteAllInfrastructureMonitors.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteAllInfrastructureMonitors.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload ? action.payload.msg : "Failed to delete all monitors";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setInfrastructureMonitors, clearInfrastructureMonitorState } =
|
|
||||||
infrastructureMonitorsSlice.actions;
|
|
||||||
|
|
||||||
export default infrastructureMonitorsSlice.reducer;
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
||||||
import { networkService } from "../../main";
|
|
||||||
const initialState = {
|
|
||||||
isLoading: false,
|
|
||||||
monitorsSummary: [],
|
|
||||||
success: null,
|
|
||||||
msg: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createPageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/createPageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.createMonitor({ monitor: monitor });
|
|
||||||
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 checkEndpointResolution = createAsyncThunk(
|
|
||||||
"monitors/checkEndpoint",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorURL } = data;
|
|
||||||
const res = await networkService.checkEndpointResolution({
|
|
||||||
monitorURL: monitorURL,
|
|
||||||
});
|
|
||||||
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 getPagespeedMonitorById = createAsyncThunk(
|
|
||||||
"monitors/getMonitorById",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
|
||||||
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 getPageSpeedByTeamId = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/getPageSpeedByTeamId",
|
|
||||||
async (_, thunkApi) => {
|
|
||||||
const user = thunkApi.getState().auth.user;
|
|
||||||
try {
|
|
||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
|
||||||
teamId: user.teamId,
|
|
||||||
types: ["pagespeed"],
|
|
||||||
});
|
|
||||||
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 updatePageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/updatePageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const updatedFields = {
|
|
||||||
name: monitor.name,
|
|
||||||
description: monitor.description,
|
|
||||||
interval: monitor.interval,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
};
|
|
||||||
const res = await networkService.updateMonitor({
|
|
||||||
monitorId: monitor._id,
|
|
||||||
updatedFields: updatedFields,
|
|
||||||
});
|
|
||||||
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 deletePageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/deletePageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.deleteMonitorById({ monitorId: monitor._id });
|
|
||||||
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 pausePageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/pausePageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.pauseMonitorById({ monitorId: monitorId });
|
|
||||||
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 pageSpeedMonitorSlice = createSlice({
|
|
||||||
name: "pageSpeedMonitor",
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
clearMonitorState: (state) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.monitorsSummary = [];
|
|
||||||
state.success = null;
|
|
||||||
state.msg = null;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
// *****************************************************
|
|
||||||
// Monitors by teamId
|
|
||||||
// *****************************************************
|
|
||||||
|
|
||||||
.addCase(getPageSpeedByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getPageSpeedByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.msg;
|
|
||||||
state.monitorsSummary = action.payload.data;
|
|
||||||
})
|
|
||||||
.addCase(getPageSpeedByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Getting page speed monitors failed";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(getPagespeedMonitorById.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getPagespeedMonitorById.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(getPagespeedMonitorById.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to get pagespeed monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Create Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(createPageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(createPageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(createPageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to create page speed monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Resolve Endpoint
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(checkEndpointResolution.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(checkEndpointResolution.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(checkEndpointResolution.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to check endpoint resolution";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Update Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(updatePageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(updatePageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(updatePageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to update page speed monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deletePageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deletePageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deletePageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete page speed monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Pause Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(pausePageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(pausePageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(pausePageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to pause page speed monitor";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setMonitors, clearMonitorState } = pageSpeedMonitorSlice.actions;
|
|
||||||
|
|
||||||
export default pageSpeedMonitorSlice.reducer;
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import { networkService } from "../../main";
|
|
||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
||||||
|
|
||||||
const initialState = {
|
|
||||||
isLoading: false,
|
|
||||||
apiBaseUrl: "",
|
|
||||||
logLevel: "debug",
|
|
||||||
pagespeedApiKey: "",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getAppSettings = createAsyncThunk(
|
|
||||||
"settings/getSettings",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const res = await networkService.getAppSettings();
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (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 updateAppSettings = createAsyncThunk(
|
|
||||||
"settings/updateSettings",
|
|
||||||
async ({ settings }, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const parsedSettings = {
|
|
||||||
language: settings.language,
|
|
||||||
pagespeedApiKey: settings.pagespeedApiKey,
|
|
||||||
};
|
|
||||||
const res = await networkService.updateAppSettings({ settings: parsedSettings });
|
|
||||||
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 handleGetSettingsFulfilled = (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
state.apiBaseUrl = action.payload.data.apiBaseUrl;
|
|
||||||
state.logLevel = action.payload.data.logLevel;
|
|
||||||
state.language = action.payload.data.language;
|
|
||||||
state.pagespeedApiKey = action.payload.data.pagespeedApiKey;
|
|
||||||
};
|
|
||||||
const handleGetSettingsRejected = (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload ? action.payload.msg : "Failed to get settings.";
|
|
||||||
};
|
|
||||||
const handleUpdateSettingsFulfilled = (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
state.apiBaseUrl = action.payload.data.apiBaseUrl;
|
|
||||||
state.logLevel = action.payload.data.logLevel;
|
|
||||||
};
|
|
||||||
const handleUpdateSettingsRejected = (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload ? action.payload.msg : "Failed to update settings.";
|
|
||||||
};
|
|
||||||
|
|
||||||
const settingsSlice = createSlice({
|
|
||||||
name: "settings",
|
|
||||||
initialState,
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
.addCase(getAppSettings.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getAppSettings.fulfilled, handleGetSettingsFulfilled)
|
|
||||||
.addCase(getAppSettings.rejected, handleGetSettingsRejected);
|
|
||||||
|
|
||||||
builder
|
|
||||||
.addCase(updateAppSettings.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(updateAppSettings.fulfilled, handleUpdateSettingsFulfilled)
|
|
||||||
.addCase(updateAppSettings.rejected, handleUpdateSettingsRejected);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default settingsSlice.reducer;
|
|
||||||
@@ -1,380 +0,0 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
||||||
import { networkService } from "../../main";
|
|
||||||
const initialState = {
|
|
||||||
isLoading: false,
|
|
||||||
monitorsSummary: [],
|
|
||||||
success: null,
|
|
||||||
msg: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createUptimeMonitor = createAsyncThunk(
|
|
||||||
"monitors/createMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.createMonitor({ monitor: monitor });
|
|
||||||
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 checkEndpointResolution = createAsyncThunk(
|
|
||||||
"monitors/checkEndpoint",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorURL } = data;
|
|
||||||
const res = await networkService.checkEndpointResolution({
|
|
||||||
monitorURL: monitorURL,
|
|
||||||
});
|
|
||||||
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 getUptimeMonitorById = createAsyncThunk(
|
|
||||||
"monitors/getMonitorById",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
|
||||||
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 updateUptimeMonitor = createAsyncThunk(
|
|
||||||
"monitors/updateMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const updatedFields = {
|
|
||||||
name: monitor.name,
|
|
||||||
description: monitor.description,
|
|
||||||
interval: monitor.interval,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
matchMethod: monitor.matchMethod,
|
|
||||||
expectedValue: monitor.expectedValue,
|
|
||||||
ignoreTlsErrors: monitor.ignoreTlsErrors,
|
|
||||||
jsonPath: monitor.jsonPath,
|
|
||||||
...(monitor.type === "port" && { port: monitor.port }),
|
|
||||||
};
|
|
||||||
const res = await networkService.updateMonitor({
|
|
||||||
monitorId: monitor._id,
|
|
||||||
updatedFields,
|
|
||||||
});
|
|
||||||
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 deleteUptimeMonitor = createAsyncThunk(
|
|
||||||
"monitors/deleteMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.deleteMonitorById({ monitorId: monitor._id });
|
|
||||||
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 pauseUptimeMonitor = createAsyncThunk(
|
|
||||||
"monitors/pauseMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.pauseMonitorById({ monitorId: monitorId });
|
|
||||||
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 deleteMonitorChecksByTeamId = createAsyncThunk(
|
|
||||||
"monitors/deleteChecksByTeamId",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { teamId } = data;
|
|
||||||
const res = await networkService.deleteChecksByTeamId({ teamId: teamId });
|
|
||||||
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 addDemoMonitors = createAsyncThunk(
|
|
||||||
"monitors/addDemoMonitors",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const res = await networkService.addDemoMonitors();
|
|
||||||
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 res = await networkService.deleteAllMonitors();
|
|
||||||
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",
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
clearUptimeMonitorState: (state) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.monitorsSummary = [];
|
|
||||||
state.success = null;
|
|
||||||
state.msg = null;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
// *****************************************************
|
|
||||||
// Create Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(createUptimeMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(createUptimeMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(createUptimeMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to create uptime monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Resolve Endpoint
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(checkEndpointResolution.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(checkEndpointResolution.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(checkEndpointResolution.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to check endpoint resolution";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Get Monitor By Id
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(getUptimeMonitorById.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getUptimeMonitorById.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(getUptimeMonitorById.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload ? action.payload.msg : "Failed to get uptime monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// update Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(updateUptimeMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(updateUptimeMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(updateUptimeMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to update uptime monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteUptimeMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteUptimeMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteUptimeMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete uptime monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor checks by Team ID
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteMonitorChecksByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteMonitorChecksByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteMonitorChecksByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete monitor checks";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Pause Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(pauseUptimeMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(pauseUptimeMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(pauseUptimeMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
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";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setUptimeMonitors, clearUptimeMonitorState } = uptimeMonitorsSlice.actions;
|
|
||||||
|
|
||||||
export default uptimeMonitorsSlice.reducer;
|
|
||||||
@@ -4,8 +4,9 @@ import { createToast } from "../Utils/toastUtils";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useMonitorUtils } from "./useMonitorUtils";
|
import { useMonitorUtils } from "./useMonitorUtils";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => {
|
const useFetchMonitorsWithSummary = ({ types, monitorUpdateTrigger }) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [monitors, setMonitors] = useState(undefined);
|
const [monitors, setMonitors] = useState(undefined);
|
||||||
const [monitorsSummary, setMonitorsSummary] = useState(undefined);
|
const [monitorsSummary, setMonitorsSummary] = useState(undefined);
|
||||||
@@ -16,7 +17,6 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) =>
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const res = await networkService.getMonitorsWithSummaryByTeamId({
|
const res = await networkService.getMonitorsWithSummaryByTeamId({
|
||||||
teamId,
|
|
||||||
types,
|
types,
|
||||||
});
|
});
|
||||||
const { monitors, summary } = res?.data?.data ?? {};
|
const { monitors, summary } = res?.data?.data ?? {};
|
||||||
@@ -33,12 +33,11 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) =>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}, [teamId, types, monitorUpdateTrigger]);
|
}, [types, monitorUpdateTrigger]);
|
||||||
return [monitors, monitorsSummary, isLoading, networkError];
|
return [monitors, monitorsSummary, isLoading, networkError];
|
||||||
};
|
};
|
||||||
|
|
||||||
const useFetchMonitorsWithChecks = ({
|
const useFetchMonitorsWithChecks = ({
|
||||||
teamId,
|
|
||||||
types,
|
types,
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
@@ -60,7 +59,6 @@ const useFetchMonitorsWithChecks = ({
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const res = await networkService.getMonitorsWithChecksByTeamId({
|
const res = await networkService.getMonitorsWithChecksByTeamId({
|
||||||
teamId,
|
|
||||||
limit,
|
limit,
|
||||||
types,
|
types,
|
||||||
page,
|
page,
|
||||||
@@ -94,7 +92,6 @@ const useFetchMonitorsWithChecks = ({
|
|||||||
order,
|
order,
|
||||||
page,
|
page,
|
||||||
rowsPerPage,
|
rowsPerPage,
|
||||||
teamId,
|
|
||||||
theme,
|
theme,
|
||||||
types,
|
types,
|
||||||
monitorUpdateTrigger,
|
monitorUpdateTrigger,
|
||||||
@@ -103,7 +100,6 @@ const useFetchMonitorsWithChecks = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useFetchMonitorsByTeamId = ({
|
const useFetchMonitorsByTeamId = ({
|
||||||
teamId,
|
|
||||||
types,
|
types,
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
@@ -126,7 +122,6 @@ const useFetchMonitorsByTeamId = ({
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const res = await networkService.getMonitorsByTeamId({
|
const res = await networkService.getMonitorsByTeamId({
|
||||||
teamId,
|
|
||||||
limit,
|
limit,
|
||||||
types,
|
types,
|
||||||
page,
|
page,
|
||||||
@@ -153,7 +148,6 @@ const useFetchMonitorsByTeamId = ({
|
|||||||
};
|
};
|
||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}, [
|
}, [
|
||||||
teamId,
|
|
||||||
types,
|
types,
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
@@ -383,6 +377,58 @@ const usePauseMonitor = () => {
|
|||||||
return [pauseMonitor, isLoading, error];
|
return [pauseMonitor, isLoading, error];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useAddDemoMonitors = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const addDemoMonitors = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.addDemoMonitors();
|
||||||
|
createToast({ body: t("settingsDemoMonitorsAdded") });
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: t("settingsFailedToAddDemoMonitors") });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return [addDemoMonitors, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
const useDeleteAllMonitors = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const deleteAllMonitors = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.deleteAllMonitors();
|
||||||
|
createToast({ body: t("settingsMonitorsDeleted") });
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: t("settingsFailedToDeleteMonitors") });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return [deleteAllMonitors, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
const UseDeleteMonitorStats = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const deleteMonitorStats = async ({ teamId }) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await networkService.deleteChecksByTeamId({ teamId });
|
||||||
|
createToast({ body: t("settingsStatsCleared") });
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: t("settingsFailedToClearStats") });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [deleteMonitorStats, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
useFetchMonitorsWithSummary,
|
useFetchMonitorsWithSummary,
|
||||||
useFetchMonitorsWithChecks,
|
useFetchMonitorsWithChecks,
|
||||||
@@ -395,4 +441,7 @@ export {
|
|||||||
useDeleteMonitor,
|
useDeleteMonitor,
|
||||||
useUpdateMonitor,
|
useUpdateMonitor,
|
||||||
usePauseMonitor,
|
usePauseMonitor,
|
||||||
|
useAddDemoMonitors,
|
||||||
|
useDeleteAllMonitors,
|
||||||
|
UseDeleteMonitorStats,
|
||||||
};
|
};
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { networkService } from "../main";
|
|
||||||
import { createToast } from "../Utils/toastUtils";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const UseDeleteMonitorStats = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const deleteMonitorStats = async ({ teamId }) => {
|
|
||||||
setIsLoading(true);
|
|
||||||
try {
|
|
||||||
const res = await networkService.deleteChecksByTeamId({ teamId });
|
|
||||||
createToast({ body: t("settingsStatsCleared") });
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: t("settingsFailedToClearStats") });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [deleteMonitorStats, isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { UseDeleteMonitorStats };
|
|
||||||
@@ -33,12 +33,13 @@ const useSaveSettings = () => {
|
|||||||
const saveSettings = async (settings) => {
|
const saveSettings = async (settings) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
await networkService.updateAppSettings({ settings });
|
const settingsResponse = await networkService.updateAppSettings({ settings });
|
||||||
if (settings.checkTTL) {
|
if (settings.checkTTL) {
|
||||||
await networkService.updateChecksTTL({
|
await networkService.updateChecksTTL({
|
||||||
ttl: settings.checkTTL,
|
ttl: settings.checkTTL,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log({ settingsResponse });
|
||||||
createToast({ body: t("settingsSuccessSaved") });
|
createToast({ body: t("settingsSuccessSaved") });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createToast({ body: t("settingsFailedToSave") });
|
createToast({ body: t("settingsFailedToSave") });
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { useTheme } from "@emotion/react";
|
|||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { clearAuthState } from "../../Features/Auth/authSlice";
|
import { clearAuthState } from "../../Features/Auth/authSlice";
|
||||||
import { clearUptimeMonitorState } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
import Background from "../../assets/Images/background-grid.svg?react";
|
import Background from "../../assets/Images/background-grid.svg?react";
|
||||||
import ConfirmIcon from "../../assets/icons/check-outlined.svg?react";
|
import ConfirmIcon from "../../assets/icons/check-outlined.svg?react";
|
||||||
import Logo from "../../assets/icons/checkmate-icon.svg?react";
|
import Logo from "../../assets/icons/checkmate-icon.svg?react";
|
||||||
@@ -19,7 +18,6 @@ const NewPasswordConfirmed = () => {
|
|||||||
|
|
||||||
const handleNavigate = () => {
|
const handleNavigate = () => {
|
||||||
dispatch(clearAuthState());
|
dispatch(clearAuthState());
|
||||||
dispatch(clearUptimeMonitorState());
|
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete }) => {
|
const MonitorsTable = ({ isLoading, monitors, isAdmin, handleActionMenuDelete }) => {
|
||||||
// Utils
|
// Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -86,6 +86,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
|
|||||||
monitor={row}
|
monitor={row}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
updateCallback={handleActionMenuDelete}
|
updateCallback={handleActionMenuDelete}
|
||||||
|
isLoading={isLoading}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -120,7 +121,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
shouldRender={shouldRender}
|
shouldRender={!isLoading}
|
||||||
headers={headers}
|
headers={headers}
|
||||||
data={data}
|
data={data}
|
||||||
config={{
|
config={{
|
||||||
@@ -140,7 +141,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
|
|||||||
};
|
};
|
||||||
|
|
||||||
MonitorsTable.propTypes = {
|
MonitorsTable.propTypes = {
|
||||||
shouldRender: PropTypes.bool,
|
isLoading: PropTypes.bool,
|
||||||
monitors: PropTypes.array,
|
monitors: PropTypes.array,
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
handleActionMenuDelete: PropTypes.func,
|
handleActionMenuDelete: PropTypes.func,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */
|
/* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */
|
||||||
|
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { createToast } from "../../../../../Utils/toastUtils";
|
import { createToast } from "../../../../../Utils/toastUtils";
|
||||||
@@ -30,7 +29,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
|
||||||
|
|
||||||
const openMenu = (e) => {
|
const openMenu = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -117,7 +115,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
onCancel={cancelRemove}
|
onCancel={cancelRemove}
|
||||||
confirmationButtonLabel="Delete"
|
confirmationButtonLabel="Delete"
|
||||||
onConfirm={handleRemove}
|
onConfirm={handleRemove}
|
||||||
isLoading={isLoading}
|
|
||||||
modelTitle="modal-delete-monitor"
|
modelTitle="modal-delete-monitor"
|
||||||
modelDescription="delete-monitor-confirmation"
|
modelDescription="delete-monitor-confirmation"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import Filter from "./Components/Filters";
|
|||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
|
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
|
||||||
@@ -21,7 +20,6 @@ const BREADCRUMBS = [{ name: `infrastructure`, path: "/infrastructure" }];
|
|||||||
|
|
||||||
const InfrastructureMonitors = () => {
|
const InfrastructureMonitors = () => {
|
||||||
// Redux state
|
// Redux state
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
|
|
||||||
// Local state
|
// Local state
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
@@ -56,7 +54,6 @@ const InfrastructureMonitors = () => {
|
|||||||
const field = toFilterStatus !== undefined ? "status" : undefined;
|
const field = toFilterStatus !== undefined ? "status" : undefined;
|
||||||
|
|
||||||
const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({
|
const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({
|
||||||
teamId: user.teamId,
|
|
||||||
limit: 1,
|
limit: 1,
|
||||||
types: TYPES,
|
types: TYPES,
|
||||||
page,
|
page,
|
||||||
@@ -118,7 +115,7 @@ const InfrastructureMonitors = () => {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<MonitorsTable
|
<MonitorsTable
|
||||||
shouldRender={!isLoading}
|
isLoading={isLoading}
|
||||||
monitors={monitors}
|
monitors={monitors}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
handleActionMenuDelete={handleActionMenuDelete}
|
handleActionMenuDelete={handleActionMenuDelete}
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ const CreateMaintenance = () => {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await networkService.getMonitorsByTeamId({
|
const response = await networkService.getMonitorsByTeamId({
|
||||||
teamId: user.teamId,
|
|
||||||
limit: null,
|
limit: null,
|
||||||
types: ["http", "ping", "pagespeed", "port"],
|
types: ["http", "ping", "pagespeed", "port"],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import GenericFallback from "../../../Components/GenericFallback";
|
|||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
|
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
|
||||||
@@ -20,11 +19,8 @@ const PageSpeed = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
const { pagespeedApiKey } = useSelector((state) => state.settings);
|
|
||||||
|
|
||||||
const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({
|
const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({
|
||||||
teamId: user.teamId,
|
|
||||||
limit: 10,
|
limit: 10,
|
||||||
types: TYPES,
|
types: TYPES,
|
||||||
page: null,
|
page: null,
|
||||||
@@ -60,7 +56,7 @@ const PageSpeed = () => {
|
|||||||
]}
|
]}
|
||||||
link="/pagespeed/create"
|
link="/pagespeed/create"
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
showPageSpeedWarning={isAdmin && !pagespeedApiKey}
|
// showPageSpeedWarning={isAdmin && !pagespeedApiKey}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,22 +11,20 @@ import SettingsEmail from "./SettingsEmail";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
// Utils
|
// Utils
|
||||||
import { settingsValidation } from "../../Validation/validation";
|
import { settingsValidation } from "../../Validation/validation";
|
||||||
import { createToast } from "../../Utils/toastUtils";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { setTimezone, setMode, setLanguage, setShowURL } from "../../Features/UI/uiSlice";
|
import { setTimezone, setMode, setLanguage, setShowURL } from "../../Features/UI/uiSlice";
|
||||||
import SettingsStats from "./SettingsStats";
|
import SettingsStats from "./SettingsStats";
|
||||||
import {
|
|
||||||
deleteMonitorChecksByTeamId,
|
|
||||||
addDemoMonitors,
|
|
||||||
deleteAllMonitors,
|
|
||||||
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
import { useFetchSettings, useSaveSettings } from "../../Hooks/useFetchSettings";
|
|
||||||
import { UseDeleteMonitorStats } from "../../Hooks/useDeleteMonitorStats";
|
|
||||||
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
|
||||||
|
|
||||||
|
import { useFetchSettings, useSaveSettings } from "../../Hooks/useFetchSettings";
|
||||||
|
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
||||||
|
import {
|
||||||
|
useAddDemoMonitors,
|
||||||
|
useDeleteAllMonitors,
|
||||||
|
UseDeleteMonitorStats,
|
||||||
|
} from "../../Hooks/monitorHooks";
|
||||||
// Constants
|
// Constants
|
||||||
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
||||||
|
|
||||||
@@ -43,15 +41,17 @@ const Settings = () => {
|
|||||||
const [isSettingsLoading, settingsError] = useFetchSettings({
|
const [isSettingsLoading, settingsError] = useFetchSettings({
|
||||||
setSettingsData,
|
setSettingsData,
|
||||||
});
|
});
|
||||||
|
const [addDemoMonitors, isAddingDemoMonitors] = useAddDemoMonitors();
|
||||||
|
|
||||||
const [isSaving, saveError, saveSettings] = useSaveSettings();
|
const [isSaving, saveError, saveSettings] = useSaveSettings();
|
||||||
|
const [deleteAllMonitors, isDeletingMonitors] = useDeleteAllMonitors();
|
||||||
const [deleteMonitorStats, isDeletingMonitorStats] = UseDeleteMonitorStats();
|
const [deleteMonitorStats, isDeletingMonitorStats] = UseDeleteMonitorStats();
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const HEADING_SX = { mt: theme.spacing(2), mb: theme.spacing(2) };
|
const HEADING_SX = { mt: theme.spacing(2), mb: theme.spacing(2) };
|
||||||
const { t, i18n } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
@@ -101,30 +101,12 @@ const Settings = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name === "demo") {
|
if (name === "demo") {
|
||||||
try {
|
await addDemoMonitors();
|
||||||
const action = await dispatch(addDemoMonitors());
|
|
||||||
if (addDemoMonitors.fulfilled.match(action)) {
|
|
||||||
createToast({ body: t("settingsDemoMonitorsAdded") });
|
|
||||||
} else {
|
|
||||||
createToast({ body: t("settingsFailedToAddDemoMonitors") });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: t("settingsFailedToAddDemoMonitors") });
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name === "deleteMonitors") {
|
if (name === "deleteMonitors") {
|
||||||
try {
|
await deleteAllMonitors();
|
||||||
const action = await dispatch(deleteAllMonitors());
|
|
||||||
if (deleteAllMonitors.fulfilled.match(action)) {
|
|
||||||
createToast({ body: t("settingsMonitorsDeleted") });
|
|
||||||
} else {
|
|
||||||
createToast({ body: t("settingsFailedToDeleteMonitors") });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: t("settingsFailedToDeleteMonitors") });
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +167,9 @@ const Settings = () => {
|
|||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
HEADER_SX={HEADING_SX}
|
HEADER_SX={HEADING_SX}
|
||||||
handleChange={handleChange}
|
handleChange={handleChange}
|
||||||
isLoading={isSettingsLoading || isSaving || isDeletingMonitorStats}
|
isLoading={
|
||||||
|
isSettingsLoading || isSaving || isDeletingMonitorStats || isAddingDemoMonitors
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<SettingsEmail
|
<SettingsEmail
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
@@ -219,7 +203,9 @@ const Settings = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
loading={isSaving || isDeletingMonitorStats || isSettingsLoading}
|
loading={
|
||||||
|
isSaving || isDeletingMonitorStats || isSettingsLoading || isDeletingMonitors
|
||||||
|
}
|
||||||
disabled={Object.keys(errors).length > 0}
|
disabled={Object.keys(errors).length > 0}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="accent"
|
color="accent"
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ const useMonitorsFetch = () => {
|
|||||||
const fetchMonitors = async () => {
|
const fetchMonitors = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await networkService.getMonitorsByTeamId({
|
const response = await networkService.getMonitorsByTeamId({
|
||||||
teamId: user.teamId,
|
|
||||||
limit: null, // donot return any checks for the monitors
|
limit: null, // donot return any checks for the monitors
|
||||||
types: ["http", "ping", "port"], // status page is available for uptime, ping, and port monitors
|
types: ["http", "ping", "port"], // status page is available for uptime, ping, and port monitors
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import { useCreateMonitor } from "../../../Hooks/monitorHooks";
|
|||||||
const CreateMonitor = () => {
|
const CreateMonitor = () => {
|
||||||
// Redux state
|
// Redux state
|
||||||
const { user } = useSelector((state) => state.auth);
|
const { user } = useSelector((state) => state.auth);
|
||||||
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
|
||||||
|
|
||||||
// Local state
|
// Local state
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
@@ -467,7 +466,7 @@ const CreateMonitor = () => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="accent"
|
color="accent"
|
||||||
disabled={!Object.values(errors).every((value) => value === undefined)}
|
disabled={!Object.values(errors).every((value) => value === undefined)}
|
||||||
loading={isLoading || isCreating}
|
loading={isCreating}
|
||||||
>
|
>
|
||||||
{t("createMonitor")}
|
{t("createMonitor")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ CreateMonitorButton.propTypes = {
|
|||||||
|
|
||||||
const UptimeMonitors = () => {
|
const UptimeMonitors = () => {
|
||||||
// Redux state
|
// Redux state
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage);
|
const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage);
|
||||||
|
|
||||||
// Local state
|
// Local state
|
||||||
@@ -106,11 +105,8 @@ const UptimeMonitors = () => {
|
|||||||
setMonitorUpdateTrigger((prev) => !prev);
|
setMonitorUpdateTrigger((prev) => !prev);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const teamId = user.teamId;
|
|
||||||
|
|
||||||
const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] =
|
const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] =
|
||||||
useFetchMonitorsWithSummary({
|
useFetchMonitorsWithSummary({
|
||||||
teamId,
|
|
||||||
types: TYPES,
|
types: TYPES,
|
||||||
monitorUpdateTrigger,
|
monitorUpdateTrigger,
|
||||||
});
|
});
|
||||||
@@ -140,7 +136,6 @@ const UptimeMonitors = () => {
|
|||||||
monitorsWithChecksIsLoading,
|
monitorsWithChecksIsLoading,
|
||||||
monitorsWithChecksNetworkError,
|
monitorsWithChecksNetworkError,
|
||||||
] = useFetchMonitorsWithChecks({
|
] = useFetchMonitorsWithChecks({
|
||||||
teamId,
|
|
||||||
types: effectiveTypes,
|
types: effectiveTypes,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
page: page,
|
page: page,
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ class Logger {
|
|||||||
constructor() {
|
constructor() {
|
||||||
let logLevel = LOG_LEVEL;
|
let logLevel = LOG_LEVEL;
|
||||||
this.unsubscribe = store.subscribe(() => {
|
this.unsubscribe = store.subscribe(() => {
|
||||||
const state = store.getState();
|
logLevel = "debug";
|
||||||
logLevel = state.settings.logLevel || "debug";
|
|
||||||
this.updateLogLevel(logLevel);
|
this.updateLogLevel(logLevel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import i18next from "i18next";
|
|||||||
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
||||||
const FALLBACK_BASE_URL = "http://localhost:5000/api/v1";
|
const FALLBACK_BASE_URL = "http://localhost:5000/api/v1";
|
||||||
import { clearAuthState } from "../Features/Auth/authSlice";
|
import { clearAuthState } from "../Features/Auth/authSlice";
|
||||||
import { clearUptimeMonitorState } from "../Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
constructor(store, dispatch, navigate) {
|
constructor(store, dispatch, navigate) {
|
||||||
this.store = store;
|
this.store = store;
|
||||||
@@ -56,7 +55,6 @@ class NetworkService {
|
|||||||
|
|
||||||
if (error.response && error.response.status === 401) {
|
if (error.response && error.response.status === 401) {
|
||||||
dispatch(clearAuthState());
|
dispatch(clearAuthState());
|
||||||
dispatch(clearUptimeMonitorState());
|
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
} else if (error.request && !error.response) {
|
} else if (error.request && !error.response) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
@@ -137,36 +135,6 @@ class NetworkService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* ************************************
|
|
||||||
* Gets monitors and summary of stats by TeamID
|
|
||||||
* ************************************
|
|
||||||
*
|
|
||||||
* @async
|
|
||||||
* @param {Object} config - The configuration object.
|
|
||||||
* @param {string} config.teamId - Team ID
|
|
||||||
* @param {Array<string>} config.types - Array of monitor types
|
|
||||||
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
|
|
||||||
*/
|
|
||||||
async getMonitorsSummaryByTeamId(config) {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
|
|
||||||
if (config.types) {
|
|
||||||
config.types.forEach((type) => {
|
|
||||||
params.append("type", type);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this.axiosInstance.get(
|
|
||||||
`/monitors/team/summary/${config.teamId}?${params.toString()}`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ************************************
|
* ************************************
|
||||||
* Get all uptime monitors for a Team
|
* Get all uptime monitors for a Team
|
||||||
@@ -186,7 +154,7 @@ class NetworkService {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
async getMonitorsByTeamId(config) {
|
async getMonitorsByTeamId(config) {
|
||||||
const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config;
|
const { limit, types, page, rowsPerPage, filter, field, order } = config;
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (limit) params.append("limit", limit);
|
if (limit) params.append("limit", limit);
|
||||||
@@ -201,7 +169,7 @@ class NetworkService {
|
|||||||
if (field) params.append("field", field);
|
if (field) params.append("field", field);
|
||||||
if (order) params.append("order", order);
|
if (order) params.append("order", order);
|
||||||
|
|
||||||
return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, {
|
return this.axiosInstance.get(`/monitors/team?${params.toString()}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
@@ -951,7 +919,7 @@ class NetworkService {
|
|||||||
// Fetch monitors with summary by TeamID
|
// Fetch monitors with summary by TeamID
|
||||||
// ************************************
|
// ************************************
|
||||||
async getMonitorsWithSummaryByTeamId(config) {
|
async getMonitorsWithSummaryByTeamId(config) {
|
||||||
const { teamId, types } = config;
|
const { types } = config;
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (types) {
|
if (types) {
|
||||||
@@ -960,21 +928,18 @@ class NetworkService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.axiosInstance.get(
|
return this.axiosInstance.get(`/monitors/summary/team?${params.toString()}`, {
|
||||||
`/monitors/summary/team/${teamId}?${params.toString()}`,
|
headers: {
|
||||||
{
|
"Content-Type": "application/json",
|
||||||
headers: {
|
},
|
||||||
"Content-Type": "application/json",
|
});
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************
|
// ************************************
|
||||||
// Fetch monitors with checks by TeamID
|
// Fetch monitors with checks by TeamID
|
||||||
// ************************************
|
// ************************************
|
||||||
async getMonitorsWithChecksByTeamId(config) {
|
async getMonitorsWithChecksByTeamId(config) {
|
||||||
const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config;
|
const { limit, types, page, rowsPerPage, filter, field, order } = config;
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (limit) params.append("limit", limit);
|
if (limit) params.append("limit", limit);
|
||||||
@@ -989,14 +954,11 @@ class NetworkService {
|
|||||||
if (field) params.append("field", field);
|
if (field) params.append("field", field);
|
||||||
if (order) params.append("order", order);
|
if (order) params.append("order", order);
|
||||||
|
|
||||||
return this.axiosInstance.get(
|
return this.axiosInstance.get(`/monitors/team/with-checks?${params.toString()}`, {
|
||||||
`/monitors/team/${teamId}/with-checks?${params.toString()}`,
|
headers: {
|
||||||
{
|
"Content-Type": "application/json",
|
||||||
headers: {
|
},
|
||||||
"Content-Type": "application/json",
|
});
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************
|
// ************************************
|
||||||
|
|||||||
+1
-9
@@ -1,11 +1,7 @@
|
|||||||
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
import uptimeMonitorsReducer from "./Features/UptimeMonitors/uptimeMonitorsSlice";
|
|
||||||
import infrastructureMonitorsReducer from "./Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
|
||||||
import pageSpeedMonitorReducer from "./Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
|
||||||
import authReducer from "./Features/Auth/authSlice";
|
import authReducer from "./Features/Auth/authSlice";
|
||||||
import uiReducer from "./Features/UI/uiSlice";
|
import uiReducer from "./Features/UI/uiSlice";
|
||||||
import settingsReducer from "./Features/Settings/settingsSlice";
|
|
||||||
import storage from "redux-persist/lib/storage";
|
import storage from "redux-persist/lib/storage";
|
||||||
import { persistReducer, persistStore, createTransform } from "redux-persist";
|
import { persistReducer, persistStore, createTransform } from "redux-persist";
|
||||||
|
|
||||||
@@ -23,17 +19,13 @@ const authTransform = createTransform(
|
|||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: "root",
|
key: "root",
|
||||||
storage,
|
storage,
|
||||||
whitelist: ["auth", "monitors", "pageSpeed", "ui", "settings"],
|
whitelist: ["auth", "ui"],
|
||||||
transforms: [authTransform],
|
transforms: [authTransform],
|
||||||
};
|
};
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
uptimeMonitors: uptimeMonitorsReducer,
|
|
||||||
infrastructureMonitors: infrastructureMonitorsReducer,
|
|
||||||
auth: authReducer,
|
auth: authReducer,
|
||||||
pageSpeedMonitors: pageSpeedMonitorReducer,
|
|
||||||
ui: uiReducer,
|
ui: uiReducer,
|
||||||
settings: settingsReducer,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||||
|
|||||||
@@ -519,7 +519,8 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
order = "asc";
|
order = "asc";
|
||||||
}
|
}
|
||||||
// Build match stage
|
// Build match stage
|
||||||
const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) };
|
const teamId = req.user.teamId;
|
||||||
|
const matchStage = { teamId: ObjectId.createFromHexString(teamId) };
|
||||||
if (type !== undefined) {
|
if (type !== undefined) {
|
||||||
matchStage.type = Array.isArray(type) ? { $in: type } : type;
|
matchStage.type = Array.isArray(type) ? { $in: type } : type;
|
||||||
}
|
}
|
||||||
@@ -560,7 +561,7 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
const getMonitorsAndSummaryByTeamId = async (req) => {
|
const getMonitorsAndSummaryByTeamId = async (req) => {
|
||||||
try {
|
try {
|
||||||
const { type } = req.query;
|
const { type } = req.query;
|
||||||
const teamId = ObjectId.createFromHexString(req.params.teamId);
|
const teamId = ObjectId.createFromHexString(req.user.teamId);
|
||||||
const matchStage = { teamId };
|
const matchStage = { teamId };
|
||||||
if (type !== undefined) {
|
if (type !== undefined) {
|
||||||
matchStage.type = Array.isArray(type) ? { $in: type } : type;
|
matchStage.type = Array.isArray(type) ? { $in: type } : type;
|
||||||
@@ -594,7 +595,7 @@ const getMonitorsWithChecksByTeamId = async (req) => {
|
|||||||
field = "name";
|
field = "name";
|
||||||
order = "asc";
|
order = "asc";
|
||||||
}
|
}
|
||||||
const teamId = ObjectId.createFromHexString(req.params.teamId);
|
const teamId = ObjectId.createFromHexString(req.user.teamId);
|
||||||
// Build match stage
|
// Build match stage
|
||||||
const matchStage = { teamId };
|
const matchStage = { teamId };
|
||||||
if (type !== undefined) {
|
if (type !== undefined) {
|
||||||
|
|||||||
@@ -35,17 +35,17 @@ class MonitorRoutes {
|
|||||||
fetchMonitorCertificate
|
fetchMonitorCertificate
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
|
||||||
|
|
||||||
this.router.get("/:monitorId", this.monitorController.getMonitorById);
|
this.router.get("/:monitorId", this.monitorController.getMonitorById);
|
||||||
|
|
||||||
this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId);
|
|
||||||
|
|
||||||
this.router.get(
|
this.router.get(
|
||||||
"/summary/team/:teamId",
|
"/summary/team",
|
||||||
this.monitorController.getMonitorsAndSummaryByTeamId
|
this.monitorController.getMonitorsAndSummaryByTeamId
|
||||||
);
|
);
|
||||||
|
|
||||||
this.router.get(
|
this.router.get(
|
||||||
"/team/:teamId/with-checks",
|
"/team/with-checks",
|
||||||
this.monitorController.getMonitorsWithChecksByTeamId
|
this.monitorController.getMonitorsWithChecksByTeamId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -126,9 +126,7 @@ const getMonitorByIdQueryValidation = joi.object({
|
|||||||
normalize: joi.boolean(),
|
normalize: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getMonitorsByTeamIdParamValidation = joi.object({
|
const getMonitorsByTeamIdParamValidation = joi.object({});
|
||||||
teamId: joi.string().required(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const getMonitorsByTeamIdQueryValidation = joi.object({
|
const getMonitorsByTeamIdQueryValidation = joi.object({
|
||||||
limit: joi.number(),
|
limit: joi.number(),
|
||||||
|
|||||||
Reference in new issue
Block a user