-More!
This commit is contained in:
33
app/actions/profile.js
Normal file
33
app/actions/profile.js
Normal file
@@ -0,0 +1,33 @@
|
||||
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 setActiveEvent = (eventId) => ({
|
||||
type: SET_ACTIVE_EVENT,
|
||||
payload: eventId,
|
||||
});
|
||||
|
||||
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));
|
||||
};
|
||||
Reference in New Issue
Block a user