Refactor anon blocking to use request.js
This commit is contained in:
parent
a893d11aa1
commit
969f7e80f8
|
@ -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";
|
||||||
|
@ -7,24 +7,25 @@ export function blockAnonEventHandler(event: Event): void {
|
||||||
const element: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
const element: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
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 => {
|
||||||
if (!data.success) return false;
|
const data = await response.json;
|
||||||
const inboxEntry: Node = element.closest('.inbox-entry');
|
|
||||||
|
|
||||||
showNotification(data.message);
|
if (!data.success) return false;
|
||||||
|
const inboxEntry: Node = element.closest('.inbox-entry');
|
||||||
|
|
||||||
(inboxEntry as HTMLElement).remove();
|
showNotification(data.message);
|
||||||
},
|
|
||||||
error: (data, status, xhr) => {
|
(inboxEntry as HTMLElement).remove();
|
||||||
console.log(data, status, xhr);
|
})
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
.catch(err => {
|
||||||
}
|
console.log(err);
|
||||||
});
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue