mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:19:52 +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";
|
||||||
|
@ -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'));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in a new issue