summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/settings/store/actions.js
blob: 0530a870eccbd047e4fe696ac849659c5a7910de (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
import Api from '~/api';
import * as types from './mutation_types';

export const setInitialState = ({ commit }, data) => commit(types.SET_INITIAL_STATE, data);
export const updateSettings = ({ commit }, data) => commit(types.UPDATE_SETTINGS, data);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_LOADING);
export const receiveSettingsSuccess = ({ commit }, data) => {
  commit(types.SET_SETTINGS, data);
};
export const resetSettings = ({ commit }) => commit(types.RESET_SETTINGS);

export const fetchSettings = ({ dispatch, state }) => {
  dispatch('toggleLoading');
  return Api.project(state.projectId)
    .then(({ data: { container_expiration_policy } }) =>
      dispatch('receiveSettingsSuccess', container_expiration_policy),
    )
    .finally(() => dispatch('toggleLoading'));
};

export const saveSettings = ({ dispatch, state }) => {
  dispatch('toggleLoading');
  return Api.updateProject(state.projectId, {
    container_expiration_policy_attributes: state.settings,
  })
    .then(({ data: { container_expiration_policy } }) =>
      dispatch('receiveSettingsSuccess', container_expiration_policy),
    )
    .finally(() => dispatch('toggleLoading'));
};