debian-mirror-gitlab/app/assets/javascripts/integrations/edit/store/actions.js

44 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import {
VALIDATE_INTEGRATION_FORM_EVENT,
I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE,
I18N_DEFAULT_ERROR_MESSAGE,
} from '~/integrations/constants';
import { testIntegrationSettings } from '../api';
import eventHub from '../event_hub';
2020-07-28 23:09:34 +05:30
import * as types from './mutation_types';
export const setOverride = ({ commit }, override) => commit(types.SET_OVERRIDE, override);
2021-03-11 19:13:27 +05:30
2022-01-26 12:08:38 +05:30
export const requestJiraIssueTypes = ({ commit, dispatch, getters }, formData) => {
2021-03-11 19:13:27 +05:30
commit(types.SET_JIRA_ISSUE_TYPES_ERROR_MESSAGE, '');
commit(types.SET_IS_LOADING_JIRA_ISSUE_TYPES, true);
2022-01-26 12:08:38 +05:30
return testIntegrationSettings(getters.propsSource.testPath, formData)
.then(
({
data: { issuetypes, error, message = I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE },
}) => {
if (error || !issuetypes?.length) {
eventHub.$emit(VALIDATE_INTEGRATION_FORM_EVENT);
throw new Error(message);
}
dispatch('receiveJiraIssueTypesSuccess', issuetypes);
},
)
.catch(({ message = I18N_DEFAULT_ERROR_MESSAGE }) => {
dispatch('receiveJiraIssueTypesError', message);
});
2021-03-11 19:13:27 +05:30
};
2022-01-26 12:08:38 +05:30
2021-03-11 19:13:27 +05:30
export const receiveJiraIssueTypesSuccess = ({ commit }, issueTypes = []) => {
commit(types.SET_IS_LOADING_JIRA_ISSUE_TYPES, false);
commit(types.SET_JIRA_ISSUE_TYPES, issueTypes);
};
export const receiveJiraIssueTypesError = ({ commit }, errorMessage) => {
commit(types.SET_IS_LOADING_JIRA_ISSUE_TYPES, false);
commit(types.SET_JIRA_ISSUE_TYPES, []);
commit(types.SET_JIRA_ISSUE_TYPES_ERROR_MESSAGE, errorMessage);
};