|
@@ -35,6 +35,34 @@ export const postNewEvent = payload => {
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+//PUT
|
|
|
|
+const editEventRequest = payload => ({
|
|
|
|
+ type: types.EDIT_EVENT_REQUEST,
|
|
|
|
+ payload
|
|
|
|
+});
|
|
|
|
+const editEventRequestSuccess = payload => ({
|
|
|
|
+ type: types.EDIT_EVENT_REQUEST_SUCCESS,
|
|
|
|
+ payload
|
|
|
|
+});
|
|
|
|
+const editEventRequestFail = payload => ({
|
|
|
|
+ type: types.EDIT_EVENT_REQUEST_FAIL,
|
|
|
|
+ payload
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+export const changeEvent = (payload) => {
|
|
|
|
+ return async dispatch => {
|
|
|
|
+ dispatch(editEventRequest());
|
|
|
|
+ try {
|
|
|
|
+ await axios.put(`https://api-marathon.herokuapp.com/api/v1/event/${payload._id} `, payload);
|
|
|
|
+ dispatch(editEventRequestSuccess({payload, id: payload._id}));
|
|
|
|
+ console.log("Event Changed", payload)
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log('edit payload',payload)
|
|
|
|
+ dispatch(editEventRequestFail(error));
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+};
|
|
|
|
+
|
|
//GET
|
|
//GET
|
|
const getEventsRequest = payload => ({
|
|
const getEventsRequest = payload => ({
|
|
type: types.GET_EVENTS_REQUEST,
|
|
type: types.GET_EVENTS_REQUEST,
|
|
@@ -75,10 +103,10 @@ const removeEventFail = payload => ({
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-export const removePost = id => dispatch => {
|
|
|
|
|
|
+export const removeEvent = _id => dispatch => {
|
|
dispatch(removeEventRequest());
|
|
dispatch(removeEventRequest());
|
|
return axios
|
|
return axios
|
|
- .delete(`https://api-marathon.herokuapp.com/api/v1/event/:${id}`)
|
|
|
|
- .then(res => dispatch(removeEventSuccess({ res, id })))
|
|
|
|
|
|
+ .delete(` https://api-marathon.herokuapp.com/api/v1/event/${_id}`)
|
|
|
|
+ .then(res => dispatch(removeEventSuccess({ res, _id })))
|
|
.catch(err => dispatch(removeEventFail(err)));
|
|
.catch(err => dispatch(removeEventFail(err)));
|
|
};
|
|
};
|