Welcome to mirror list, hosted at ThFree Co, Russian Federation.

actions.js « new « store « feature_flags « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e21c128cd39763986b4c9a5f496cded55df5bb9e (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
import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility';
import { NEW_VERSION_FLAG } from '../../constants';
import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers';

/**
 * Handles the creation of a new feature flag.
 *
 * Will dispatch `requestCreateFeatureFlag`
 * Serializes the params and makes a post request
 * Dispatches an action acording to the request status.
 *
 * @param {Object} params
 */
export const createFeatureFlag = ({ state, dispatch }, params) => {
  dispatch('requestCreateFeatureFlag');

  return axios
    .post(
      state.endpoint,
      params.version === NEW_VERSION_FLAG
        ? mapStrategiesToRails(params)
        : mapFromScopesViewModel(params),
    )
    .then(() => {
      dispatch('receiveCreateFeatureFlagSuccess');
      visitUrl(state.path);
    })
    .catch(error => dispatch('receiveCreateFeatureFlagError', error.response.data));
};

export const requestCreateFeatureFlag = ({ commit }) => commit(types.REQUEST_CREATE_FEATURE_FLAG);
export const receiveCreateFeatureFlagSuccess = ({ commit }) =>
  commit(types.RECEIVE_CREATE_FEATURE_FLAG_SUCCESS);
export const receiveCreateFeatureFlagError = ({ commit }, error) =>
  commit(types.RECEIVE_CREATE_FEATURE_FLAG_ERROR, error);