From fe6b6b198ff51764d63b6a67e025c163882381a5 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 3 Sep 2022 08:42:55 +0200 Subject: [PATCH] Refactor report removal to use request.js --- .../features/moderation/destroy.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/javascript/retrospring/features/moderation/destroy.ts b/app/javascript/retrospring/features/moderation/destroy.ts index 765f2387..77c1376e 100644 --- a/app/javascript/retrospring/features/moderation/destroy.ts +++ b/app/javascript/retrospring/features/moderation/destroy.ts @@ -1,4 +1,4 @@ -import Rails from '@rails/ujs'; +import { post } from '@rails/request.js'; import swal from 'sweetalert'; import I18n from 'retrospring/i18n'; @@ -18,22 +18,24 @@ export function destroyReportHandler(event: Event): void { cancelButtonText: I18n.translate('voc.cancel'), closeOnConfirm: true }, () => { - Rails.ajax({ - url: '/ajax/mod/destroy_report', - type: 'POST', - data: new URLSearchParams({ + post('/ajax/mod/destroy_report', { + body: { id: id - }).toString(), - success: (data) => { + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + if (data.success) { document.querySelector(`.moderationbox[data-id="${id}"]`).remove(); } + showNotification(data.message, data.success); - }, - error: (data, status, xhr) => { - console.log(data, status, xhr); + }) + .catch(err => { + console.log(err); showErrorNotification(I18n.translate('frontend.error.message')); - } - }); + }); }); } \ No newline at end of file