summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/releases/stores/modules/detail/actions.js
blob: c9749582f5c3eedae471d684699e057e09395329 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as types from './mutation_types';
import api from '~/api';
import createFlash from '~/flash';
import { s__ } from '~/locale';
import { redirectTo } from '~/lib/utils/url_utility';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';

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

export const requestRelease = ({ commit }) => commit(types.REQUEST_RELEASE);
export const receiveReleaseSuccess = ({ commit }, data) =>
  commit(types.RECEIVE_RELEASE_SUCCESS, data);
export const receiveReleaseError = ({ commit }, error) => {
  commit(types.RECEIVE_RELEASE_ERROR, error);
  createFlash(s__('Release|Something went wrong while getting the release details'));
};

export const fetchRelease = ({ dispatch, state }) => {
  dispatch('requestRelease');

  return api
    .release(state.projectId, state.tagName)
    .then(({ data: release }) => {
      const camelCasedRelease = convertObjectPropsToCamelCase(release, { deep: true });
      dispatch('receiveReleaseSuccess', camelCasedRelease);
    })
    .catch(error => {
      dispatch('receiveReleaseError', error);
    });
};

export const updateReleaseTitle = ({ commit }, title) => commit(types.UPDATE_RELEASE_TITLE, title);
export const updateReleaseNotes = ({ commit }, notes) => commit(types.UPDATE_RELEASE_NOTES, notes);

export const requestUpdateRelease = ({ commit }) => commit(types.REQUEST_UPDATE_RELEASE);
export const receiveUpdateReleaseSuccess = ({ commit, dispatch }) => {
  commit(types.RECEIVE_UPDATE_RELEASE_SUCCESS);
  dispatch('navigateToReleasesPage');
};
export const receiveUpdateReleaseError = ({ commit }, error) => {
  commit(types.RECEIVE_UPDATE_RELEASE_ERROR, error);
  createFlash(s__('Release|Something went wrong while saving the release details'));
};

export const updateRelease = ({ dispatch, state }) => {
  dispatch('requestUpdateRelease');

  return api
    .updateRelease(state.projectId, state.tagName, {
      name: state.release.name,
      description: state.release.description,
    })
    .then(() => dispatch('receiveUpdateReleaseSuccess'))
    .catch(error => {
      dispatch('receiveUpdateReleaseError', error);
    });
};

export const navigateToReleasesPage = ({ state }) => {
  redirectTo(state.releasesPagePath);
};