mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:29:53 +01:00
Refactor anon blocking to use request.js
This commit is contained in:
parent
a893d11aa1
commit
969f7e80f8
1 changed files with 18 additions and 17 deletions
|
@ -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 a new issue