about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/actions/rules.js
blob: b95045e81acce72588153afeb274f853d1cac2a1 (plain) (blame)
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
import api from 'flavours/glitch/util/api';

export const RULES_FETCH_REQUEST = 'RULES_FETCH_REQUEST';
export const RULES_FETCH_SUCCESS = 'RULES_FETCH_SUCCESS';
export const RULES_FETCH_FAIL    = 'RULES_FETCH_FAIL';

export const fetchRules = () => (dispatch, getState) => {
  dispatch(fetchRulesRequest());

  api(getState)
    .get('/api/v1/instance').then(({ data }) => dispatch(fetchRulesSuccess(data.rules)))
    .catch(err => dispatch(fetchRulesFail(err)));
};

const fetchRulesRequest = () => ({
  type: RULES_FETCH_REQUEST,
});

const fetchRulesSuccess = rules => ({
  type: RULES_FETCH_SUCCESS,
  rules,
});

const fetchRulesFail = error => ({
  type: RULES_FETCH_FAIL,
  error,
});