Convert merge_conflict_service.js to axios

This commit is contained in:
Phil Hughes 2018-01-30 16:47:19 +00:00
parent 05a3479c9e
commit 8750507b5d
No known key found for this signature in database
GPG Key ID: 32245528C52E0F9F
2 changed files with 11 additions and 21 deletions

View File

@ -1,4 +1,5 @@
/* eslint-disable no-param-reassign, comma-dangle */
import axios from '../lib/utils/axios_utils';
((global) => {
global.mergeConflicts = global.mergeConflicts || {};
@ -10,20 +11,11 @@
}
fetchConflictsData() {
return $.ajax({
dataType: 'json',
url: this.conflictsPath
});
return axios.get(this.conflictsPath);
}
submitResolveConflicts(data) {
return $.ajax({
url: this.resolveConflictsPath,
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
method: 'POST'
});
return axios.post(this.resolveConflictsPath, data);
}
}

View File

@ -38,24 +38,22 @@ $(() => {
showDiffViewTypeSwitcher() { return mergeConflictsStore.fileTextTypePresent(); }
},
created() {
mergeConflictsService
.fetchConflictsData()
.done((data) => {
mergeConflictsService.fetchConflictsData()
.then(({ data }) => {
if (data.type === 'error') {
mergeConflictsStore.setFailedRequest(data.message);
} else {
mergeConflictsStore.setConflictsData(data);
}
})
.error(() => {
mergeConflictsStore.setFailedRequest();
})
.always(() => {
mergeConflictsStore.setLoadingState(false);
this.$nextTick(() => {
syntaxHighlight($('.js-syntax-highlight'));
});
})
.catch(() => {
mergeConflictsStore.setFailedRequest();
});
},
methods: {
@ -82,10 +80,10 @@ $(() => {
mergeConflictsService
.submitResolveConflicts(mergeConflictsStore.getCommitData())
.done((data) => {
.then(({ data }) => {
window.location.href = data.redirect_to;
})
.error(() => {
.catch(() => {
mergeConflictsStore.setSubmitState(false);
new Flash('Failed to save merge conflicts resolutions. Please try again!');
});