2022-01-02 18:26:28 -08:00
|
|
|
import Rails from '@rails/ujs';
|
|
|
|
import swal from 'sweetalert';
|
|
|
|
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-02 18:26:28 -08:00
|
|
|
import { updateDeleteButton } from '../delete';
|
|
|
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
|
|
|
|
|
|
|
export function deleteEntryHandler(event: Event): void {
|
|
|
|
const element: HTMLButtonElement = event.target as HTMLButtonElement;
|
2022-01-03 06:04:09 -08:00
|
|
|
element.disabled = true;
|
2022-01-02 18:26:28 -08:00
|
|
|
|
|
|
|
const data = {
|
|
|
|
id: element.getAttribute('data-ib-id')
|
|
|
|
};
|
|
|
|
|
|
|
|
swal({
|
2022-01-02 19:36:45 -08:00
|
|
|
title: I18n.translate('frontend.inbox.confirm.title'),
|
|
|
|
text: I18n.translate('frontend.inbox.confirm.text'),
|
2022-01-02 18:26:28 -08:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: "#DD6B55",
|
|
|
|
confirmButtonText: I18n.translate('views.actions.delete'),
|
|
|
|
cancelButtonText: I18n.translate('views.actions.cancel'),
|
|
|
|
closeOnConfirm: true
|
|
|
|
}, (returnValue) => {
|
2022-01-03 06:04:09 -08:00
|
|
|
if (returnValue === false) {
|
|
|
|
element.disabled = false;
|
|
|
|
return;
|
|
|
|
}
|
2022-01-02 18:26:28 -08:00
|
|
|
|
|
|
|
Rails.ajax({
|
|
|
|
url: '/ajax/delete_inbox',
|
|
|
|
type: 'POST',
|
|
|
|
data: new URLSearchParams(data).toString(),
|
|
|
|
success: (data) => {
|
|
|
|
if (!data.success) return false;
|
|
|
|
const inboxEntry: Node = element.closest('.inbox-entry');
|
|
|
|
|
|
|
|
updateDeleteButton(false);
|
|
|
|
showNotification(data.message);
|
|
|
|
|
|
|
|
(inboxEntry as HTMLElement).remove();
|
|
|
|
},
|
|
|
|
error: (data, status, xhr) => {
|
|
|
|
console.log(data, status, xhr);
|
2022-01-02 19:36:45 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2022-01-02 18:26:28 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|