Refactor inbox entry deleting to use request.js

This commit is contained in:
Andreas Nedbal 2022-09-03 06:57:52 +02:00
parent 969f7e80f8
commit 90f33dd76c
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 I18n from 'retrospring/i18n'; import I18n from 'retrospring/i18n';
@ -28,11 +28,13 @@ export function deleteEntryHandler(event: Event): void {
return; return;
} }
Rails.ajax({ post('/ajax/delete_inbox', {
url: '/ajax/delete_inbox', body: data,
type: 'POST', contentType: 'application/json'
data: new URLSearchParams(data).toString(), })
success: (data) => { .then(async response => {
const data = await response.json;
if (!data.success) return false; if (!data.success) return false;
const inboxEntry: Node = element.closest('.inbox-entry'); const inboxEntry: Node = element.closest('.inbox-entry');
@ -40,11 +42,10 @@ export function deleteEntryHandler(event: Event): void {
showNotification(data.message); showNotification(data.message);
(inboxEntry as HTMLElement).remove(); (inboxEntry as HTMLElement).remove();
}, })
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'));
} });
});
}) })
} }