remove unused reducers
This commit is contained in:
1 parent
9503f08dd8
commit
5e6aaa3caa
3 files changed
+1
-703
No files matched your search
@@ -1,389 +0,0 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
||||||
import { networkService } from "../../main";
|
|
||||||
const initialState = {
|
|
||||||
isLoading: false,
|
|
||||||
monitorsSummary: [],
|
|
||||||
success: null,
|
|
||||||
msg: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/createMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.createMonitor({ monitor: monitor });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const checkInfrastructureEndpointResolution = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/CheckEndpoint",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorURL } = data;
|
|
||||||
const res = await networkService.checkEndpointResolution({
|
|
||||||
monitorURL: monitorURL,
|
|
||||||
});
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getInfrastructureMonitorById = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/getMonitorById",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getInfrastructureMonitorsByTeamId = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/getMonitorsByTeamId",
|
|
||||||
async (_, thunkApi) => {
|
|
||||||
const user = thunkApi.getState().auth.user;
|
|
||||||
try {
|
|
||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
|
||||||
teamId: user.teamId,
|
|
||||||
types: ["hardware"],
|
|
||||||
limit: 1,
|
|
||||||
rowsPerPage: 0,
|
|
||||||
});
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const updateInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/updateMonitor",
|
|
||||||
async ({ monitorId, monitor }, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const updatedFields = {
|
|
||||||
name: monitor.name,
|
|
||||||
description: monitor.description,
|
|
||||||
interval: monitor.interval,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
thresholds: monitor.thresholds,
|
|
||||||
secret: monitor.secret,
|
|
||||||
};
|
|
||||||
const res = await networkService.updateMonitor({
|
|
||||||
monitorId,
|
|
||||||
monitor,
|
|
||||||
updatedFields,
|
|
||||||
});
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const deleteInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/deleteMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.deleteMonitorById({ monitorId: monitor._id });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const pauseInfrastructureMonitor = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/pauseMonitor",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.pauseMonitorById({ monitorId: monitorId });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const deleteInfrastructureMonitorChecksByTeamId = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/deleteChecksByTeamId",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { teamId } = data;
|
|
||||||
const res = await networkService.deleteChecksByTeamId({ teamId: teamId });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const deleteAllInfrastructureMonitors = createAsyncThunk(
|
|
||||||
"infrastructureMonitors/deleteAllMonitors",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const res = await networkService.deleteAllMonitors();
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const infrastructureMonitorsSlice = createSlice({
|
|
||||||
name: "infrastructureMonitors",
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
clearInfrastructureMonitorState: (state) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.monitorsSummary = [];
|
|
||||||
state.success = null;
|
|
||||||
state.msg = null;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
// *****************************************************
|
|
||||||
// Monitors by teamId
|
|
||||||
// *****************************************************
|
|
||||||
|
|
||||||
.addCase(getInfrastructureMonitorsByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorsByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.msg;
|
|
||||||
state.monitorsSummary = action.payload.data;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorsByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Getting infrastructure monitors failed";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Create Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(createInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(createInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(createInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to create infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Resolve Endpoint
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(checkInfrastructureEndpointResolution.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(checkInfrastructureEndpointResolution.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(checkInfrastructureEndpointResolution.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to check endpoint resolution";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Get Monitor By Id
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(getInfrastructureMonitorById.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorById.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(getInfrastructureMonitorById.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to get infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// update Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(updateInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(updateInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(updateInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to update infrastructure monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor checks by Team ID
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteInfrastructureMonitorChecksByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitorChecksByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteInfrastructureMonitorChecksByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete monitor checks";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Pause Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(pauseInfrastructureMonitor.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(pauseInfrastructureMonitor.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(pauseInfrastructureMonitor.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to pause infrastructure monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Delete all Monitors
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deleteAllInfrastructureMonitors.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deleteAllInfrastructureMonitors.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deleteAllInfrastructureMonitors.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload ? action.payload.msg : "Failed to delete all monitors";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setInfrastructureMonitors, clearInfrastructureMonitorState } =
|
|
||||||
infrastructureMonitorsSlice.actions;
|
|
||||||
|
|
||||||
export default infrastructureMonitorsSlice.reducer;
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
|
||||||
import { networkService } from "../../main";
|
|
||||||
const initialState = {
|
|
||||||
isLoading: false,
|
|
||||||
monitorsSummary: [],
|
|
||||||
success: null,
|
|
||||||
msg: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createPageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/createPageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.createMonitor({ monitor: monitor });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const checkEndpointResolution = createAsyncThunk(
|
|
||||||
"monitors/checkEndpoint",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorURL } = data;
|
|
||||||
const res = await networkService.checkEndpointResolution({
|
|
||||||
monitorURL: monitorURL,
|
|
||||||
});
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getPagespeedMonitorById = createAsyncThunk(
|
|
||||||
"monitors/getMonitorById",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getPageSpeedByTeamId = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/getPageSpeedByTeamId",
|
|
||||||
async (_, thunkApi) => {
|
|
||||||
const user = thunkApi.getState().auth.user;
|
|
||||||
try {
|
|
||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
|
||||||
teamId: user.teamId,
|
|
||||||
types: ["pagespeed"],
|
|
||||||
});
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const updatePageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/updatePageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const updatedFields = {
|
|
||||||
name: monitor.name,
|
|
||||||
description: monitor.description,
|
|
||||||
interval: monitor.interval,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
};
|
|
||||||
const res = await networkService.updateMonitor({
|
|
||||||
monitorId: monitor._id,
|
|
||||||
updatedFields: updatedFields,
|
|
||||||
});
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const deletePageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/deletePageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitor } = data;
|
|
||||||
const res = await networkService.deleteMonitorById({ monitorId: monitor._id });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
export const pausePageSpeed = createAsyncThunk(
|
|
||||||
"pageSpeedMonitors/pausePageSpeed",
|
|
||||||
async (data, thunkApi) => {
|
|
||||||
try {
|
|
||||||
const { monitorId } = data;
|
|
||||||
const res = await networkService.pauseMonitorById({ monitorId: monitorId });
|
|
||||||
return res.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (error.response && error.response.data) {
|
|
||||||
return thunkApi.rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
const payload = {
|
|
||||||
status: false,
|
|
||||||
msg: error.message ? error.message : "Unknown error",
|
|
||||||
};
|
|
||||||
return thunkApi.rejectWithValue(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const pageSpeedMonitorSlice = createSlice({
|
|
||||||
name: "pageSpeedMonitor",
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
clearMonitorState: (state) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.monitorsSummary = [];
|
|
||||||
state.success = null;
|
|
||||||
state.msg = null;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder
|
|
||||||
// *****************************************************
|
|
||||||
// Monitors by teamId
|
|
||||||
// *****************************************************
|
|
||||||
|
|
||||||
.addCase(getPageSpeedByTeamId.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getPageSpeedByTeamId.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.msg;
|
|
||||||
state.monitorsSummary = action.payload.data;
|
|
||||||
})
|
|
||||||
.addCase(getPageSpeedByTeamId.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Getting page speed monitors failed";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(getPagespeedMonitorById.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(getPagespeedMonitorById.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(getPagespeedMonitorById.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to get pagespeed monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Create Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(createPageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(createPageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(createPageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to create page speed monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Resolve Endpoint
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(checkEndpointResolution.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(checkEndpointResolution.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(checkEndpointResolution.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to check endpoint resolution";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Update Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(updatePageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(updatePageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(updatePageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to update page speed monitor";
|
|
||||||
})
|
|
||||||
|
|
||||||
// *****************************************************
|
|
||||||
// Delete Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(deletePageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(deletePageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(deletePageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to delete page speed monitor";
|
|
||||||
})
|
|
||||||
// *****************************************************
|
|
||||||
// Pause Monitor
|
|
||||||
// *****************************************************
|
|
||||||
.addCase(pausePageSpeed.pending, (state) => {
|
|
||||||
state.isLoading = true;
|
|
||||||
})
|
|
||||||
.addCase(pausePageSpeed.fulfilled, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
})
|
|
||||||
.addCase(pausePageSpeed.rejected, (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = false;
|
|
||||||
state.msg = action.payload
|
|
||||||
? action.payload.msg
|
|
||||||
: "Failed to pause page speed monitor";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const { setMonitors, clearMonitorState } = pageSpeedMonitorSlice.actions;
|
|
||||||
|
|
||||||
export default pageSpeedMonitorSlice.reducer;
|
|
||||||
+1
-5
@@ -1,7 +1,5 @@
|
|||||||
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
import infrastructureMonitorsReducer from "./Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
|
||||||
import pageSpeedMonitorReducer from "./Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
|
||||||
import authReducer from "./Features/Auth/authSlice";
|
import authReducer from "./Features/Auth/authSlice";
|
||||||
import uiReducer from "./Features/UI/uiSlice";
|
import uiReducer from "./Features/UI/uiSlice";
|
||||||
import settingsReducer from "./Features/Settings/settingsSlice";
|
import settingsReducer from "./Features/Settings/settingsSlice";
|
||||||
@@ -22,14 +20,12 @@ const authTransform = createTransform(
|
|||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: "root",
|
key: "root",
|
||||||
storage,
|
storage,
|
||||||
whitelist: ["auth", "pageSpeed", "ui", "settings"],
|
whitelist: ["auth", "ui", "settings"],
|
||||||
transforms: [authTransform],
|
transforms: [authTransform],
|
||||||
};
|
};
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
infrastructureMonitors: infrastructureMonitorsReducer,
|
|
||||||
auth: authReducer,
|
auth: authReducer,
|
||||||
pageSpeedMonitors: pageSpeedMonitorReducer,
|
|
||||||
ui: uiReducer,
|
ui: uiReducer,
|
||||||
settings: settingsReducer,
|
settings: settingsReducer,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user