30 lines
795 B
JavaScript
30 lines
795 B
JavaScript
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 });
|
|
});
|
|
};
|
|
|