summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/feature_flags/store/gitlab_user_list/actions.js
blob: d4587713fed81b1f3a720f8836f041474c67c5c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import Api from '~/api';
import * as types from './mutation_types';

const getErrorMessages = error => [].concat(error?.response?.data?.message ?? error.message);

export const fetchUserLists = ({ commit, state: { filter, projectId } }) => {
  commit(types.FETCH_USER_LISTS);

  return Api.searchFeatureFlagUserLists(projectId, filter)
    .then(({ data }) => commit(types.RECEIVE_USER_LISTS_SUCCESS, data))
    .catch(error => commit(types.RECEIVE_USER_LISTS_ERROR, getErrorMessages(error)));
};

export const setFilter = ({ commit, dispatch }, filter) => {
  commit(types.SET_FILTER, filter);
  return dispatch('fetchUserLists');
};