delete tutorial button at tutorial builder

This commit is contained in:
Delucse
2020-12-08 15:33:03 +01:00
parent e6813ba2d3
commit 3cf7f10d34
2 changed files with 85 additions and 20 deletions
+22
View File
@@ -56,6 +56,28 @@ export const getTutorials = () => (dispatch, getState) => {
});
};
export const deleteTutorial = (id) => (dispatch, getState) => {
var tutorial = getState().tutorial;
var id = getState().builder.id;
axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`)
.then(res => {
var tutorials = tutorial.tutorials;
var index = tutorials.findIndex(res => res._id === id);
tutorials.splice(index, 1)
dispatch({
type: GET_TUTORIALS,
payload: tutorials
});
dispatch(returnSuccess(res.data.message, res.status, 'TUTORIAL_DELETE_SUCCESS'));
})
.catch(err => {
if(err.response){
dispatch(returnErrors(err.response.data.message, err.response.status, 'TUTORIAL_DELETE_FAIL'));
}
});
};
export const resetTutorial = () => (dispatch) => {
dispatch({
type: GET_TUTORIALS,