This commit is contained in:
2019-07-24 00:53:01 -04:00
parent 434a1ded24
commit a9f4324f29
21 changed files with 345 additions and 100 deletions

38
app/actions/items.js Normal file
View File

@@ -0,0 +1,38 @@
import { List } from 'immutable';
import { getEndpointUrl } from '../api/index.js';
import {
GET_ITEMS,
ITEMS_LOADED,
} from '../constants/actionTypes.js';
import { blockUI, unblockUI } from './index.js';
import { API_ENDPOINTS } from '../constants/constants.js';
import Item from '../domain/Item.js';
const itemsLoadSuccess = (items, dispatch) => {
const payload = List(items).map((i) => Item.fromJS(i));
dispatch({ type: ITEMS_LOADED, payload });
dispatch(unblockUI);
};
export const fetchItems = () => (dispatch, getState) => {
const state = getState();
const activeEvent = state.get('activeEvent');
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_ITEMS);
apiUrl = apiUrl.replace(/:event_id$/, '');
if (activeEvent) {
apiUrl = `${apiUrl}${activeEvent}`;
}
dispatch(blockUI());
fetch(apiUrl)
.then(response => response.json())
.then(payload => itemsLoadSuccess(payload, dispatch))
.catch(err => console.error('[actions::getItems]', err));
};