Merge pull request #1787 from YinDongFang/feature/auth

Setting Authorization in axios interceptor instead of passing from UI component
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-02-18 10:15:14 -08:00
commit 1174f9d728
49 files changed
+161 -417

No files matched your search

-10
View File
@@ -31,7 +31,6 @@
"i18next": "^24.2.2", "i18next": "^24.2.2",
"immutability-helper": "^3.1.1", "immutability-helper": "^3.1.1",
"joi": "17.13.3", "joi": "17.13.3",
"jwt-decode": "^4.0.0",
"maplibre-gl": "5.1.0", "maplibre-gl": "5.1.0",
"mui-color-input": "^5.0.1", "mui-color-input": "^5.0.1",
"react": "18.3.1", "react": "18.3.1",
@@ -13822,15 +13821,6 @@
"node": ">=4.0" "node": ">=4.0"
} }
}, },
"node_modules/jwt-decode": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==",
"license": "MIT",
"engines": {
"node": ">=18"
}
},
"node_modules/kdbush": { "node_modules/kdbush": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/kdbush/-/kdbush-4.0.2.tgz", "resolved": "https://registry.npmjs.org/kdbush/-/kdbush-4.0.2.tgz",
-1
View File
@@ -34,7 +34,6 @@
"i18next": "^24.2.2", "i18next": "^24.2.2",
"immutability-helper": "^3.1.1", "immutability-helper": "^3.1.1",
"joi": "17.13.3", "joi": "17.13.3",
"jwt-decode": "^4.0.0",
"maplibre-gl": "5.1.0", "maplibre-gl": "5.1.0",
"mui-color-input": "^5.0.1", "mui-color-input": "^5.0.1",
"react": "18.3.1", "react": "18.3.1",
+2 -4
View File
@@ -25,8 +25,6 @@ const ActionsMenu = ({
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const dispatch = useDispatch(); const dispatch = useDispatch();
const theme = useTheme(); const theme = useTheme();
const authState = useSelector((state) => state.auth);
const authToken = authState.authToken;
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
const handleRemove = async (event) => { const handleRemove = async (event) => {
@@ -34,7 +32,7 @@ const ActionsMenu = ({
event.stopPropagation(); event.stopPropagation();
let monitor = { _id: actions.id }; let monitor = { _id: actions.id };
const action = await dispatch( const action = await dispatch(
deleteUptimeMonitor({ authToken: authState.authToken, monitor }) deleteUptimeMonitor({ monitor })
); );
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
setIsOpen(false); // close modal setIsOpen(false); // close modal
@@ -49,7 +47,7 @@ const ActionsMenu = ({
try { try {
setIsLoading(true); setIsLoading(true);
const action = await dispatch( const action = await dispatch(
pauseUptimeMonitor({ authToken, monitorId: monitor._id }) pauseUptimeMonitor({ monitorId: monitor._id })
); );
if (pauseUptimeMonitor.fulfilled.match(action)) { if (pauseUptimeMonitor.fulfilled.match(action)) {
const state = action?.payload?.data.isActive === false ? "paused" : "resumed"; const state = action?.payload?.data.isActive === false ? "paused" : "resumed";
@@ -30,7 +30,7 @@ const PasswordPanel = () => {
const SPACING_GAP = theme.spacing(12); const SPACING_GAP = theme.spacing(12);
//redux state //redux state
const { authToken, isLoading } = useSelector((state) => state.auth); const { isLoading } = useSelector((state) => state.auth);
const idToName = { const idToName = {
"edit-current-password": "password", "edit-current-password": "password",
@@ -89,7 +89,7 @@ const PasswordPanel = () => {
}); });
setErrors(newErrors); setErrors(newErrors);
} else { } else {
const action = await dispatch(update({ authToken, localData })); const action = await dispatch(update({ localData }));
if (action.payload.success) { if (action.payload.success) {
createToast({ createToast({
body: "Your password was changed successfully.", body: "Your password was changed successfully.",
@@ -32,7 +32,7 @@ const ProfilePanel = () => {
const SPACING_GAP = theme.spacing(12); const SPACING_GAP = theme.spacing(12);
//redux state //redux state
const { user, authToken, isLoading } = useSelector((state) => state.auth); const { user, isLoading } = useSelector((state) => state.auth);
const idToName = { const idToName = {
"edit-first-name": "firstName", "edit-first-name": "firstName",
@@ -164,7 +164,7 @@ const ProfilePanel = () => {
return; return;
} }
const action = await dispatch(update({ authToken, localData })); const action = await dispatch(update({ localData }));
if (action.payload.success) { if (action.payload.success) {
createToast({ createToast({
body: "Your profile data was changed successfully.", body: "Your profile data was changed successfully.",
@@ -187,7 +187,7 @@ const ProfilePanel = () => {
// Initiates the account deletion process // Initiates the account deletion process
const handleDeleteAccount = async () => { const handleDeleteAccount = async () => {
const action = await dispatch(deleteUser(authToken)); const action = await dispatch(deleteUser());
if (action.payload.success) { if (action.payload.success) {
dispatch(clearAuthState()); dispatch(clearAuthState());
dispatch(clearUptimeMonitorState()); dispatch(clearUptimeMonitorState());
@@ -23,7 +23,6 @@ const TeamPanel = () => {
const SPACING_GAP = theme.spacing(12); const SPACING_GAP = theme.spacing(12);
const { authToken } = useSelector((state) => state.auth);
const [toInvite, setToInvite] = useState({ const [toInvite, setToInvite] = useState({
email: "", email: "",
role: ["0"], role: ["0"],
@@ -63,9 +62,7 @@ const TeamPanel = () => {
useEffect(() => { useEffect(() => {
const fetchTeam = async () => { const fetchTeam = async () => {
try { try {
const response = await networkService.getAllUsers({ const response = await networkService.getAllUsers();
authToken: authToken,
});
setMembers(response.data.data); setMembers(response.data.data);
} catch (error) { } catch (error) {
createToast({ createToast({
@@ -75,7 +72,7 @@ const TeamPanel = () => {
}; };
fetchTeam(); fetchTeam();
}, [authToken]); }, []);
useEffect(() => { useEffect(() => {
const ROLE_MAP = { const ROLE_MAP = {
@@ -150,7 +147,6 @@ const TeamPanel = () => {
try { try {
await networkService.requestInvitationToken({ await networkService.requestInvitationToken({
authToken: authToken,
email: toInvite.email, email: toInvite.email,
role: toInvite.role, role: toInvite.role,
}); });
+5 -10
View File
@@ -1,6 +1,5 @@
import { networkService } from "../../main"; import { networkService } from "../../main";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { jwtDecode } from "jwt-decode";
import axios from "axios"; import axios from "axios";
const initialState = { const initialState = {
@@ -44,8 +43,8 @@ export const login = createAsyncThunk("auth/login", async (form, thunkApi) => {
}); });
export const update = createAsyncThunk("auth/update", async (data, thunkApi) => { export const update = createAsyncThunk("auth/update", async (data, thunkApi) => {
const { authToken: token, localData: form } = data; const { localData: form } = data;
const user = jwtDecode(token); const user = thunkApi.getState().auth.user;
try { try {
const fd = new FormData(); const fd = new FormData();
form.firstName && fd.append("firstName", form.firstName); form.firstName && fd.append("firstName", form.firstName);
@@ -61,7 +60,6 @@ export const update = createAsyncThunk("auth/update", async (data, thunkApi) =>
form.deleteProfileImage && fd.append("deleteProfileImage", form.deleteProfileImage); form.deleteProfileImage && fd.append("deleteProfileImage", form.deleteProfileImage);
const res = await networkService.updateUser({ const res = await networkService.updateUser({
authToken: token,
userId: user._id, userId: user._id,
form: fd, form: fd,
}); });
@@ -78,14 +76,11 @@ export const update = createAsyncThunk("auth/update", async (data, thunkApi) =>
} }
}); });
export const deleteUser = createAsyncThunk("auth/delete", async (data, thunkApi) => { export const deleteUser = createAsyncThunk("auth/delete", async (_, thunkApi) => {
const user = jwtDecode(data); const user = thunkApi.getState().auth.user;
try { try {
const res = await networkService.deleteUser({ const res = await networkService.deleteUser({ userId: user._id, });
authToken: data,
userId: user._id,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -1,5 +1,4 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { jwtDecode } from "jwt-decode";
import { networkService } from "../../main"; import { networkService } from "../../main";
const initialState = { const initialState = {
isLoading: false, isLoading: false,
@@ -12,11 +11,8 @@ export const createInfrastructureMonitor = createAsyncThunk(
"infrastructureMonitors/createMonitor", "infrastructureMonitors/createMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const res = await networkService.createMonitor({ const res = await networkService.createMonitor({ monitor: monitor });
authToken: authToken,
monitor: monitor,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -35,12 +31,8 @@ export const checkInfrastructureEndpointResolution = createAsyncThunk(
"infrastructureMonitors/CheckEndpoint", "infrastructureMonitors/CheckEndpoint",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorURL } = data; const { monitorURL } = data;
const res = await networkService.checkEndpointResolution({ monitorURL: monitorURL, });
const res = await networkService.checkEndpointResolution({
authToken: authToken,
monitorURL: monitorURL,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -59,11 +51,8 @@ export const getInfrastructureMonitorById = createAsyncThunk(
"infrastructureMonitors/getMonitorById", "infrastructureMonitors/getMonitorById",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorId } = data; const { monitorId } = data;
const res = await networkService.getMonitorById({ const res = await networkService.getMonitorById({ monitorId: monitorId });
authToken: authToken,
monitorId: monitorId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -80,11 +69,10 @@ export const getInfrastructureMonitorById = createAsyncThunk(
export const getInfrastructureMonitorsByTeamId = createAsyncThunk( export const getInfrastructureMonitorsByTeamId = createAsyncThunk(
"infrastructureMonitors/getMonitorsByTeamId", "infrastructureMonitors/getMonitorsByTeamId",
async (token, thunkApi) => { async (_, thunkApi) => {
const user = jwtDecode(token); const user = thunkApi.getState().auth.user;
try { try {
const res = await networkService.getMonitorsAndSummaryByTeamId({ const res = await networkService.getMonitorsAndSummaryByTeamId({
authToken: token,
teamId: user.teamId, teamId: user.teamId,
types: ["hardware"], types: ["hardware"],
limit: 1, limit: 1,
@@ -108,7 +96,7 @@ export const updateInfrastructureMonitor = createAsyncThunk(
"infrastructureMonitors/updateMonitor", "infrastructureMonitors/updateMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const updatedFields = { const updatedFields = {
name: monitor.name, name: monitor.name,
description: monitor.description, description: monitor.description,
@@ -117,7 +105,6 @@ export const updateInfrastructureMonitor = createAsyncThunk(
threshold: monitor.threshold, threshold: monitor.threshold,
}; };
const res = await networkService.updateMonitor({ const res = await networkService.updateMonitor({
authToken: authToken,
monitorId: monitor._id, monitorId: monitor._id,
updatedFields: updatedFields, updatedFields: updatedFields,
}); });
@@ -139,11 +126,8 @@ export const deleteInfrastructureMonitor = createAsyncThunk(
"infrastructureMonitors/deleteMonitor", "infrastructureMonitors/deleteMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const res = await networkService.deleteMonitorById({ const res = await networkService.deleteMonitorById({ monitorId: monitor._id, });
authToken: authToken,
monitorId: monitor._id,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -162,11 +146,8 @@ export const pauseInfrastructureMonitor = createAsyncThunk(
"infrastructureMonitors/pauseMonitor", "infrastructureMonitors/pauseMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorId } = data; const { monitorId } = data;
const res = await networkService.pauseMonitorById({ const res = await networkService.pauseMonitorById({ monitorId: monitorId, });
authToken: authToken,
monitorId: monitorId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -185,11 +166,8 @@ export const deleteInfrastructureMonitorChecksByTeamId = createAsyncThunk(
"infrastructureMonitors/deleteChecksByTeamId", "infrastructureMonitors/deleteChecksByTeamId",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, teamId } = data; const { teamId } = data;
const res = await networkService.deleteChecksByTeamId({ const res = await networkService.deleteChecksByTeamId({ teamId: teamId, });
authToken: authToken,
teamId: teamId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -208,10 +186,7 @@ export const deleteAllInfrastructureMonitors = createAsyncThunk(
"infrastructureMonitors/deleteAllMonitors", "infrastructureMonitors/deleteAllMonitors",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken } = data; const res = await networkService.deleteAllMonitors();
const res = await networkService.deleteAllMonitors({
authToken: authToken,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -1,5 +1,4 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { jwtDecode } from "jwt-decode";
import { networkService } from "../../main"; import { networkService } from "../../main";
const initialState = { const initialState = {
isLoading: false, isLoading: false,
@@ -12,11 +11,8 @@ export const createPageSpeed = createAsyncThunk(
"pageSpeedMonitors/createPageSpeed", "pageSpeedMonitors/createPageSpeed",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const res = await networkService.createMonitor({ const res = await networkService.createMonitor({ monitor: monitor, });
authToken: authToken,
monitor: monitor,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -35,12 +31,8 @@ export const checkEndpointResolution = createAsyncThunk(
"monitors/checkEndpoint", "monitors/checkEndpoint",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorURL } = data; const { monitorURL } = data;
const res = await networkService.checkEndpointResolution({ monitorURL: monitorURL, });
const res = await networkService.checkEndpointResolution({
authToken: authToken,
monitorURL: monitorURL,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -59,11 +51,8 @@ export const getPagespeedMonitorById = createAsyncThunk(
"monitors/getMonitorById", "monitors/getMonitorById",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorId } = data; const { monitorId } = data;
const res = await networkService.getMonitorById({ const res = await networkService.getMonitorById({ monitorId: monitorId, });
authToken: authToken,
monitorId: monitorId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -80,11 +69,10 @@ export const getPagespeedMonitorById = createAsyncThunk(
export const getPageSpeedByTeamId = createAsyncThunk( export const getPageSpeedByTeamId = createAsyncThunk(
"pageSpeedMonitors/getPageSpeedByTeamId", "pageSpeedMonitors/getPageSpeedByTeamId",
async (token, thunkApi) => { async (_, thunkApi) => {
const user = jwtDecode(token); const user = thunkApi.getState().auth.user;
try { try {
const res = await networkService.getMonitorsAndSummaryByTeamId({ const res = await networkService.getMonitorsAndSummaryByTeamId({
authToken: token,
teamId: user.teamId, teamId: user.teamId,
types: ["pagespeed"], types: ["pagespeed"],
}); });
@@ -106,7 +94,7 @@ export const updatePageSpeed = createAsyncThunk(
"pageSpeedMonitors/updatePageSpeed", "pageSpeedMonitors/updatePageSpeed",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const updatedFields = { const updatedFields = {
name: monitor.name, name: monitor.name,
description: monitor.description, description: monitor.description,
@@ -114,7 +102,6 @@ export const updatePageSpeed = createAsyncThunk(
// notifications: monitor.notifications, // notifications: monitor.notifications,
}; };
const res = await networkService.updateMonitor({ const res = await networkService.updateMonitor({
authToken: authToken,
monitorId: monitor._id, monitorId: monitor._id,
updatedFields: updatedFields, updatedFields: updatedFields,
}); });
@@ -136,11 +123,8 @@ export const deletePageSpeed = createAsyncThunk(
"pageSpeedMonitors/deletePageSpeed", "pageSpeedMonitors/deletePageSpeed",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const res = await networkService.deleteMonitorById({ const res = await networkService.deleteMonitorById({ monitorId: monitor._id, });
authToken: authToken,
monitorId: monitor._id,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -158,11 +142,8 @@ export const pausePageSpeed = createAsyncThunk(
"pageSpeedMonitors/pausePageSpeed", "pageSpeedMonitors/pausePageSpeed",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorId } = data; const { monitorId } = data;
const res = await networkService.pauseMonitorById({ const res = await networkService.pauseMonitorById({ monitorId: monitorId, });
authToken: authToken,
monitorId: monitorId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
+3 -8
View File
@@ -11,9 +11,7 @@ export const getAppSettings = createAsyncThunk(
"settings/getSettings", "settings/getSettings",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const res = await networkService.getAppSettings({ const res = await networkService.getAppSettings();
authToken: data.authToken,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response.data) { if (error.response.data) {
@@ -30,7 +28,7 @@ export const getAppSettings = createAsyncThunk(
export const updateAppSettings = createAsyncThunk( export const updateAppSettings = createAsyncThunk(
"settings/updateSettings", "settings/updateSettings",
async ({ settings, authToken }, thunkApi) => { async ({ settings }, thunkApi) => {
networkService.setBaseUrl(settings.apiBaseUrl); networkService.setBaseUrl(settings.apiBaseUrl);
try { try {
const parsedSettings = { const parsedSettings = {
@@ -49,10 +47,7 @@ export const updateAppSettings = createAsyncThunk(
systemEmailAddress: settings.systemEmailAddress, systemEmailAddress: settings.systemEmailAddress,
systemEmailPassword: settings.systemEmailPassword, systemEmailPassword: settings.systemEmailPassword,
}; };
const res = await networkService.updateAppSettings({ const res = await networkService.updateAppSettings({ settings: parsedSettings, });
settings: parsedSettings,
authToken,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -1,5 +1,4 @@
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { jwtDecode } from "jwt-decode";
import { networkService } from "../../main"; import { networkService } from "../../main";
const initialState = { const initialState = {
isLoading: false, isLoading: false,
@@ -12,11 +11,8 @@ export const createUptimeMonitor = createAsyncThunk(
"monitors/createMonitor", "monitors/createMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const res = await networkService.createMonitor({ const res = await networkService.createMonitor({ monitor: monitor });
authToken: authToken,
monitor: monitor,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -35,12 +31,8 @@ export const checkEndpointResolution = createAsyncThunk(
"monitors/checkEndpoint", "monitors/checkEndpoint",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorURL } = data; const { monitorURL } = data;
const res = await networkService.checkEndpointResolution({ monitorURL: monitorURL, });
const res = await networkService.checkEndpointResolution({
authToken: authToken,
monitorURL: monitorURL,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -59,11 +51,8 @@ export const getUptimeMonitorById = createAsyncThunk(
"monitors/getMonitorById", "monitors/getMonitorById",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorId } = data; const { monitorId } = data;
const res = await networkService.getMonitorById({ const res = await networkService.getMonitorById({ monitorId: monitorId, });
authToken: authToken,
monitorId: monitorId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -82,7 +71,7 @@ export const updateUptimeMonitor = createAsyncThunk(
"monitors/updateMonitor", "monitors/updateMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const updatedFields = { const updatedFields = {
name: monitor.name, name: monitor.name,
description: monitor.description, description: monitor.description,
@@ -93,7 +82,6 @@ export const updateUptimeMonitor = createAsyncThunk(
jsonPath: monitor.jsonPath, jsonPath: monitor.jsonPath,
}; };
const res = await networkService.updateMonitor({ const res = await networkService.updateMonitor({
authToken: authToken,
monitorId: monitor._id, monitorId: monitor._id,
monitor, monitor,
}); });
@@ -115,11 +103,8 @@ export const deleteUptimeMonitor = createAsyncThunk(
"monitors/deleteMonitor", "monitors/deleteMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitor } = data; const { monitor } = data;
const res = await networkService.deleteMonitorById({ const res = await networkService.deleteMonitorById({ monitorId: monitor._id, });
authToken: authToken,
monitorId: monitor._id,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -138,11 +123,8 @@ export const pauseUptimeMonitor = createAsyncThunk(
"monitors/pauseMonitor", "monitors/pauseMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, monitorId } = data; const { monitorId } = data;
const res = await networkService.pauseMonitorById({ const res = await networkService.pauseMonitorById({ monitorId: monitorId, });
authToken: authToken,
monitorId: monitorId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -161,11 +143,8 @@ export const deleteMonitorChecksByTeamId = createAsyncThunk(
"monitors/deleteChecksByTeamId", "monitors/deleteChecksByTeamId",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken, teamId } = data; const { teamId } = data;
const res = await networkService.deleteChecksByTeamId({ const res = await networkService.deleteChecksByTeamId({ teamId: teamId, });
authToken: authToken,
teamId: teamId,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -183,10 +162,7 @@ export const addDemoMonitors = createAsyncThunk(
"monitors/addDemoMonitors", "monitors/addDemoMonitors",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken } = data; const res = await networkService.addDemoMonitors();
const res = await networkService.addDemoMonitors({
authToken: authToken,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -205,10 +181,7 @@ export const deleteAllMonitors = createAsyncThunk(
"monitors/deleteAllMonitors", "monitors/deleteAllMonitors",
async (data, thunkApi) => { async (data, thunkApi) => {
try { try {
const { authToken } = data; const res = await networkService.deleteAllMonitors();
const res = await networkService.deleteAllMonitors({
authToken: authToken,
});
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -4,17 +4,15 @@ import { useSelector } from "react-redux";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const useCreateDistributedUptimeMonitor = ({ isCreate, monitorId }) => { const useCreateDistributedUptimeMonitor = ({ isCreate, monitorId }) => {
const { authToken, user } = useSelector((state) => state.auth);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const createDistributedUptimeMonitor = async ({ form }) => { const createDistributedUptimeMonitor = async ({ form }) => {
setIsLoading(true); setIsLoading(true);
try { try {
if (isCreate) { if (isCreate) {
await networkService.createMonitor({ authToken, monitor: form }); await networkService.createMonitor({ monitor: form });
} else { } else {
await networkService.updateMonitor({ authToken, monitor: form, monitorId }); await networkService.updateMonitor({ monitor: form, monitorId });
} }
return true; return true;
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { networkService } from "../../../../main"; import { networkService } from "../../../../main";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
export const useMonitorFetch = ({ authToken, monitorId, isCreate }) => { export const useMonitorFetch = ({ monitorId, isCreate }) => {
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [monitor, setMonitor] = useState(undefined); const [monitor, setMonitor] = useState(undefined);
@@ -12,7 +12,6 @@ export const useMonitorFetch = ({ authToken, monitorId, isCreate }) => {
try { try {
if (isCreate) return; if (isCreate) return;
const res = await networkService.getUptimeDetailsById({ const res = await networkService.getUptimeDetailsById({
authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
normalize: true, normalize: true,
}); });
@@ -25,7 +24,7 @@ export const useMonitorFetch = ({ authToken, monitorId, isCreate }) => {
} }
}; };
fetchMonitors(); fetchMonitors();
}, [authToken, monitorId, isCreate]); }, [monitorId, isCreate]);
return [monitor, isLoading, networkError]; return [monitor, isLoading, networkError];
}; };
+1 -2
View File
@@ -48,7 +48,7 @@ const CreateDistributedUptime = () => {
]; ];
// Redux state // Redux state
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
// Local state // Local state
const [https, setHttps] = useState(true); const [https, setHttps] = useState(true);
@@ -68,7 +68,6 @@ const CreateDistributedUptime = () => {
useCreateDistributedUptimeMonitor({ isCreate, monitorId }); useCreateDistributedUptimeMonitor({ isCreate, monitorId });
const [monitor, monitorIsLoading, monitorNetworkError] = useMonitorFetch({ const [monitor, monitorIsLoading, monitorNetworkError] = useMonitorFetch({
authToken,
monitorId, monitorId,
isCreate, isCreate,
}); });
@@ -5,11 +5,10 @@ import { createToast } from "../../../../Utils/toastUtils";
const useDeleteMonitor = ({ monitorId }) => { const useDeleteMonitor = ({ monitorId }) => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { authToken } = useSelector((state) => state.auth);
const deleteMonitor = async () => { const deleteMonitor = async () => {
try { try {
setIsLoading(true); setIsLoading(true);
await networkService.deleteMonitorById({ authToken, monitorId }); await networkService.deleteMonitorById({ monitorId });
return true; return true;
} catch (error) { } catch (error) {
createToast({ createToast({
@@ -53,7 +53,6 @@ const useSubscribeToDetails = ({ monitorId, isPublic, isPublished, dateRange })
const [monitor, setMonitor] = useState(undefined); const [monitor, setMonitor] = useState(undefined);
const [lastUpdateTrigger, setLastUpdateTrigger] = useState(0); const [lastUpdateTrigger, setLastUpdateTrigger] = useState(0);
const [devices, setDevices] = useState(Array.from({ length: 5 }, getRandomDevice)); const [devices, setDevices] = useState(Array.from({ length: 5 }, getRandomDevice));
const authToken = useSelector((state) => state.auth.token);
const prevDateRangeRef = useRef(dateRange); const prevDateRangeRef = useRef(dateRange);
@@ -68,7 +67,6 @@ const useSubscribeToDetails = ({ monitorId, isPublic, isPublished, dateRange })
try { try {
const cleanup = networkService.subscribeToDistributedUptimeDetails({ const cleanup = networkService.subscribeToDistributedUptimeDetails({
authToken,
monitorId, monitorId,
dateRange: dateRange, dateRange: dateRange,
normalize: true, normalize: true,
@@ -105,7 +103,6 @@ const useSubscribeToDetails = ({ monitorId, isPublic, isPublished, dateRange })
setNetworkError(true); setNetworkError(true);
} }
}, [ }, [
authToken,
dateRange, dateRange,
monitorId, monitorId,
retryCount, retryCount,
@@ -7,7 +7,7 @@ import { createToast } from "../../../../Utils/toastUtils";
const useSubscribeToMonitors = () => { const useSubscribeToMonitors = () => {
// Redux // Redux
const { authToken, user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
// Local state // Local state
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
@@ -22,7 +22,6 @@ const useSubscribeToMonitors = () => {
useEffect(() => { useEffect(() => {
try { try {
const cleanup = networkService.subscribeToDistributedUptimeMonitors({ const cleanup = networkService.subscribeToDistributedUptimeMonitors({
authToken: authToken,
teamId: user.teamId, teamId: user.teamId,
limit: 25, limit: 25,
types: ["distributed_http"], types: ["distributed_http"],
@@ -57,7 +56,7 @@ const useSubscribeToMonitors = () => {
}); });
setNetworkError(true); setNetworkError(true);
} }
}, [authToken, user, getMonitorWithPercentage, theme]); }, [user, getMonitorWithPercentage, theme]);
return [isLoading, networkError, monitors, monitorsSummary, filteredMonitors]; return [isLoading, networkError, monitors, monitorsSummary, filteredMonitors];
}; };
export { useSubscribeToMonitors }; export { useSubscribeToMonitors };
@@ -9,12 +9,10 @@ const useStatusPageFetchByUrl = ({ url }) => {
const [statusPage, setStatusPage] = useState(undefined); const [statusPage, setStatusPage] = useState(undefined);
const [monitorId, setMonitorId] = useState(undefined); const [monitorId, setMonitorId] = useState(undefined);
const [isPublished, setIsPublished] = useState(false); const [isPublished, setIsPublished] = useState(false);
const { authToken } = useSelector((state) => state.auth);
useEffect(() => { useEffect(() => {
const fetchStatusPageByUrl = async () => { const fetchStatusPageByUrl = async () => {
try { try {
const response = await networkService.getStatusPageByUrl({ const response = await networkService.getStatusPageByUrl({
authToken,
url, url,
type: "distributed", type: "distributed",
}); });
@@ -33,7 +31,7 @@ const useStatusPageFetchByUrl = ({ url }) => {
} }
}; };
fetchStatusPageByUrl(); fetchStatusPageByUrl();
}, [authToken, url]); }, [url]);
return [isLoading, networkError, statusPage, monitorId, isPublished]; return [isLoading, networkError, statusPage, monitorId, isPublished];
}; };
+2 -4
View File
@@ -4,7 +4,7 @@ import { createToast } from "../../../Utils/toastUtils";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
const useChecksFetch = ({ selectedMonitor, filter, dateRange, page, rowsPerPage }) => { const useChecksFetch = ({ selectedMonitor, filter, dateRange, page, rowsPerPage }) => {
//Redux //Redux
const { authToken, user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
//Local //Local
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
@@ -20,7 +20,6 @@ const useChecksFetch = ({ selectedMonitor, filter, dateRange, page, rowsPerPage
if (selectedMonitor === "0") { if (selectedMonitor === "0") {
res = await networkService.getChecksByTeam({ res = await networkService.getChecksByTeam({
authToken: authToken,
status: false, status: false,
teamId: user.teamId, teamId: user.teamId,
sortOrder: "desc", sortOrder: "desc",
@@ -32,7 +31,6 @@ const useChecksFetch = ({ selectedMonitor, filter, dateRange, page, rowsPerPage
}); });
} else { } else {
res = await networkService.getChecksByMonitor({ res = await networkService.getChecksByMonitor({
authToken: authToken,
status: false, status: false,
monitorId: selectedMonitor, monitorId: selectedMonitor,
sortOrder: "desc", sortOrder: "desc",
@@ -53,7 +51,7 @@ const useChecksFetch = ({ selectedMonitor, filter, dateRange, page, rowsPerPage
} }
}; };
fetchChecks(); fetchChecks();
}, [authToken, user, dateRange, page, rowsPerPage, filter, selectedMonitor]); }, [user, dateRange, page, rowsPerPage, filter, selectedMonitor]);
return { isLoading, networkError, checks, checksCount }; return { isLoading, networkError, checks, checksCount };
}; };
@@ -1,7 +1,7 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { networkService } from "../../../main"; import { networkService } from "../../../main";
import { createToast } from "../../../Utils/toastUtils"; import { createToast } from "../../../Utils/toastUtils";
const useMonitorsFetch = ({ authToken, teamId }) => { const useMonitorsFetch = ({ teamId }) => {
//Local state //Local state
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
@@ -13,7 +13,6 @@ const useMonitorsFetch = ({ authToken, teamId }) => {
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getMonitorsByTeamId({ const res = await networkService.getMonitorsByTeamId({
authToken,
teamId, teamId,
limit: null, limit: null,
types: null, types: null,
@@ -44,7 +43,7 @@ const useMonitorsFetch = ({ authToken, teamId }) => {
}; };
fetchMonitors(); fetchMonitors();
}, [authToken, teamId]); }, [teamId]);
return { isLoading, monitors, networkError }; return { isLoading, monitors, networkError };
}; };
+1 -2
View File
@@ -16,7 +16,7 @@ const BREADCRUMBS = [{ name: `Incidents`, path: "/incidents" }];
const Incidents = () => { const Incidents = () => {
// Redux state // Redux state
const { authToken, user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
// Local state // Local state
const [selectedMonitor, setSelectedMonitor] = useState("0"); const [selectedMonitor, setSelectedMonitor] = useState("0");
@@ -26,7 +26,6 @@ const Incidents = () => {
const theme = useTheme(); const theme = useTheme();
const { monitors, isLoading, networkError } = useMonitorsFetch({ const { monitors, isLoading, networkError } = useMonitorsFetch({
authToken,
teamId: user.teamId, teamId: user.teamId,
}); });
+2 -2
View File
@@ -48,7 +48,7 @@ const getAlertError = (errors) => {
const CreateInfrastructureMonitor = () => { const CreateInfrastructureMonitor = () => {
const theme = useTheme(); const theme = useTheme();
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const monitorState = useSelector((state) => state.infrastructureMonitor); const monitorState = useSelector((state) => state.infrastructureMonitor);
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
@@ -148,7 +148,7 @@ const CreateInfrastructureMonitor = () => {
}; };
const action = await dispatch( const action = await dispatch(
createInfrastructureMonitor({ authToken, monitor: form }) createInfrastructureMonitor({ monitor: form })
); );
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Infrastructure monitor created successfully!" }); createToast({ body: "Infrastructure monitor created successfully!" });
@@ -7,13 +7,10 @@ const useHardwareMonitorsFetch = ({ monitorId, dateRange }) => {
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const [monitor, setMonitor] = useState(undefined); const [monitor, setMonitor] = useState(undefined);
const { authToken } = useSelector((state) => state.auth);
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
const response = await networkService.getHardwareDetailsByMonitorId({ const response = await networkService.getHardwareDetailsByMonitorId({
authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
dateRange: dateRange, dateRange: dateRange,
}); });
@@ -26,7 +23,7 @@ const useHardwareMonitorsFetch = ({ monitorId, dateRange }) => {
} }
}; };
fetchData(); fetchData();
}, [monitorId, dateRange, authToken]); }, [monitorId, dateRange]);
return { return {
isLoading, isLoading,
@@ -30,8 +30,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 authState = useSelector((state) => state.auth);
const authToken = authState.authToken;
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
const openMenu = (e) => { const openMenu = (e) => {
@@ -61,7 +59,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
const handleRemove = async () => { const handleRemove = async () => {
try { try {
await networkService.deleteMonitorById({ await networkService.deleteMonitorById({
authToken,
monitorId: monitor.id, monitorId: monitor.id,
}); });
createToast({ body: "Monitor deleted successfully." }); createToast({ body: "Monitor deleted successfully." });
@@ -5,7 +5,7 @@ import { createToast } from "../../../../Utils/toastUtils";
const useMonitorFetch = ({ page, rowsPerPage, updateTrigger }) => { const useMonitorFetch = ({ page, rowsPerPage, updateTrigger }) => {
// Redux state // Redux state
const { authToken, user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
// Local state // Local state
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
@@ -17,7 +17,6 @@ const useMonitorFetch = ({ page, rowsPerPage, updateTrigger }) => {
const fetchMonitors = async () => { const fetchMonitors = async () => {
try { try {
const response = await networkService.getMonitorsByTeamId({ const response = await networkService.getMonitorsByTeamId({
authToken,
teamId: user.teamId, teamId: user.teamId,
limit: 1, limit: 1,
types: ["hardware"], types: ["hardware"],
@@ -37,7 +36,7 @@ const useMonitorFetch = ({ page, rowsPerPage, updateTrigger }) => {
}; };
fetchMonitors(); fetchMonitors();
}, [page, rowsPerPage, authToken, user.teamId, updateTrigger]); }, [page, rowsPerPage, user.teamId, updateTrigger]);
return { monitors, summary, isLoading, networkError }; return { monitors, summary, isLoading, networkError };
}; };
@@ -113,7 +113,7 @@ const CreateMaintenance = () => {
const { maintenanceWindowId } = useParams(); const { maintenanceWindowId } = useParams();
const navigate = useNavigate(); const navigate = useNavigate();
const theme = useTheme(); const theme = useTheme();
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const [monitors, setMonitors] = useState([]); const [monitors, setMonitors] = useState([]);
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
@@ -133,7 +133,6 @@ const CreateMaintenance = () => {
setIsLoading(true); setIsLoading(true);
try { try {
const response = await networkService.getMonitorsByTeamId({ const response = await networkService.getMonitorsByTeamId({
authToken: authToken,
teamId: user.teamId, teamId: user.teamId,
limit: null, limit: null,
types: ["http", "ping", "pagespeed"], types: ["http", "ping", "pagespeed"],
@@ -146,7 +145,6 @@ const CreateMaintenance = () => {
} }
const res = await networkService.getMaintenanceWindowById({ const res = await networkService.getMaintenanceWindowById({
authToken: authToken,
maintenanceWindowId: maintenanceWindowId, maintenanceWindowId: maintenanceWindowId,
}); });
const maintenanceWindow = res.data.data; const maintenanceWindow = res.data.data;
@@ -174,7 +172,7 @@ const CreateMaintenance = () => {
} }
}; };
fetchMonitors(); fetchMonitors();
}, [authToken, user]); }, [user]);
const handleSearch = (value) => { const handleSearch = (value) => {
setSearch(value); setSearch(value);
@@ -239,7 +237,7 @@ const CreateMaintenance = () => {
submit.expiry = end; submit.expiry = end;
} }
const requestConfig = { authToken: authToken, maintenanceWindow: submit }; const requestConfig = { maintenanceWindow: submit };
if (maintenanceWindowId !== undefined) { if (maintenanceWindowId !== undefined) {
requestConfig.maintenanceWindowId = maintenanceWindowId; requestConfig.maintenanceWindowId = maintenanceWindowId;
@@ -13,7 +13,6 @@ import Dialog from "../../../../Components/Dialog";
const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => { const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => {
maintenanceWindow; maintenanceWindow;
const { authToken } = useSelector((state) => state.auth);
const [anchorEl, setAnchorEl] = useState(null); const [anchorEl, setAnchorEl] = useState(null);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
@@ -26,7 +25,6 @@ const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => {
try { try {
setIsLoading(true); setIsLoading(true);
await networkService.deleteMaintenanceWindow({ await networkService.deleteMaintenanceWindow({
authToken,
maintenanceWindowId: maintenanceWindow._id, maintenanceWindowId: maintenanceWindow._id,
}); });
updateCallback(); updateCallback();
@@ -47,7 +45,6 @@ const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => {
active: !maintenanceWindow.active, active: !maintenanceWindow.active,
}; };
await networkService.editMaintenanceWindow({ await networkService.editMaintenanceWindow({
authToken,
maintenanceWindowId: maintenanceWindow._id, maintenanceWindowId: maintenanceWindow._id,
maintenanceWindow: data, maintenanceWindow: data,
}); });
+1 -3
View File
@@ -13,7 +13,6 @@ import { useIsAdmin } from "../../Hooks/useIsAdmin";
const Maintenance = () => { const Maintenance = () => {
const theme = useTheme(); const theme = useTheme();
const navigate = useNavigate(); const navigate = useNavigate();
const { authToken } = useSelector((state) => state.auth);
const { rowsPerPage } = useSelector((state) => state.ui.maintenance); const { rowsPerPage } = useSelector((state) => state.ui.maintenance);
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const [maintenanceWindows, setMaintenanceWindows] = useState([]); const [maintenanceWindows, setMaintenanceWindows] = useState([]);
@@ -30,7 +29,6 @@ const Maintenance = () => {
const fetchMaintenanceWindows = async () => { const fetchMaintenanceWindows = async () => {
try { try {
const response = await networkService.getMaintenanceWindowsByTeamId({ const response = await networkService.getMaintenanceWindowsByTeamId({
authToken: authToken,
page: page, page: page,
rowsPerPage: rowsPerPage, rowsPerPage: rowsPerPage,
}); });
@@ -42,7 +40,7 @@ const Maintenance = () => {
} }
}; };
fetchMaintenanceWindows(); fetchMaintenanceWindows();
}, [authToken, page, rowsPerPage, updateTrigger]); }, [page, rowsPerPage, updateTrigger]);
return ( return (
<Box <Box
+7 -7
View File
@@ -31,7 +31,7 @@ const PageSpeedConfigure = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const dispatch = useDispatch(); const dispatch = useDispatch();
const MS_PER_MINUTE = 60000; const MS_PER_MINUTE = 60000;
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.pageSpeedMonitors); const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
const { monitorId } = useParams(); const { monitorId } = useParams();
const [monitor, setMonitor] = useState({}); const [monitor, setMonitor] = useState({});
@@ -59,7 +59,7 @@ const PageSpeedConfigure = () => {
useEffect(() => { useEffect(() => {
const fetchMonitor = async () => { const fetchMonitor = async () => {
try { try {
const action = await dispatch(getPagespeedMonitorById({ authToken, monitorId })); const action = await dispatch(getPagespeedMonitorById({ monitorId }));
if (getPagespeedMonitorById.fulfilled.match(action)) { if (getPagespeedMonitorById.fulfilled.match(action)) {
const monitor = action.payload.data; const monitor = action.payload.data;
@@ -73,7 +73,7 @@ const PageSpeedConfigure = () => {
} }
}; };
fetchMonitor(); fetchMonitor();
}, [dispatch, authToken, monitorId, navigate]); }, [dispatch, monitorId, navigate]);
const handleChange = (event, name) => { const handleChange = (event, name) => {
let { value, id } = event.target; let { value, id } = event.target;
@@ -130,7 +130,7 @@ const PageSpeedConfigure = () => {
const handlePause = async () => { const handlePause = async () => {
try { try {
const action = await dispatch(pausePageSpeed({ authToken, monitorId })); const action = await dispatch(pausePageSpeed({ monitorId }));
if (pausePageSpeed.fulfilled.match(action)) { if (pausePageSpeed.fulfilled.match(action)) {
const monitor = action.payload.data; const monitor = action.payload.data;
setMonitor(monitor); setMonitor(monitor);
@@ -147,10 +147,10 @@ const PageSpeedConfigure = () => {
const handleSave = async (event) => { const handleSave = async (event) => {
event.preventDefault(); event.preventDefault();
const action = await dispatch(updatePageSpeed({ authToken, monitor: monitor })); const action = await dispatch(updatePageSpeed({ monitor: monitor }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Monitor updated successfully!" }); createToast({ body: "Monitor updated successfully!" });
dispatch(getPageSpeedByTeamId(authToken)); dispatch(getPageSpeedByTeamId());
} else { } else {
createToast({ body: "Failed to update monitor." }); createToast({ body: "Failed to update monitor." });
} }
@@ -160,7 +160,7 @@ const PageSpeedConfigure = () => {
const handleRemove = async (event) => { const handleRemove = async (event) => {
event.preventDefault(); event.preventDefault();
setButtonLoading(true); setButtonLoading(true);
const action = await dispatch(deletePageSpeed({ authToken, monitor })); const action = await dispatch(deletePageSpeed({ monitor }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
navigate("/pagespeed"); navigate("/pagespeed");
} else { } else {
+3 -3
View File
@@ -54,7 +54,7 @@ const CreatePageSpeed = () => {
const [https, setHttps] = useState(true); const [https, setHttps] = useState(true);
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.pageSpeedMonitors); const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
// Setup // Setup
@@ -87,7 +87,7 @@ const CreatePageSpeed = () => {
} }
const checkEndpointAction = await dispatch( const checkEndpointAction = await dispatch(
checkEndpointResolution({ authToken, monitorURL: form.url }) checkEndpointResolution({ monitorURL: form.url })
); );
if (checkEndpointAction.meta.requestStatus === "rejected") { if (checkEndpointAction.meta.requestStatus === "rejected") {
@@ -106,7 +106,7 @@ const CreatePageSpeed = () => {
notifications: monitor.notifications, notifications: monitor.notifications,
}; };
const action = await dispatch(createPageSpeed({ authToken, monitor: form })); const action = await dispatch(createPageSpeed({ monitor: form }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Monitor created successfully!" }); createToast({ body: "Monitor created successfully!" });
navigate("/pagespeed"); navigate("/pagespeed");
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { networkService } from "../../../../main"; import { networkService } from "../../../../main";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
const useMonitorFetch = ({ authToken, monitorId }) => { const useMonitorFetch = ({ monitorId }) => {
const navigate = useNavigate(); const navigate = useNavigate();
const [monitor, setMonitor] = useState(undefined); const [monitor, setMonitor] = useState(undefined);
@@ -13,7 +13,6 @@ const useMonitorFetch = ({ authToken, monitorId }) => {
const fetchMonitor = async () => { const fetchMonitor = async () => {
try { try {
const res = await networkService.getStatsByMonitorId({ const res = await networkService.getStatsByMonitorId({
authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
sortOrder: "desc", sortOrder: "desc",
limit: 50, limit: 50,
@@ -32,7 +31,7 @@ const useMonitorFetch = ({ authToken, monitorId }) => {
}; };
fetchMonitor(); fetchMonitor();
}, [authToken, monitorId, navigate]); }, [monitorId, navigate]);
return { monitor, audits, isLoading }; return { monitor, audits, isLoading };
}; };
-2
View File
@@ -25,10 +25,8 @@ const PageSpeedDetails = () => {
const theme = useTheme(); const theme = useTheme();
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const { monitorId } = useParams(); const { monitorId } = useParams();
const { authToken } = useSelector((state) => state.auth);
const { monitor, audits, isLoading, networkError } = useMonitorFetch({ const { monitor, audits, isLoading, networkError } = useMonitorFetch({
authToken,
monitorId, monitorId,
}); });
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { networkService } from "../../../../main"; import { networkService } from "../../../../main";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const useMonitorsFetch = ({ authToken, teamId }) => { const useMonitorsFetch = ({ teamId }) => {
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [monitors, setMonitors] = useState([]); const [monitors, setMonitors] = useState([]);
const [summary, setSummary] = useState({}); const [summary, setSummary] = useState({});
@@ -13,7 +13,6 @@ const useMonitorsFetch = ({ authToken, teamId }) => {
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getMonitorsByTeamId({ const res = await networkService.getMonitorsByTeamId({
authToken: authToken,
teamId: teamId, teamId: teamId,
limit: 10, limit: 10,
types: ["pagespeed"], types: ["pagespeed"],
@@ -38,7 +37,7 @@ const useMonitorsFetch = ({ authToken, teamId }) => {
}; };
fetchMonitors(); fetchMonitors();
}, [authToken, teamId]); }, [teamId]);
return { isLoading, monitors, summary, networkError }; return { isLoading, monitors, summary, networkError };
}; };
+1 -2
View File
@@ -19,10 +19,9 @@ const BREADCRUMBS = [{ name: `pagespeed`, path: "/pagespeed" }];
const PageSpeed = () => { const PageSpeed = () => {
const theme = useTheme(); const theme = useTheme();
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { isLoading, monitors, summary, networkError } = useMonitorsFetch({ const { isLoading, monitors, summary, networkError } = useMonitorsFetch({
authToken: authToken,
teamId: user.teamId, teamId: user.teamId,
}); });
+5 -6
View File
@@ -39,7 +39,7 @@ const SECONDS_PER_DAY = 86400;
const Settings = () => { const Settings = () => {
const theme = useTheme(); const theme = useTheme();
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { checkTTL } = user; const { checkTTL } = user;
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
const { isLoading: authIsLoading } = useSelector((state) => state.auth); const { isLoading: authIsLoading } = useSelector((state) => state.auth);
@@ -115,11 +115,10 @@ const Settings = () => {
try { try {
setChecksIsLoading(true); setChecksIsLoading(true);
await networkService.updateChecksTTL({ await networkService.updateChecksTTL({
authToken: authToken,
ttl: form.ttl, ttl: form.ttl,
}); });
const updatedUser = { ...user, checkTTL: form.ttl }; const updatedUser = { ...user, checkTTL: form.ttl };
const action = await dispatch(update({ authToken, localData: updatedUser })); const action = await dispatch(update({ localData: updatedUser }));
if (action.payload.success) { if (action.payload.success) {
createToast({ createToast({
@@ -149,7 +148,7 @@ const Settings = () => {
const handleClearStats = async () => { const handleClearStats = async () => {
try { try {
const action = await dispatch( const action = await dispatch(
deleteMonitorChecksByTeamId({ teamId: user.teamId, authToken }) deleteMonitorChecksByTeamId({ teamId: user.teamId })
); );
if (deleteMonitorChecksByTeamId.fulfilled.match(action)) { if (deleteMonitorChecksByTeamId.fulfilled.match(action)) {
@@ -167,7 +166,7 @@ const Settings = () => {
const handleInsertDemoMonitors = async () => { const handleInsertDemoMonitors = async () => {
try { try {
const action = await dispatch(addDemoMonitors({ authToken })); const action = await dispatch(addDemoMonitors());
if (addDemoMonitors.fulfilled.match(action)) { if (addDemoMonitors.fulfilled.match(action)) {
createToast({ body: "Successfully added demo monitors" }); createToast({ body: "Successfully added demo monitors" });
} else { } else {
@@ -181,7 +180,7 @@ const Settings = () => {
const handleDeleteAllMonitors = async () => { const handleDeleteAllMonitors = async () => {
try { try {
const action = await dispatch(deleteAllMonitors({ authToken })); const action = await dispatch(deleteAllMonitors());
if (deleteAllMonitors.fulfilled.match(action)) { if (deleteAllMonitors.fulfilled.match(action)) {
createToast({ body: "Successfully deleted all monitors" }); createToast({ body: "Successfully deleted all monitors" });
} else { } else {
@@ -4,14 +4,14 @@ import { useSelector } from "react-redux";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const useCreateStatusPage = (isCreate, url) => { const useCreateStatusPage = (isCreate, url) => {
const { authToken, user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const createStatusPage = async ({ form }) => { const createStatusPage = async ({ form }) => {
setIsLoading(true); setIsLoading(true);
try { try {
await networkService.createStatusPage({ authToken, user, form, isCreate, url }); await networkService.createStatusPage({ user, form, isCreate, url });
return true; return true;
} catch (error) { } catch (error) {
setNetworkError(true); setNetworkError(true);
@@ -4,7 +4,7 @@ import { useSelector } from "react-redux";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const useMonitorsFetch = () => { const useMonitorsFetch = () => {
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const [monitors, setMonitors] = useState(undefined); const [monitors, setMonitors] = useState(undefined);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
@@ -13,7 +13,6 @@ const useMonitorsFetch = () => {
const fetchMonitors = async () => { const fetchMonitors = async () => {
try { try {
const response = await networkService.getMonitorsByTeamId({ const response = await networkService.getMonitorsByTeamId({
authToken: authToken,
teamId: user.teamId, teamId: user.teamId,
limit: null, // donot return any checks for the monitors limit: null, // donot return any checks for the monitors
types: ["http"], // status page is available only for the uptime type types: ["http"], // status page is available only for the uptime type
@@ -27,7 +26,7 @@ const useMonitorsFetch = () => {
} }
}; };
fetchMonitors(); fetchMonitors();
}, [authToken, user]); }, [user]);
return [monitors, isLoading, networkError]; return [monitors, isLoading, networkError];
}; };
@@ -5,11 +5,10 @@ import { createToast } from "../../../../Utils/toastUtils";
const useStatusPageDelete = (fetchStatusPage, url) => { const useStatusPageDelete = (fetchStatusPage, url) => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { authToken } = useSelector((state) => state.auth);
const deleteStatusPage = async () => { const deleteStatusPage = async () => {
try { try {
setIsLoading(true); setIsLoading(true);
await networkService.deleteStatusPage({ authToken, url }); await networkService.deleteStatusPage({ url });
fetchStatusPage?.(); fetchStatusPage?.();
return true; return true;
} catch (error) { } catch (error) {
@@ -10,13 +10,11 @@ const useStatusPageFetch = (isCreate = false, url) => {
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const [statusPage, setStatusPage] = useState(undefined); const [statusPage, setStatusPage] = useState(undefined);
const [monitors, setMonitors] = useState(undefined); const [monitors, setMonitors] = useState(undefined);
const { authToken } = useSelector((state) => state.auth);
const theme = useTheme(); const theme = useTheme();
const { getMonitorWithPercentage } = useMonitorUtils(); const { getMonitorWithPercentage } = useMonitorUtils();
const fetchStatusPage = useCallback(async () => { const fetchStatusPage = useCallback(async () => {
try { try {
const response = await networkService.getStatusPageByUrl({ const response = await networkService.getStatusPageByUrl({
authToken,
url, url,
type: "uptime", type: "uptime",
}); });
@@ -40,7 +38,7 @@ const useStatusPageFetch = (isCreate = false, url) => {
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
}, [authToken, theme, getMonitorWithPercentage, url]); }, [theme, getMonitorWithPercentage, url]);
useEffect(() => { useEffect(() => {
if (isCreate === true) { if (isCreate === true) {
@@ -4,7 +4,7 @@ import { useSelector } from "react-redux";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const useStatusPagesFetch = () => { const useStatusPagesFetch = () => {
const { authToken, user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
@@ -14,7 +14,6 @@ const useStatusPagesFetch = () => {
const fetchStatusPages = async () => { const fetchStatusPages = async () => {
try { try {
const res = await networkService.getStatusPagesByTeamId({ const res = await networkService.getStatusPagesByTeamId({
authToken,
teamId: user.teamId, teamId: user.teamId,
}); });
setStatusPages(res?.data?.data); setStatusPages(res?.data?.data);
@@ -28,7 +27,7 @@ const useStatusPagesFetch = () => {
} }
}; };
fetchStatusPages(); fetchStatusPages();
}, [authToken, user]); }, [user]);
return [isLoading, networkError, statusPages]; return [isLoading, networkError, statusPages];
}; };
+6 -6
View File
@@ -48,7 +48,7 @@ const Configure = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const theme = useTheme(); const theme = useTheme();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
const [monitor, setMonitor] = useState({}); const [monitor, setMonitor] = useState({});
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
@@ -76,7 +76,7 @@ const Configure = () => {
useEffect(() => { useEffect(() => {
const fetchMonitor = async () => { const fetchMonitor = async () => {
try { try {
const action = await dispatch(getUptimeMonitorById({ authToken, monitorId })); const action = await dispatch(getUptimeMonitorById({ monitorId }));
if (getUptimeMonitorById.fulfilled.match(action)) { if (getUptimeMonitorById.fulfilled.match(action)) {
const monitor = action.payload.data; const monitor = action.payload.data;
@@ -90,7 +90,7 @@ const Configure = () => {
} }
}; };
fetchMonitor(); fetchMonitor();
}, [monitorId, authToken, navigate]); }, [monitorId, navigate]);
const handleChange = (event, name) => { const handleChange = (event, name) => {
let { value, id } = event.target; let { value, id } = event.target;
@@ -147,7 +147,7 @@ const Configure = () => {
const handlePause = async () => { const handlePause = async () => {
try { try {
const action = await dispatch(pauseUptimeMonitor({ authToken, monitorId })); const action = await dispatch(pauseUptimeMonitor({ monitorId }));
if (pauseUptimeMonitor.fulfilled.match(action)) { if (pauseUptimeMonitor.fulfilled.match(action)) {
const monitor = action.payload.data; const monitor = action.payload.data;
setMonitor(monitor); setMonitor(monitor);
@@ -164,7 +164,7 @@ const Configure = () => {
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
const action = await dispatch(updateUptimeMonitor({ authToken, monitor: monitor })); const action = await dispatch(updateUptimeMonitor({ monitor: monitor }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Monitor updated successfully!" }); createToast({ body: "Monitor updated successfully!" });
} else { } else {
@@ -175,7 +175,7 @@ const Configure = () => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const handleRemove = async (event) => { const handleRemove = async (event) => {
event.preventDefault(); event.preventDefault();
const action = await dispatch(deleteUptimeMonitor({ authToken, monitor })); const action = await dispatch(deleteUptimeMonitor({ monitor }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
navigate("/uptime"); navigate("/uptime");
} else { } else {
+5 -5
View File
@@ -68,7 +68,7 @@ const CreateMonitor = () => {
}, },
}; };
const { user, authToken } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
@@ -126,7 +126,7 @@ const CreateMonitor = () => {
if (monitor.type === "http") { if (monitor.type === "http") {
// const checkEndpointAction = await dispatch( // const checkEndpointAction = await dispatch(
// checkEndpointResolution({ authToken, monitorURL: form.url }) // checkEndpointResolution({ monitorURL: form.url })
// ); // );
// if (checkEndpointAction.meta.requestStatus === "rejected") { // if (checkEndpointAction.meta.requestStatus === "rejected") {
// createToast({ // createToast({
@@ -144,7 +144,7 @@ const CreateMonitor = () => {
userId: user._id, userId: user._id,
notifications: monitor.notifications, notifications: monitor.notifications,
}; };
const action = await dispatch(createUptimeMonitor({ authToken, monitor: form })); const action = await dispatch(createUptimeMonitor({ monitor: form }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Monitor created successfully!" }); createToast({ body: "Monitor created successfully!" });
navigate("/uptime"); navigate("/uptime");
@@ -205,7 +205,7 @@ const CreateMonitor = () => {
useEffect(() => { useEffect(() => {
const fetchMonitor = async () => { const fetchMonitor = async () => {
if (monitorId) { if (monitorId) {
const action = await dispatch(getUptimeMonitorById({ authToken, monitorId })); const action = await dispatch(getUptimeMonitorById({ monitorId }));
if (action.payload.success) { if (action.payload.success) {
const data = action.payload.data; const data = action.payload.data;
@@ -228,7 +228,7 @@ const CreateMonitor = () => {
} }
}; };
fetchMonitor(); fetchMonitor();
}, [monitorId, authToken, dispatch, navigate]); }, [monitorId, dispatch, navigate]);
return ( return (
<Box className="create-monitor"> <Box className="create-monitor">
@@ -5,7 +5,6 @@ import { formatDateWithTz } from "../../../../Utils/timeUtils";
const useCertificateFetch = ({ const useCertificateFetch = ({
monitor, monitor,
authToken,
monitorId, monitorId,
certificateDateFormat, certificateDateFormat,
uiTimezone, uiTimezone,
@@ -22,7 +21,6 @@ const useCertificateFetch = ({
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getCertificateExpiry({ const res = await networkService.getCertificateExpiry({
authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
}); });
if (res?.data?.data?.certificateDate) { if (res?.data?.data?.certificateDate) {
@@ -39,7 +37,7 @@ const useCertificateFetch = ({
} }
}; };
fetchCertificate(); fetchCertificate();
}, [authToken, monitorId, certificateDateFormat, uiTimezone, monitor]); }, [monitorId, certificateDateFormat, uiTimezone, monitor]);
return [certificateExpiry, isLoading]; return [certificateExpiry, isLoading];
}; };
@@ -3,7 +3,6 @@ import { useEffect } from "react";
import { networkService } from "../../../../main"; import { networkService } from "../../../../main";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
export const useChecksFetch = ({ export const useChecksFetch = ({
authToken,
monitorId, monitorId,
dateRange, dateRange,
page, page,
@@ -19,7 +18,6 @@ export const useChecksFetch = ({
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getChecksByMonitor({ const res = await networkService.getChecksByMonitor({
authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
sortOrder: "desc", sortOrder: "desc",
limit: null, limit: null,
@@ -38,7 +36,7 @@ export const useChecksFetch = ({
} }
}; };
fetchChecks(); fetchChecks();
}, [authToken, monitorId, dateRange, page, rowsPerPage]); }, [monitorId, dateRange, page, rowsPerPage]);
return [checks, checksCount, isLoading, networkError]; return [checks, checksCount, isLoading, networkError];
}; };
@@ -3,7 +3,7 @@ import { networkService } from "../../../../main";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => { export const useMonitorFetch = ({ monitorId, dateRange }) => {
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [monitor, setMonitor] = useState(undefined); const [monitor, setMonitor] = useState(undefined);
@@ -13,7 +13,6 @@ export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
const fetchMonitors = async () => { const fetchMonitors = async () => {
try { try {
const res = await networkService.getUptimeDetailsById({ const res = await networkService.getUptimeDetailsById({
authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
dateRange: dateRange, dateRange: dateRange,
normalize: true, normalize: true,
@@ -27,7 +26,7 @@ export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
} }
}; };
fetchMonitors(); fetchMonitors();
}, [authToken, dateRange, monitorId, navigate]); }, [dateRange, monitorId, navigate]);
return [monitor, isLoading, networkError]; return [monitor, isLoading, networkError];
}; };
-4
View File
@@ -31,7 +31,6 @@ const certificateDateFormat = "MMM D, YYYY h A";
const UptimeDetails = () => { const UptimeDetails = () => {
// Redux state // Redux state
const { authToken } = useSelector((state) => state.auth);
const uiTimezone = useSelector((state) => state.ui.timezone); const uiTimezone = useSelector((state) => state.ui.timezone);
// Local state // Local state
@@ -48,21 +47,18 @@ const UptimeDetails = () => {
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const [monitor, monitorIsLoading, monitorNetworkError] = useMonitorFetch({ const [monitor, monitorIsLoading, monitorNetworkError] = useMonitorFetch({
authToken,
monitorId, monitorId,
dateRange, dateRange,
}); });
const [certificateExpiry, certificateIsLoading] = useCertificateFetch({ const [certificateExpiry, certificateIsLoading] = useCertificateFetch({
monitor, monitor,
authToken,
monitorId, monitorId,
certificateDateFormat, certificateDateFormat,
uiTimezone, uiTimezone,
}); });
const [checks, checksCount, checksAreLoading, checksNetworkError] = useChecksFetch({ const [checks, checksCount, checksAreLoading, checksNetworkError] = useChecksFetch({
authToken,
monitorId, monitorId,
dateRange, dateRange,
page, page,
@@ -5,7 +5,6 @@ import { useTheme } from "@emotion/react";
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils"; import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
export const useMonitorFetch = ({ export const useMonitorFetch = ({
authToken,
teamId, teamId,
limit, limit,
page, page,
@@ -28,7 +27,6 @@ export const useMonitorFetch = ({
try { try {
setMonitorsAreLoading(true); setMonitorsAreLoading(true);
const res = await networkService.getMonitorsByTeamId({ const res = await networkService.getMonitorsByTeamId({
authToken,
teamId, teamId,
limit, limit,
types: ["http", "ping", "docker", "port"], types: ["http", "ping", "docker", "port"],
@@ -56,7 +54,6 @@ export const useMonitorFetch = ({
}; };
fetchMonitors(); fetchMonitors();
}, [ }, [
authToken,
teamId, teamId,
limit, limit,
field, field,
+1 -2
View File
@@ -54,7 +54,7 @@ CreateMonitorButton.propTypes = {
const UptimeMonitors = () => { const UptimeMonitors = () => {
// Redux state // Redux state
const { authToken, user } = useSelector((state) => state.auth); 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
@@ -96,7 +96,6 @@ const UptimeMonitors = () => {
monitorsSummary, monitorsSummary,
networkError, networkError,
} = useMonitorsFetch({ } = useMonitorsFetch({
authToken,
teamId, teamId,
limit: 25, limit: 25,
page: page, page: page,
+33 -138
View File
@@ -28,9 +28,12 @@ class NetworkService {
(config) => { (config) => {
const currentLanguage = i18next.language || "en"; const currentLanguage = i18next.language || "en";
const { authToken } = store.getState().auth;
config.headers = { config.headers = {
...config.headers, Authorization: `Bearer ${authToken}`,
"Accept-Language": currentLanguage, "Accept-Language": currentLanguage,
...config.headers,
}; };
return config; return config;
@@ -72,7 +75,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The monitor ID to be sent in the param. * @param {string} config.monitorId - The monitor ID to be sent in the param.
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
*/ */
@@ -80,7 +82,6 @@ class NetworkService {
async getMonitorById(config) { async getMonitorById(config) {
return this.axiosInstance.get(`/monitors/${config.monitorId}`, { return this.axiosInstance.get(`/monitors/${config.monitorId}`, {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -94,19 +95,13 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {Object} config.monitor - The monitor object to be sent in the request body. * @param {Object} config.monitor - The monitor object to be sent in the request body.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
*/ */
async createMonitor(config) { async createMonitor(config) {
const { authToken, monitor } = config; const { monitor } = config;
return this.axiosInstance.post(`/monitors`, monitor, { return this.axiosInstance.post(`/monitors`, monitor);
headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json",
},
});
} }
/** /**
@@ -117,19 +112,17 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {Object} config.monitorURL - The monitor url to be sent in the request body. * @param {Object} config.monitorURL - The monitor url to be sent in the request body.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
*/ */
async checkEndpointResolution(config) { async checkEndpointResolution(config) {
const { authToken, monitorURL } = config; const { monitorURL } = config;
const params = new URLSearchParams(); const params = new URLSearchParams();
if (monitorURL) params.append("monitorURL", monitorURL); if (monitorURL) params.append("monitorURL", monitorURL);
return this.axiosInstance.get(`/monitors/resolution/url?${params.toString()}`, { return this.axiosInstance.get(`/monitors/resolution/url?${params.toString()}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -143,7 +136,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.teamId - Team ID * @param {string} config.teamId - Team ID
* @param {Array<string>} config.types - Array of monitor types * @param {Array<string>} config.types - Array of monitor types
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
@@ -160,7 +152,6 @@ class NetworkService {
`/monitors/team/summary/${config.teamId}?${params.toString()}`, `/monitors/team/summary/${config.teamId}?${params.toString()}`,
{ {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
@@ -174,7 +165,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.teamId - The ID of the team whose monitors are to be retrieved. * @param {string} config.teamId - The ID of the team whose monitors are to be retrieved.
* @param {number} [config.limit] - The maximum number of checks to retrieve. 0 for all, -1 for none * @param {number} [config.limit] - The maximum number of checks to retrieve. 0 for all, -1 for none
* @param {Array<string>} [config.types] - The types of monitors to retrieve. * @param {Array<string>} [config.types] - The types of monitors to retrieve.
@@ -187,7 +177,7 @@ class NetworkService {
*/ */
async getMonitorsByTeamId(config) { async getMonitorsByTeamId(config) {
const { authToken, teamId, limit, types, page, rowsPerPage, filter, field, order } = const { teamId, limit, types, page, rowsPerPage, filter, field, order } =
config; config;
const params = new URLSearchParams(); const params = new URLSearchParams();
@@ -205,7 +195,6 @@ class NetworkService {
return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, { return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -218,7 +207,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The ID of the monitor whose statistics are to be retrieved. * @param {string} config.monitorId - The ID of the monitor whose statistics are to be retrieved.
* @param {string} config.sortOrder - The order in which to sort the retrieved statistics. * @param {string} config.sortOrder - The order in which to sort the retrieved statistics.
* @param {number} config.limit - The maximum number of statistics to retrieve. * @param {number} config.limit - The maximum number of statistics to retrieve.
@@ -236,13 +224,7 @@ class NetworkService {
if (config.normalize) params.append("normalize", config.normalize); if (config.normalize) params.append("normalize", config.normalize);
return this.axiosInstance.get( return this.axiosInstance.get(
`/monitors/stats/${config.monitorId}?${params.toString()}`, `/monitors/stats/${config.monitorId}?${params.toString()}`);
{
headers: {
Authorization: `Bearer ${config.authToken}`,
},
}
);
} }
async getHardwareDetailsByMonitorId(config) { async getHardwareDetailsByMonitorId(config) {
@@ -250,13 +232,7 @@ class NetworkService {
if (config.dateRange) params.append("dateRange", config.dateRange); if (config.dateRange) params.append("dateRange", config.dateRange);
return this.axiosInstance.get( return this.axiosInstance.get(
`/monitors/hardware/details/${config.monitorId}?${params.toString()}`, `/monitors/hardware/details/${config.monitorId}?${params.toString()}`);
{
headers: {
Authorization: `Bearer ${config.authToken}`,
},
}
);
} }
async getUptimeDetailsById(config) { async getUptimeDetailsById(config) {
const params = new URLSearchParams(); const params = new URLSearchParams();
@@ -264,13 +240,7 @@ class NetworkService {
if (config.normalize) params.append("normalize", config.normalize); if (config.normalize) params.append("normalize", config.normalize);
return this.axiosInstance.get( return this.axiosInstance.get(
`/monitors/uptime/details/${config.monitorId}?${params.toString()}`, `/monitors/uptime/details/${config.monitorId}?${params.toString()}`);
{
headers: {
Authorization: `Bearer ${config.authToken}`,
},
}
);
} }
/** /**
@@ -280,13 +250,12 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The ID of the monitor to be updated. * @param {string} config.monitorId - The ID of the monitor to be updated.
* @param {Object} config.updatedFields - The fields to be updated for the monitor. * @param {Object} config.updatedFields - The fields to be updated for the monitor.
* @returns {Promise<AxiosResponse>} The response from the axios PUT request. * @returns {Promise<AxiosResponse>} The response from the axios PUT request.
*/ */
async updateMonitor(config) { async updateMonitor(config) {
const { authToken, monitorId, monitor } = config; const { monitorId, monitor } = config;
const updatedFields = { const updatedFields = {
name: monitor.name, name: monitor.name,
description: monitor.description, description: monitor.description,
@@ -295,7 +264,6 @@ class NetworkService {
}; };
return this.axiosInstance.put(`/monitors/${monitorId}`, updatedFields, { return this.axiosInstance.put(`/monitors/${monitorId}`, updatedFields, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -308,14 +276,12 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The ID of the monitor to be deleted. * @param {string} config.monitorId - The ID of the monitor to be deleted.
* @returns {Promise<AxiosResponse>} The response from the axios DELETE request. * @returns {Promise<AxiosResponse>} The response from the axios DELETE request.
*/ */
async deleteMonitorById(config) { async deleteMonitorById(config) {
return this.axiosInstance.delete(`/monitors/${config.monitorId}`, { return this.axiosInstance.delete(`/monitors/${config.monitorId}`, {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -328,14 +294,12 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.teamId - The team ID of the monitors to be deleted. * @param {string} config.teamId - The team ID of the monitors to be deleted.
* @returns {Promise<AxiosResponse>} The response from the axios DELETE request. * @returns {Promise<AxiosResponse>} The response from the axios DELETE request.
*/ */
async deleteChecksByTeamId(config) { async deleteChecksByTeamId(config) {
return this.axiosInstance.delete(`/checks/team/${config.teamId}`, { return this.axiosInstance.delete(`/checks/team/${config.teamId}`, {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -347,7 +311,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The ID of the monitor to be paused. * @param {string} config.monitorId - The ID of the monitor to be paused.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
*/ */
@@ -357,7 +320,6 @@ class NetworkService {
{}, {},
{ {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
@@ -371,7 +333,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
*/ */
async addDemoMonitors(config) { async addDemoMonitors(config) {
@@ -380,7 +341,6 @@ class NetworkService {
{}, {},
{ {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
@@ -394,13 +354,11 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @returns {Promise<AxiosResponse>} The response from the axios DELETE request. * @returns {Promise<AxiosResponse>} The response from the axios DELETE request.
*/ */
async deleteAllMonitors(config) { async deleteAllMonitors(config) {
return this.axiosInstance.delete(`/monitors/`, { return this.axiosInstance.delete(`/monitors/`, {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -413,17 +371,12 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The ID of the monitor whose certificate expiry is to be retrieved. * @param {string} config.monitorId - The ID of the monitor whose certificate expiry is to be retrieved.
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
* *
*/ */
async getCertificateExpiry(config) { async getCertificateExpiry(config) {
return this.axiosInstance.get(`/monitors/certificate/${config.monitorId}`, { return this.axiosInstance.get(`/monitors/certificate/${config.monitorId}`);
headers: {
Authorization: `Bearer ${config.authToken}`,
},
});
} }
/** /**
@@ -460,18 +413,13 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.userId - The ID of the user to be updated. * @param {string} config.userId - The ID of the user to be updated.
* @param {Object} config.form - The form data for the user to be updated. * @param {Object} config.form - The form data for the user to be updated.
* @returns {Promise<AxiosResponse>} The response from the axios PUT request. * @returns {Promise<AxiosResponse>} The response from the axios PUT request.
* *
*/ */
async updateUser(config) { async updateUser(config) {
return this.axiosInstance.put(`/auth/user/${config.userId}`, config.form, { return this.axiosInstance.put(`/auth/user/${config.userId}`, config.form);
headers: {
Authorization: `Bearer ${config.authToken}`,
},
});
} }
/** /**
@@ -481,14 +429,11 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.userId - The ID of the user to be deleted. * @param {string} config.userId - The ID of the user to be deleted.
* *
**/ **/
async deleteUser(config) { async deleteUser(config) {
return this.axiosInstance.delete(`/auth/user/${config.userId}`, { return this.axiosInstance.delete(`/auth/user/${config.userId}`);
headers: { Authorization: `Bearer ${config.authToken}` },
});
} }
/** /**
@@ -561,14 +506,11 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
* *
*/ */
async getAllUsers(config) { async getAllUsers(config) {
return this.axiosInstance.get("/auth/users", { return this.axiosInstance.get("/auth/users");
headers: { Authorization: `Bearer ${config.authToken}` },
});
} }
/** /**
@@ -578,7 +520,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.email - The email of the user to be invited. * @param {string} config.email - The email of the user to be invited.
* @param {string} config.role - The role of the user to be invited. * @param {string} config.role - The role of the user to be invited.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
@@ -588,9 +529,6 @@ class NetworkService {
return this.axiosInstance.post( return this.axiosInstance.post(
`/invite`, `/invite`,
{ email: config.email, role: config.role }, { email: config.email, role: config.role },
{
headers: { Authorization: `Bearer ${config.authToken}` },
}
); );
} }
@@ -617,7 +555,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.monitorId - The ID of the monitor. * @param {string} config.monitorId - The ID of the monitor.
* @param {string} config.sortOrder - The order in which to sort the checks. * @param {string} config.sortOrder - The order in which to sort the checks.
* @param {number} config.limit - The maximum number of checks to retrieve. * @param {number} config.limit - The maximum number of checks to retrieve.
@@ -639,9 +576,7 @@ class NetworkService {
if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage); if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage);
if (config.status !== undefined) params.append("status", config.status); if (config.status !== undefined) params.append("status", config.status);
return this.axiosInstance.get(`/checks/${config.monitorId}?${params.toString()}`, { return this.axiosInstance.get(`/checks/${config.monitorId}?${params.toString()}`);
headers: { Authorization: `Bearer ${config.authToken}` },
});
} }
/** /**
@@ -651,7 +586,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} config.userId - The ID of the user. * @param {string} config.userId - The ID of the user.
* @param {string} config.sortOrder - The order in which to sort the checks. * @param {string} config.sortOrder - The order in which to sort the checks.
* @param {number} config.limit - The maximum number of checks to retrieve. * @param {number} config.limit - The maximum number of checks to retrieve.
@@ -671,9 +605,7 @@ class NetworkService {
if (config.page) params.append("page", config.page); if (config.page) params.append("page", config.page);
if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage); if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage);
if (config.status !== undefined) params.append("status", config.status); if (config.status !== undefined) params.append("status", config.status);
return this.axiosInstance.get(`/checks/team/${config.teamId}?${params.toString()}`, { return this.axiosInstance.get(`/checks/team/${config.teamId}?${params.toString()}`);
headers: { Authorization: `Bearer ${config.authToken}` },
});
} }
/** /**
@@ -683,7 +615,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {number} config.ttl - TTL for checks * @param {number} config.ttl - TTL for checks
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
* *
@@ -694,7 +625,6 @@ class NetworkService {
{ ttl: config.ttl }, { ttl: config.ttl },
{ {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
@@ -708,7 +638,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @returns {Promise<AxiosResponse>} The response from the axios GET request. * @returns {Promise<AxiosResponse>} The response from the axios GET request.
* *
*/ */
@@ -716,7 +645,6 @@ class NetworkService {
async getAppSettings(config) { async getAppSettings(config) {
return this.axiosInstance.get("/settings", { return this.axiosInstance.get("/settings", {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -730,14 +658,12 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {Object} config.settings - The monitor object to be sent in the request body. * @param {Object} config.settings - The monitor object to be sent in the request body.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
*/ */
async updateAppSettings(config) { async updateAppSettings(config) {
return this.axiosInstance.put(`/settings`, config.settings, { return this.axiosInstance.put(`/settings`, config.settings, {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -750,7 +676,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {Object} config.maintenanceWindow - The maintenance window object to be sent in the request body. * @param {Object} config.maintenanceWindow - The maintenance window object to be sent in the request body.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
* *
@@ -759,7 +684,6 @@ class NetworkService {
async createMaintenanceWindow(config) { async createMaintenanceWindow(config) {
return this.axiosInstance.post(`/maintenance-window`, config.maintenanceWindow, { return this.axiosInstance.post(`/maintenance-window`, config.maintenanceWindow, {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -772,7 +696,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {Object} config.maintenanceWindowId - The maintenance window id. * @param {Object} config.maintenanceWindowId - The maintenance window id.
* @param {Object} config.maintenanceWindow - The maintenance window object to be sent in the request body. * @param {Object} config.maintenanceWindow - The maintenance window object to be sent in the request body.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
@@ -785,7 +708,6 @@ class NetworkService {
config.maintenanceWindow, config.maintenanceWindow,
{ {
headers: { headers: {
Authorization: `Bearer ${config.authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
@@ -799,17 +721,15 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} [config.maintenanceWindowId] - The id of the maintenance window to delete. * @param {string} [config.maintenanceWindowId] - The id of the maintenance window to delete.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
* *
*/ */
async getMaintenanceWindowById(config) { async getMaintenanceWindowById(config) {
const { authToken, maintenanceWindowId } = config; const { maintenanceWindowId } = config;
return this.axiosInstance.get(`/maintenance-window/${maintenanceWindowId}`, { return this.axiosInstance.get(`/maintenance-window/${maintenanceWindowId}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -822,7 +742,6 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} [config.active] - The status of the maintenance windows to retrieve. * @param {string} [config.active] - The status of the maintenance windows to retrieve.
* @param {number} [config.page] - The page number for pagination. * @param {number} [config.page] - The page number for pagination.
* @param {number} [config.rowsPerPage] - The number of rows per page for pagination. * @param {number} [config.rowsPerPage] - The number of rows per page for pagination.
@@ -833,7 +752,7 @@ class NetworkService {
*/ */
async getMaintenanceWindowsByTeamId(config) { async getMaintenanceWindowsByTeamId(config) {
const { authToken, active, page, rowsPerPage, field, order } = config; const { active, page, rowsPerPage, field, order } = config;
const params = new URLSearchParams(); const params = new URLSearchParams();
if (active) params.append("status", active); if (active) params.append("status", active);
@@ -844,7 +763,6 @@ class NetworkService {
return this.axiosInstance.get(`/maintenance-window/team?${params.toString()}`, { return this.axiosInstance.get(`/maintenance-window/team?${params.toString()}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -856,17 +774,15 @@ class NetworkService {
* *
* @async * @async
* @param {Object} config - The configuration object. * @param {Object} config - The configuration object.
* @param {string} config.authToken - The authorization token to be used in the request header.
* @param {string} [config.maintenanceWindowId] - The id of the maintenance window to delete. * @param {string} [config.maintenanceWindowId] - The id of the maintenance window to delete.
* @returns {Promise<AxiosResponse>} The response from the axios POST request. * @returns {Promise<AxiosResponse>} The response from the axios POST request.
* *
*/ */
async deleteMaintenanceWindow(config) { async deleteMaintenanceWindow(config) {
const { authToken, maintenanceWindowId } = config; const { maintenanceWindowId } = config;
return this.axiosInstance.delete(`/maintenance-window/${maintenanceWindowId}`, { return this.axiosInstance.delete(`/maintenance-window/${maintenanceWindowId}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -889,7 +805,6 @@ class NetworkService {
subscribeToDistributedUptimeMonitors(config) { subscribeToDistributedUptimeMonitors(config) {
const { const {
authToken,
teamId, teamId,
onUpdate, onUpdate,
onError, onError,
@@ -922,15 +837,13 @@ class NetworkService {
} }
const url = `${this.axiosInstance.defaults.baseURL}/distributed-uptime/monitors/${teamId}?${params.toString()}`; const url = `${this.axiosInstance.defaults.baseURL}/distributed-uptime/monitors/${teamId}?${params.toString()}`;
this.eventSource = new EventSource(url, { this.eventSource = new EventSource(url);
headers: { Authorization: `Bearer ${authToken}` },
});
this.eventSource.onopen = () => { this.eventSource.onopen = () => {
onOpen?.(); onOpen?.();
}; };
this.eventSource.addEventListener("open", (e) => {}); this.eventSource.addEventListener("open", (e) => { });
this.eventSource.onmessage = (event) => { this.eventSource.onmessage = (event) => {
const data = JSON.parse(event.data); const data = JSON.parse(event.data);
@@ -957,15 +870,13 @@ class NetworkService {
subscribeToDistributedUptimeDetails(config) { subscribeToDistributedUptimeDetails(config) {
const params = new URLSearchParams(); const params = new URLSearchParams();
const { authToken, monitorId, onUpdate, onOpen, onError, dateRange, normalize } = const { monitorId, onUpdate, onOpen, onError, dateRange, normalize } =
config; config;
if (dateRange) params.append("dateRange", dateRange); if (dateRange) params.append("dateRange", dateRange);
if (normalize) params.append("normalize", normalize); if (normalize) params.append("normalize", normalize);
const url = `${this.axiosInstance.defaults.baseURL}/distributed-uptime/monitors/details/${monitorId}?${params.toString()}`; const url = `${this.axiosInstance.defaults.baseURL}/distributed-uptime/monitors/details/${monitorId}?${params.toString()}`;
this.eventSource = new EventSource(url, { this.eventSource = new EventSource(url);
headers: { Authorization: `Bearer ${authToken}` },
});
this.eventSource.onopen = (e) => { this.eventSource.onopen = (e) => {
onOpen?.(); onOpen?.();
@@ -989,41 +900,37 @@ class NetworkService {
}; };
} }
async getStatusPage(config) { async getStatusPage() {
const { authToken } = config;
return this.axiosInstance.get(`/status-page`, { return this.axiosInstance.get(`/status-page`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
} }
async getStatusPageByUrl(config) { async getStatusPageByUrl(config) {
const { authToken, url, type } = config; const { url, type } = config;
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append("type", type); params.append("type", type);
return this.axiosInstance.get(`/status-page/${url}?${params.toString()}`, { return this.axiosInstance.get(`/status-page/${url}?${params.toString()}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
} }
async getStatusPagesByTeamId(config) { async getStatusPagesByTeamId(config) {
const { authToken, teamId } = config; const { teamId } = config;
return this.axiosInstance.get(`/status-page/team/${teamId}`, { return this.axiosInstance.get(`/status-page/team/${teamId}`, {
headers: { headers: {
Authorization: `Bearer ${authToken}`,
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
} }
async createStatusPage(config) { async createStatusPage(config) {
const { authToken, user, form, isCreate } = config; const { user, form, isCreate } = config;
const fd = new FormData(); const fd = new FormData();
fd.append("teamId", user.teamId); fd.append("teamId", user.teamId);
@@ -1052,29 +959,17 @@ class NetworkService {
} }
} }
if (isCreate) { if (isCreate) {
return this.axiosInstance.post(`/status-page`, fd, { return this.axiosInstance.post(`/status-page`, fd);
headers: {
Authorization: `Bearer ${authToken}`,
},
});
} }
return this.axiosInstance.put(`/status-page`, fd, { return this.axiosInstance.put(`/status-page`, fd);
headers: {
Authorization: `Bearer ${authToken}`,
},
});
} }
async deleteStatusPage(config) { async deleteStatusPage(config) {
const { authToken, url } = config; const { url } = config;
const encodedUrl = encodeURIComponent(url); const encodedUrl = encodeURIComponent(url);
return this.axiosInstance.delete(`/status-page/${encodedUrl}`, { return this.axiosInstance.delete(`/status-page/${encodedUrl}`);
headers: {
Authorization: `Bearer ${authToken}`,
},
});
} }
} }