summaryrefslogtreecommitdiffstats
path: root/src/app/configurableViews/ConfigurableViewActions.js
blob: 7cffaccee47c6baeb8d95e175fd7e7b5b8226757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
  GET,
  POST_HEADER
} from 'app/networking/NetworkConstants.js';
import {
  GET_LAYOUTS_URL,
  configurableViewsActionTypes
} from './ConfigurableViewConstants.js';

function createConfigReceivedEvent(config) {
  return {
    type: configurableViewsActionTypes.CONFIGURABLE_VIEWS_CONFIG_RECEIVED,
    data: config
  };
}

export function newCustomComponentsEvent(components) {
  return {
    type: configurableViewsActionTypes.CUSTOM_COMPONENTS_RECEIVED,
    data: components
  };
}

export function setCustomRoutes(routes) {
  return {
    type: configurableViewsActionTypes.CUSTOM_ROUTES,
    data: routes
  };
}

export function getConfigurableViewConfigs() {
  return dispatch => {
    return fetch(GET_LAYOUTS_URL, {
      method: GET,
      headers: POST_HEADER
    }).then(
      (response) => response.json()
    ).then(
      (responseJson) => {
        dispatch(createConfigReceivedEvent(responseJson));
      }
    ).catch(
      (err) => {
        console.log(`problems fetching configurable view configs: ${err}`);
      }
    );
  };
}