Add getting monitors by team id to redux slice to make use of loading state

This commit is contained in:
Alex Holliday committed 2025-01-07 14:24:47 -08:00
1 parent 741f0d1884
commit 290740d58e
1 file changed
+55 -7
@@ -78,12 +78,12 @@ export const getUptimeMonitorById = createAsyncThunk(
} }
); );
export const getUptimeMonitorsByTeamId = createAsyncThunk( export const getUptimeSummaryByTeamId = createAsyncThunk(
"monitors/getMonitorsByTeamId", "monitors/getSummaryByTeamId",
async (token, thunkApi) => { async (token, thunkApi) => {
const user = jwtDecode(token); const user = jwtDecode(token);
try { try {
const res = await networkService.getMonitorsAndSummaryByTeamId({ const res = await networkService.getMonitorsSummaryByTeamId({
authToken: token, authToken: token,
teamId: user.teamId, teamId: user.teamId,
types: ["http", "ping", "docker", "port"], types: ["http", "ping", "docker", "port"],
@@ -102,6 +102,38 @@ export const getUptimeMonitorsByTeamId = createAsyncThunk(
} }
); );
export const getUptimeMonitorsByTeamId = createAsyncThunk(
"monitors/getMonitorsByTeamId",
async (config, thunkApi) => {
try {
const res = await networkService.getMonitorsByTeamId({
authToken: config.authToken,
teamId: config.teamId,
limit: 25,
types: ["http", "ping", "docker", "port"],
status: null,
checkOrder: "desc",
normalize: true,
page: config.page,
rowsPerPage: config.rowsPerPage,
filter: config.filter,
field: config.sort.field,
order: config.sort.order,
});
return res.data;
} catch (error) {
if (error.response && error.response.data) {
return thunkApi.rejectWithValue(error.response.data);
}
const payload = {
status: false,
msg: error.message ? error.message : "Unknown error",
};
return thunkApi.rejectWithValue(payload);
}
}
);
export const updateUptimeMonitor = createAsyncThunk( export const updateUptimeMonitor = createAsyncThunk(
"monitors/updateMonitor", "monitors/updateMonitor",
async (data, thunkApi) => { async (data, thunkApi) => {
@@ -258,16 +290,33 @@ const uptimeMonitorsSlice = createSlice({
extraReducers: (builder) => { extraReducers: (builder) => {
builder builder
// ***************************************************** // *****************************************************
// Monitors by teamId // Summary by teamId
// ***************************************************** // *****************************************************
.addCase(getUptimeSummaryByTeamId.pending, (state) => {
state.isLoading = true;
})
.addCase(getUptimeSummaryByTeamId.fulfilled, (state, action) => {
state.isLoading = false;
state.success = action.payload.msg;
state.monitorsSummary = action.payload.data;
})
.addCase(getUptimeSummaryByTeamId.rejected, (state, action) => {
state.isLoading = false;
state.success = false;
state.msg = action.payload ? action.payload.msg : "Getting uptime summary failed";
})
// *****************************************************
// Monitors by teamId
// *****************************************************
.addCase(getUptimeMonitorsByTeamId.pending, (state) => { .addCase(getUptimeMonitorsByTeamId.pending, (state) => {
state.isLoading = true; state.isLoading = true;
}) })
.addCase(getUptimeMonitorsByTeamId.fulfilled, (state, action) => { .addCase(getUptimeMonitorsByTeamId.fulfilled, (state, action) => {
state.isLoading = false; state.isLoading = false;
state.success = action.payload.msg; state.success = action.payload.success;
state.monitorsSummary = action.payload.data; state.msg = action.payload.msg;
}) })
.addCase(getUptimeMonitorsByTeamId.rejected, (state, action) => { .addCase(getUptimeMonitorsByTeamId.rejected, (state, action) => {
state.isLoading = false; state.isLoading = false;
@@ -276,7 +325,6 @@ const uptimeMonitorsSlice = createSlice({
? action.payload.msg ? action.payload.msg
: "Getting uptime monitors failed"; : "Getting uptime monitors failed";
}) })
// ***************************************************** // *****************************************************
// Create Monitor // Create Monitor
// ***************************************************** // *****************************************************