|
@@ -1,36 +1,43 @@
|
|
-import axios from "axios";
|
|
|
|
-import * as types from "../actionTypes/actionTypes"
|
|
|
|
|
|
+import axios from 'axios';
|
|
|
|
+import * as types from '../actionTypes/actionTypes';
|
|
|
|
|
|
-const eventURL = 'https://api-marathon.herokuapp.com/api/v1/event'
|
|
|
|
|
|
+const eventURL = 'https://api-marathon.herokuapp.com/api/v1/event';
|
|
|
|
|
|
-export const editEvent = payload => {
|
|
|
|
|
|
+export const editEvent = (payload) => {
|
|
return {
|
|
return {
|
|
type: types.EDIT_EVENT,
|
|
type: types.EDIT_EVENT,
|
|
payload
|
|
payload
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+export const changeEditFlag = (payload) => {
|
|
|
|
+ return {
|
|
|
|
+ type: types.CHANGE_EDIT_FLAG,
|
|
|
|
+ payload
|
|
|
|
+ };
|
|
|
|
+};
|
|
|
|
+
|
|
//POST
|
|
//POST
|
|
-const postNewEventRequest = payload => ({
|
|
|
|
|
|
+const postNewEventRequest = (payload) => ({
|
|
type: types.POST_NEW_EVENT_REQUEST,
|
|
type: types.POST_NEW_EVENT_REQUEST,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
-const postNewEventRequestSuccess = payload => ({
|
|
|
|
|
|
+const postNewEventRequestSuccess = (payload) => ({
|
|
type: types.POST_NEW_EVENT_REQUEST_SUCCESS,
|
|
type: types.POST_NEW_EVENT_REQUEST_SUCCESS,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
-const postNewEventRequestFail = payload => ({
|
|
|
|
|
|
+const postNewEventRequestFail = (payload) => ({
|
|
type: types.POST_NEW_EVENT_REQUEST_FAIL,
|
|
type: types.POST_NEW_EVENT_REQUEST_FAIL,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-export const postNewEvent = payload => {
|
|
|
|
- return async dispatch => {
|
|
|
|
|
|
+export const postNewEvent = (payload) => {
|
|
|
|
+ return async (dispatch) => {
|
|
dispatch(postNewEventRequest());
|
|
dispatch(postNewEventRequest());
|
|
try {
|
|
try {
|
|
const { data } = await axios.post(eventURL, payload);
|
|
const { data } = await axios.post(eventURL, payload);
|
|
dispatch(postNewEventRequestSuccess(data));
|
|
dispatch(postNewEventRequestSuccess(data));
|
|
- console.log("New Event Posted", payload)
|
|
|
|
|
|
+ console.log('New Event Posted', payload);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
dispatch(postNewEventRequestFail(error));
|
|
dispatch(postNewEventRequestFail(error));
|
|
}
|
|
}
|
|
@@ -38,102 +45,102 @@ export const postNewEvent = payload => {
|
|
};
|
|
};
|
|
|
|
|
|
//PUT
|
|
//PUT
|
|
-const editEventRequest = payload => ({
|
|
|
|
|
|
+const editEventRequest = (payload) => ({
|
|
type: types.EDIT_EVENT_REQUEST,
|
|
type: types.EDIT_EVENT_REQUEST,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
-const editEventRequestSuccess = payload => ({
|
|
|
|
|
|
+const editEventRequestSuccess = (payload) => ({
|
|
type: types.EDIT_EVENT_REQUEST_SUCCESS,
|
|
type: types.EDIT_EVENT_REQUEST_SUCCESS,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
-const editEventRequestFail = payload => ({
|
|
|
|
|
|
+const editEventRequestFail = (payload) => ({
|
|
type: types.EDIT_EVENT_REQUEST_FAIL,
|
|
type: types.EDIT_EVENT_REQUEST_FAIL,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
export const changeEvent = (payload) => {
|
|
export const changeEvent = (payload) => {
|
|
- return async dispatch => {
|
|
|
|
|
|
+ return async (dispatch) => {
|
|
dispatch(editEventRequest());
|
|
dispatch(editEventRequest());
|
|
try {
|
|
try {
|
|
await axios.put(`${eventURL}/${payload._id} `, payload);
|
|
await axios.put(`${eventURL}/${payload._id} `, payload);
|
|
- dispatch(editEventRequestSuccess({payload, id: payload._id}));
|
|
|
|
- console.log("Event Changed", payload)
|
|
|
|
|
|
+ dispatch(editEventRequestSuccess({ payload, id: payload._id }));
|
|
|
|
+ console.log('Event Changed', payload);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.log('edit payload',payload)
|
|
|
|
|
|
+ console.log('edit payload', payload);
|
|
dispatch(editEventRequestFail(error));
|
|
dispatch(editEventRequestFail(error));
|
|
}
|
|
}
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
//GET
|
|
//GET
|
|
-const getEventsRequest = payload => ({
|
|
|
|
|
|
+const getEventsRequest = (payload) => ({
|
|
type: types.GET_EVENTS_REQUEST,
|
|
type: types.GET_EVENTS_REQUEST,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-const getEventsRequestSuccess = payload => ({
|
|
|
|
|
|
+const getEventsRequestSuccess = (payload) => ({
|
|
type: types.GET_EVENTS_REQUEST_SUCCESS,
|
|
type: types.GET_EVENTS_REQUEST_SUCCESS,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-const getEventsRequestFail = payload => ({
|
|
|
|
|
|
+const getEventsRequestFail = (payload) => ({
|
|
type: types.GET_EVENTS_REQUEST_FAIL,
|
|
type: types.GET_EVENTS_REQUEST_FAIL,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-export const getEvents = (type = 'Select Event Type') => dispatch => {
|
|
|
|
|
|
+export const getEvents = (type = 'Select Event Type') => (dispatch) => {
|
|
dispatch(getEventsRequest());
|
|
dispatch(getEventsRequest());
|
|
return axios
|
|
return axios
|
|
- .get( type !== 'Select Event Type' ? `${eventURL}/?eventType=${type}` : eventURL)
|
|
|
|
- .then(res => dispatch(getEventsRequestSuccess(res)))
|
|
|
|
- .catch(err => dispatch(getEventsRequestFail(err)));
|
|
|
|
|
|
+ .get(type !== 'Select Event Type' ? `${eventURL}/?eventType=${type}` : eventURL)
|
|
|
|
+ .then((res) => dispatch(getEventsRequestSuccess(res)))
|
|
|
|
+ .catch((err) => dispatch(getEventsRequestFail(err)));
|
|
};
|
|
};
|
|
|
|
|
|
-//GET BY TITLE
|
|
|
|
|
|
+//GET BY TITLE
|
|
|
|
|
|
-const getEventByTitleRequest = payload => ({
|
|
|
|
|
|
+const getEventByTitleRequest = (payload) => ({
|
|
type: types.GET_EVENT_BY_TITLE,
|
|
type: types.GET_EVENT_BY_TITLE,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-const getEventByTitleRequestSuccess = payload => ({
|
|
|
|
|
|
+const getEventByTitleRequestSuccess = (payload) => ({
|
|
type: types.GET_EVENT_BY_TITLE_SUCCESS,
|
|
type: types.GET_EVENT_BY_TITLE_SUCCESS,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-const getEventByTitleRequestFail = payload => ({
|
|
|
|
|
|
+const getEventByTitleRequestFail = (payload) => ({
|
|
type: types.GET_EVENT_BY_TITLE_FAIL,
|
|
type: types.GET_EVENT_BY_TITLE_FAIL,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-export const getEventByTitle = (title) => dispatch => {
|
|
|
|
|
|
+export const getEventByTitle = (title) => (dispatch) => {
|
|
dispatch(getEventByTitleRequest());
|
|
dispatch(getEventByTitleRequest());
|
|
return axios
|
|
return axios
|
|
- .get( title && `${eventURL}/?title=${title}`)
|
|
|
|
- .then(res => dispatch(getEventByTitleRequestSuccess(res)))
|
|
|
|
- .catch(err => dispatch(getEventByTitleRequestFail(err)));
|
|
|
|
|
|
+ .get(title && `${eventURL}/?title=${title}`)
|
|
|
|
+ .then((res) => dispatch(getEventByTitleRequestSuccess(res)))
|
|
|
|
+ .catch((err) => dispatch(getEventByTitleRequestFail(err)));
|
|
};
|
|
};
|
|
|
|
|
|
// REMOVE
|
|
// REMOVE
|
|
-const removeEventRequest = payload => ({
|
|
|
|
|
|
+const removeEventRequest = (payload) => ({
|
|
type: types.REMOVE_EVENT_REQUEST,
|
|
type: types.REMOVE_EVENT_REQUEST,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-const removeEventSuccess = payload => ({
|
|
|
|
|
|
+const removeEventSuccess = (payload) => ({
|
|
type: types.REMOVE_EVENT_REQUEST_SUCCESS,
|
|
type: types.REMOVE_EVENT_REQUEST_SUCCESS,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-const removeEventFail = payload => ({
|
|
|
|
|
|
+const removeEventFail = (payload) => ({
|
|
type: types.REMOVE_EVENT_REQUEST_FAIL,
|
|
type: types.REMOVE_EVENT_REQUEST_FAIL,
|
|
payload
|
|
payload
|
|
});
|
|
});
|
|
|
|
|
|
-export const removeEvent = _id => dispatch => {
|
|
|
|
|
|
+export const removeEvent = (_id) => (dispatch) => {
|
|
dispatch(removeEventRequest());
|
|
dispatch(removeEventRequest());
|
|
return axios
|
|
return axios
|
|
.delete(`${eventURL}/${_id}`)
|
|
.delete(`${eventURL}/${_id}`)
|
|
- .then(res => dispatch(removeEventSuccess({ res, _id })))
|
|
|
|
- .catch(err => dispatch(removeEventFail(err)));
|
|
|
|
-};
|
|
|
|
|
|
+ .then((res) => dispatch(removeEventSuccess({ res, _id })))
|
|
|
|
+ .catch((err) => dispatch(removeEventFail(err)));
|
|
|
|
+};
|