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

100% Statements 18/18
100% Branches 0/0
100% Functions 9/9
100% Lines 17/17

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        2x 20x 20x 17x 4x     2x 2x 6x 6x     2x 3x 3x     2x 9x   9x       8x 8x    
import Api from '~/api';
import { stringifyUserIds } from '../utils';
import * as types from './mutation_types';
 
export const fetchUserList = ({ commit, state }) => {
  commit(types.REQUEST_USER_LIST);
  return Api.fetchFeatureFlagUserList(state.projectId, state.userListIid)
    .then((response) => commit(types.RECEIVE_USER_LIST_SUCCESS, response.data))
    .catch(() => commit(types.RECEIVE_USER_LIST_ERROR));
};
 
export const dismissErrorAlert = ({ commit }) => commit(types.DISMISS_ERROR_ALERT);
export const addUserIds = ({ dispatch, commit }, userIds) => {
  commit(types.ADD_USER_IDS, userIds);
  return dispatch('updateUserList');
};
 
export const removeUserId = ({ commit, dispatch }, userId) => {
  commit(types.REMOVE_USER_ID, userId);
  return dispatch('updateUserList');
};
 
export const updateUserList = ({ commit, state }) => {
  commit(types.REQUEST_USER_LIST);
 
  return Api.updateFeatureFlagUserList(state.projectId, {
    ...state.userList,
    user_xids: stringifyUserIds(state.userIds),
  })
    .then((response) => commit(types.RECEIVE_USER_LIST_SUCCESS, response.data))
    .catch(() => commit(types.RECEIVE_USER_LIST_ERROR));
};