2022-11-25 23:54:43 +05:30
|
|
|
import { createAlert } from '~/flash';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-09-04 21:01:54 +05:30
|
|
|
import { refreshCurrentPage } from '~/lib/utils/url_utility';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { __ } from '~/locale';
|
2019-09-04 21:01:54 +05:30
|
|
|
import * as mutationTypes from './mutation_types';
|
|
|
|
|
|
|
|
export const setExternalDashboardUrl = ({ commit }, url) =>
|
|
|
|
commit(mutationTypes.SET_EXTERNAL_DASHBOARD_URL, url);
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
export const setDashboardTimezone = ({ commit }, selected) =>
|
|
|
|
commit(mutationTypes.SET_DASHBOARD_TIMEZONE, selected);
|
|
|
|
|
|
|
|
export const saveChanges = ({ state, dispatch }) =>
|
2019-09-04 21:01:54 +05:30
|
|
|
axios
|
|
|
|
.patch(state.operationsSettingsEndpoint, {
|
|
|
|
project: {
|
|
|
|
metrics_setting_attributes: {
|
2020-06-23 00:09:42 +05:30
|
|
|
dashboard_timezone: state.dashboardTimezone.selected,
|
|
|
|
external_dashboard_url: state.externalDashboard.url,
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2020-06-23 00:09:42 +05:30
|
|
|
.then(() => dispatch('receiveSaveChangesSuccess'))
|
2021-03-08 18:12:59 +05:30
|
|
|
.catch((error) => dispatch('receiveSaveChangesError', error));
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
export const receiveSaveChangesSuccess = () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
/**
|
|
|
|
* The operations_controller currently handles successful requests
|
|
|
|
* by creating a flash banner messsage to notify the user.
|
|
|
|
*/
|
|
|
|
refreshCurrentPage();
|
|
|
|
};
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
export const receiveSaveChangesError = (_, error) => {
|
|
|
|
const { response = {} } = error;
|
2019-09-04 21:01:54 +05:30
|
|
|
const message = response.data && response.data.message ? response.data.message : '';
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-04 01:27:46 +05:30
|
|
|
message: `${__('There was an error saving your changes.')} ${message}`,
|
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
};
|