summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/commits/store/actions.js
blob: a3a53c2f975b3e98df2b9847524f60a23edb189c (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
33
34
35
import * as Sentry from '@sentry/browser';
import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
import { __ } from '~/locale';

export default {
  setInitialData({ commit }, data) {
    commit(types.SET_INITIAL_DATA, data);
  },
  receiveAuthorsSuccess({ commit }, authors) {
    commit(types.COMMITS_AUTHORS, authors);
  },
  receiveAuthorsError() {
    createFlash(__('An error occurred fetching the project authors.'));
  },
  fetchAuthors({ dispatch, state }, author = null) {
    const { projectId } = state;
    const path = '/autocomplete/users.json';

    return axios
      .get(path, {
        params: {
          project_id: projectId,
          active: true,
          search: author,
        },
      })
      .then(({ data }) => dispatch('receiveAuthorsSuccess', data))
      .catch(error => {
        Sentry.captureException(error);
        dispatch('receiveAuthorsError');
      });
  },
};