From 7fa548b6136bea0a64ead75cfd1e045f84a3ee09 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 3 Jan 2023 14:59:53 +0100 Subject: [PATCH] Remove use of @rails/ujs in report dialog handler --- .../retrospring/utilities/reportDialog.ts | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/javascript/retrospring/utilities/reportDialog.ts b/app/javascript/retrospring/utilities/reportDialog.ts index c0c9ba04..771513de 100644 --- a/app/javascript/retrospring/utilities/reportDialog.ts +++ b/app/javascript/retrospring/utilities/reportDialog.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'; @@ -19,22 +19,20 @@ export function reportDialog(type: string, target: string): void { if (returnValue === false) { return; } - - Rails.ajax({ - url: '/ajax/report', - type: 'POST', - data: new URLSearchParams({ + + post('/ajax/report', { + body: { id: String(target), type: type, reason: returnValue - }).toString(), - success: (data) => { - showNotification(data.message); - }, - error: (data, status, xhr) => { - console.log(data, status, xhr); - showErrorNotification(I18n.translate('frontend.error.message')); } + }).then(async response => { + const data = await response.json; + + showNotification(data.message, data.success); + }).catch(e => { + console.error("Failed to submit report", e); + showErrorNotification(I18n.translate('frontend.error.message')); }); }); -} \ No newline at end of file +}