Retrospring/app/javascript/retrospring/features/inbox/entry/delete.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.4 KiB
TypeScript
Raw Normal View History

import { post } from '@rails/request.js';
import swal from 'sweetalert';
import I18n from 'retrospring/i18n';
import { updateDeleteButton } from '../delete';
import { showNotification, showErrorNotification } from 'utilities/notifications';
export function deleteEntryHandler(event: Event): void {
const element: HTMLButtonElement = event.target as HTMLButtonElement;
const data = {
id: element.getAttribute('data-ib-id')
};
swal({
title: I18n.translate('frontend.inbox.confirm.title'),
text: I18n.translate('frontend.inbox.confirm.text'),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
2022-07-30 09:50:46 -07:00
confirmButtonText: I18n.translate('voc.delete'),
cancelButtonText: I18n.translate('voc.cancel'),
closeOnConfirm: true
2023-11-06 15:58:21 -08:00
}, () => {
element.disabled = true;
post('/ajax/delete_inbox', {
body: data,
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
if (!data.success) return false;
const inboxEntry: Node = element.closest('.inbox-entry');
updateDeleteButton(false);
showNotification(data.message);
(inboxEntry as HTMLElement).remove();
})
.catch(err => {
2023-11-06 15:58:21 -08:00
element.disabled = false;
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
});
})
}