2022-09-02 21:57:32 -07:00
|
|
|
import { post } from '@rails/request.js';
|
2022-06-14 14:16:55 -07:00
|
|
|
|
|
|
|
import { showErrorNotification, showNotification } from "utilities/notifications";
|
|
|
|
import I18n from "retrospring/i18n";
|
|
|
|
|
|
|
|
export function blockAnonEventHandler(event: Event): void {
|
|
|
|
const element: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
|
|
|
|
|
|
|
const data = {
|
2022-09-02 21:57:32 -07:00
|
|
|
question: element.getAttribute('data-q-id'),
|
2022-06-14 14:16:55 -07:00
|
|
|
};
|
|
|
|
|
2022-09-02 21:57:32 -07:00
|
|
|
post('/ajax/block_anon', {
|
|
|
|
body: data,
|
|
|
|
contentType: 'application/json'
|
|
|
|
})
|
|
|
|
.then(async response => {
|
|
|
|
const data = await response.json;
|
2022-06-14 14:16:55 -07:00
|
|
|
|
2022-09-02 21:57:32 -07:00
|
|
|
if (!data.success) return false;
|
|
|
|
const inboxEntry: Node = element.closest('.inbox-entry');
|
2022-06-14 14:16:55 -07:00
|
|
|
|
2022-09-02 21:57:32 -07:00
|
|
|
showNotification(data.message);
|
|
|
|
|
|
|
|
(inboxEntry as HTMLElement).remove();
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
|
|
|
});
|
2022-06-14 14:16:55 -07:00
|
|
|
}
|