29 lines
784 B
JavaScript
29 lines
784 B
JavaScript
import { List } from 'immutable';
|
|
|
|
import { getEndpointUrl } from '../api/index.js';
|
|
|
|
import {
|
|
EVENTS_LOADED,
|
|
GET_EVENTS,
|
|
} from '../constants/actionTypes.js';
|
|
|
|
import { blockUI, unblockUI } from './index.js';
|
|
import { API_ENDPOINTS } from '../constants/constants.js';
|
|
|
|
import Event from '../domain/Event.js';
|
|
|
|
|
|
const eventsLoadSuccess = (events, dispatch) => {
|
|
const payload = List(events).map((i) => Event.fromJS(i));
|
|
dispatch({ type: EVENTS_LOADED, payload });
|
|
dispatch(unblockUI);
|
|
};
|
|
|
|
export const fetchEvents = () => (dispatch) => {
|
|
dispatch(blockUI());
|
|
fetch(getEndpointUr(API_ENDPOINTS.GET_EVENTS))
|
|
.then(response => response.json())
|
|
.then(payload => eventsLoadSuccess(payload, dispatch))
|
|
.catch(err => console.error('[actions::getEvents]', err));
|
|
};
|