diff options
Diffstat (limited to 'app/javascript/flavours/glitch/actions/rules.js')
-rw-r--r-- | app/javascript/flavours/glitch/actions/rules.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/actions/rules.js b/app/javascript/flavours/glitch/actions/rules.js new file mode 100644 index 000000000..b95045e81 --- /dev/null +++ b/app/javascript/flavours/glitch/actions/rules.js @@ -0,0 +1,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, +}); |