summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/sidebar/labels_select_widget/store/actions.js
blob: 2b96b159ca3168b5080143a64cef93f8c4ec4009 (plain)
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
import { deprecatedCreateFlash as flash } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale';
import * as types from './mutation_types';

export const setInitialState = ({ commit }, props) => commit(types.SET_INITIAL_STATE, props);

export const toggleDropdownButton = ({ commit }) => commit(types.TOGGLE_DROPDOWN_BUTTON);
export const toggleDropdownContents = ({ commit }) => commit(types.TOGGLE_DROPDOWN_CONTENTS);

export const toggleDropdownContentsCreateView = ({ commit }) =>
  commit(types.TOGGLE_DROPDOWN_CONTENTS_CREATE_VIEW);

export const requestLabels = ({ commit }) => commit(types.REQUEST_LABELS);
export const receiveLabelsSuccess = ({ commit }, labels) =>
  commit(types.RECEIVE_SET_LABELS_SUCCESS, labels);
export const receiveLabelsFailure = ({ commit }) => {
  commit(types.RECEIVE_SET_LABELS_FAILURE);
  flash(__('Error fetching labels.'));
};
export const fetchLabels = ({ state, dispatch }) => {
  dispatch('requestLabels');
  return axios
    .get(state.labelsFetchPath)
    .then(({ data }) => {
      dispatch('receiveLabelsSuccess', data);
    })
    .catch(() => dispatch('receiveLabelsFailure'));
};

export const updateSelectedLabels = ({ commit }, labels) =>
  commit(types.UPDATE_SELECTED_LABELS, { labels });