summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/feature_flags/store/gitlab_user_list/actions.js
blob: a834524df6cd10e318beaad9eca9282b7ead72ad (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');
};