Refactor anon blocking to use request.js

This commit is contained in:
Andreas Nedbal 2022-09-03 06:57:32 +02:00
parent a893d11aa1
commit 969f7e80f8

View file

@ -1,4 +1,4 @@
import Rails from '@rails/ujs'; import { post } from '@rails/request.js';
import { showErrorNotification, showNotification } from "utilities/notifications"; import { showErrorNotification, showNotification } from "utilities/notifications";
import I18n from "retrospring/i18n"; import I18n from "retrospring/i18n";
@ -10,21 +10,22 @@ export function blockAnonEventHandler(event: Event): void {
question: element.getAttribute('data-q-id'), question: element.getAttribute('data-q-id'),
}; };
Rails.ajax({ post('/ajax/block_anon', {
url: '/ajax/block_anon', body: data,
type: 'POST', contentType: 'application/json'
data: new URLSearchParams(data).toString(), })
success: (data) => { .then(async response => {
const data = await response.json;
if (!data.success) return false; if (!data.success) return false;
const inboxEntry: Node = element.closest('.inbox-entry'); const inboxEntry: Node = element.closest('.inbox-entry');
showNotification(data.message); showNotification(data.message);
(inboxEntry as HTMLElement).remove(); (inboxEntry as HTMLElement).remove();
}, })
error: (data, status, xhr) => { .catch(err => {
console.log(data, status, xhr); console.log(err);
showErrorNotification(I18n.translate('frontend.error.message')); showErrorNotification(I18n.translate('frontend.error.message'));
}
}); });
} }