All files / app/assets/javascripts/user_lists/store/index actions.js

95.83% Statements 23/24
50% Branches 1/2
92.31% Functions 12/13
95.24% Lines 20/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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      2x 14x   2x 15x   15x 11x 3x     14x 2x 11x 3x   2x 2x   2x 1x   1x             2x     2x 1x 2x  
import Api from '~/api';
import * as types from './mutation_types';
 
export const setUserListsOptions = ({ commit }, options) =>
  commit(types.SET_USER_LISTS_OPTIONS, options);
 
export const fetchUserLists = ({ state, dispatch }) => {
  dispatch('requestUserLists');
 
  return Api.fetchFeatureFlagUserLists(state.projectId, state.options.page)
    .then(({ data, headers }) => dispatch('receiveUserListsSuccess', { data, headers }))
    .catch(() => dispatch('receiveUserListsError'));
};
 
export const requestUserLists = ({ commit }) => commit(types.REQUEST_USER_LISTS);
export const receiveUserListsSuccess = ({ commit }, response) =>
  commit(types.RECEIVE_USER_LISTS_SUCCESS, response);
export const receiveUserListsError = ({ commit }) => commit(types.RECEIVE_USER_LISTS_ERROR);
 
export const deleteUserList = ({ state, dispatch }, list) => {
  dispatch('requestDeleteUserList', list);
 
  return Api.deleteFeatureFlagUserList(state.projectId, list.iid)
    .then(() => dispatch('fetchUserLists'))
    .catch((error) =>
      dispatch('receiveDeleteUserListError', {
        list,
        error: error?.response?.data ?? error,
      }),
    );
};
 
export const requestDeleteUserList = ({ commit }, list) =>
  commit(types.REQUEST_DELETE_USER_LIST, list);
 
export const receiveDeleteUserListError = ({ commit }, { error, list }) =>
  commit(types.RECEIVE_DELETE_USER_LIST_ERROR, { error, list });
export const clearAlert = ({ commit }, index) => commit(types.RECEIVE_CLEAR_ALERT, index);