- Initial commit
This commit is contained in:
29
app/actions/index.js
Normal file
29
app/actions/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getEndpointUrl } from '../api/index.js';
|
||||
import {
|
||||
EVENTS_LOADED,
|
||||
GET_EVENTS,
|
||||
GET_ITEMS,
|
||||
ITEMS_LOADED,
|
||||
} from '../constants/actionTypes.js';
|
||||
import { API_ENDPOINTS } from '../constants/constants.js';
|
||||
|
||||
export const getEvents = () => (dispatch) => {
|
||||
return fetch(getEndpointUrl[API_ENDPOINTS.GET_EVENTS])
|
||||
.then(response => response.json())
|
||||
.then(payload => {
|
||||
dispatch({ type: EVENTS_LOADED, payload });
|
||||
});
|
||||
};
|
||||
|
||||
export const getItems = () => (dispatch, getState) => {
|
||||
const { activeEvent } = getState();
|
||||
let apiUrl = getEndpointUrl[API_ENDPOINTS.GET_ITEMS];
|
||||
apiUrl = apiUrl.replace(/:event_id/, activeEvent);
|
||||
|
||||
return fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(payload => {
|
||||
dispatch({ type: ITEMS_LOADED, payload });
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user