Add thunk and network methods
This commit is contained in:
1 parent
6708027d66
commit
13039ed2ff
2 files changed
+57
No files matched your search
@@ -149,6 +149,26 @@ export const pauseUptimeMonitor = createAsyncThunk(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const deleteMonitorChecksByTeamId = createAsyncThunk(
|
||||||
|
"monitors/deleteChecksByTeamId",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, teamId } = data;
|
||||||
|
const res = await networkService.deleteChecksByTeamId(authToken, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const uptimeMonitorsSlice = createSlice({
|
const uptimeMonitorsSlice = createSlice({
|
||||||
name: "uptimeMonitors",
|
name: "uptimeMonitors",
|
||||||
initialState,
|
initialState,
|
||||||
@@ -256,6 +276,24 @@ const uptimeMonitorsSlice = createSlice({
|
|||||||
: "Failed to delete uptime monitor";
|
: "Failed to delete uptime monitor";
|
||||||
})
|
})
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
|
// Delete Monitor checks by Team ID
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(deleteMonitorChecksByTeamId.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(deleteMonitorChecksByTeamId.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(deleteMonitorChecksByTeamId.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to delete monitor checks";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
// Pause Monitor
|
// Pause Monitor
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
.addCase(pauseUptimeMonitor.pending, (state) => {
|
.addCase(pauseUptimeMonitor.pending, (state) => {
|
||||||
|
|||||||
@@ -184,6 +184,25 @@ class NetworkService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ************************************
|
||||||
|
* Deletes all checks for all monitor by teamID
|
||||||
|
* ************************************
|
||||||
|
*
|
||||||
|
* @async
|
||||||
|
* @param {string} authToken - The authorization token to be used in the request header.
|
||||||
|
* @param {string} monitorId - The ID of the monitor to be deleted.
|
||||||
|
* @returns {Promise<AxiosResponse>} The response from the axios DELETE request.
|
||||||
|
*/
|
||||||
|
async deleteChecksByTeamId(authToken, teamId) {
|
||||||
|
return this.axiosInstance.delete(`/checks/team/${teamId}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* ************************************
|
* ************************************
|
||||||
* Pauses a single monitor by its ID
|
* Pauses a single monitor by its ID
|
||||||
|
|||||||
Reference in new issue
Block a user