Merge branch 'bulk-download-invoices' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into staging

This commit is contained in:
edmondlang
2023-10-12 18:11:24 +08:00
4 changed files with 144 additions and 41 deletions
@@ -91,7 +91,11 @@
},
successHandler(response) {
this.isLoading = false;
this.returnData = response;
if (response.message) {
this.returnData = response;
} else {
this.returnData = null;
}
},
hasMarkingParameter() {
const urlSearchParams = new URLSearchParams(window.location.search);
+29 -9
View File
@@ -13,19 +13,39 @@ export default {
let statusCode = response.status,
success = response.ok;
response.json().then(response => {
if (response.headers.get("content-type") === "application/zip") {
const fileName = response.headers.get('Content-Disposition').split('filename=')[1];
if(!success){
this.openModal();
errorNotification ? this.$store.dispatch('createNotification', {title: response.title, message: response.message, type: 'error'}): null;
this.errorHandler(response, statusCode); return;
}
response.blob().then(response => {
if (!success) {
this.openModal();
errorNotification ? this.$store.dispatch('createNotification', { title: response.title, message: response.message, type: 'error' }) : null;
this.errorHandler(response, statusCode); return;
}
successNotification ? this.$store.dispatch('createNotification', {title: response.title, message: response.message, type: 'success'}): null;
this.successHandler(response)
successNotification ? this.$store.dispatch('createNotification', { title: response.title, message: response.message, type: 'success' }) : null;
const link = document.createElement('a');
link.href = window.URL.createObjectURL(response);
link.download = fileName;
link.click();
this.successHandler(response)
});
} else {
response.json().then(response => {
if (!success) {
this.openModal();
errorNotification ? this.$store.dispatch('createNotification', { title: response.title, message: response.message, type: 'error' }) : null;
this.errorHandler(response, statusCode); return;
}
successNotification ? this.$store.dispatch('createNotification', { title: response.title, message: response.message, type: 'success' }) : null;
this.successHandler(response)
});
});
}
}).catch((error) => {
console.log(error);
this.$store.dispatch('createNotification', {title: 'Unexpected Error', message: 'An unexpected error has occurred. Try again!', type: 'error'});