Refactor list removal to use request.js

This commit is contained in:
Andreas Nedbal 2022-09-03 07:50:33 +02:00
parent af0258c8aa
commit 41fea7fd5e
1 changed files with 13 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import Rails from '@rails/ujs'; import { post } from '@rails/request.js';
import swal from 'sweetalert'; import swal from 'sweetalert';
import { showNotification, showErrorNotification } from 'utilities/notifications'; import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from 'retrospring/i18n'; import I18n from 'retrospring/i18n';
@ -18,13 +18,15 @@ export function destroyListHandler(event: Event): void {
cancelButtonText: I18n.translate('voc.cancel'), cancelButtonText: I18n.translate('voc.cancel'),
closeOnConfirm: true closeOnConfirm: true
}, () => { }, () => {
Rails.ajax({ post('/ajax/destroy_list', {
url: '/ajax/destroy_list', body: {
type: 'POST',
data: new URLSearchParams({
list: list list: list
}).toString(), },
success: (data) => { contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
if (data.success) { if (data.success) {
const element = document.querySelector(`li.list-group-item#list-${list}`); const element = document.querySelector(`li.list-group-item#list-${list}`);
@ -34,11 +36,10 @@ export function destroyListHandler(event: Event): void {
} }
showNotification(data.message, data.success); showNotification(data.message, data.success);
}, })
error: (data, status, xhr) => { .catch(err => {
console.log(data, status, xhr); console.log(err);
showErrorNotification(I18n.translate('frontend.error.message')); showErrorNotification(I18n.translate('frontend.error.message'));
}
}); });
}); });
} }