From 31e2ad6e0b6750816bd78c76f605526058574ac4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 8 Jan 2022 02:52:42 +0100 Subject: [PATCH] Port report destroy functionality to TypeScript --- .../features/moderation/destroy.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/javascript/retrospring/features/moderation/destroy.ts diff --git a/app/javascript/retrospring/features/moderation/destroy.ts b/app/javascript/retrospring/features/moderation/destroy.ts new file mode 100644 index 00000000..0cd3cddb --- /dev/null +++ b/app/javascript/retrospring/features/moderation/destroy.ts @@ -0,0 +1,39 @@ +import Rails from '@rails/ujs'; +import swal from 'sweetalert'; + +import I18n from '../../../legacy/i18n'; +import { showNotification, showErrorNotification } from 'utilities/notifications'; + +export function destroyReportHandler(event: Event): void { + const button = event.target as HTMLButtonElement; + const id = button.dataset.id; + + swal({ + title: I18n.translate('frontend.destroy_report.confirm.title'), + text: I18n.translate('frontend.destroy_report.confirm.text'), + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: I18n.translate('views.actions.delete'), + cancelButtonText: I18n.translate('views.actions.cancel'), + closeOnConfirm: true + }, () => { + Rails.ajax({ + url: '/ajax/mod/destroy_report', + type: 'POST', + data: new URLSearchParams({ + id: id + }).toString(), + success: (data) => { + if (data.success) { + document.querySelector(`.moderationbox[data-id="${id}"]`).remove(); + } + showNotification(data.message, data.success); + }, + error: (data, status, xhr) => { + console.log(data, status, xhr); + showErrorNotification(I18n.translate('frontend.error.message')); + } + }); + }); +} \ No newline at end of file