Refactor global anon blocks to use request.js
This commit is contained in:
parent
6639519905
commit
389e1271d7
|
@ -1,46 +1,47 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
|
|
||||||
import { showErrorNotification, showNotification } from "utilities/notifications";
|
import { showErrorNotification, showNotification } from "utilities/notifications";
|
||||||
import I18n from "retrospring/i18n";
|
import I18n from "retrospring/i18n";
|
||||||
|
|
||||||
export function blockAnonEventHandler(event: Event): void {
|
export function blockAnonEventHandler(event: Event): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
swal({
|
swal({
|
||||||
title: I18n.translate('frontend.mod_mute.confirm.title'),
|
title: I18n.translate('frontend.mod_mute.confirm.title'),
|
||||||
text: I18n.translate('frontend.mod_mute.confirm.text'),
|
text: I18n.translate('frontend.mod_mute.confirm.text'),
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonColor: "#DD6B55",
|
confirmButtonColor: "#DD6B55",
|
||||||
confirmButtonText: I18n.translate('voc.y'),
|
confirmButtonText: I18n.translate('voc.y'),
|
||||||
cancelButtonText: I18n.translate('voc.n'),
|
cancelButtonText: I18n.translate('voc.n'),
|
||||||
closeOnConfirm: true,
|
closeOnConfirm: true,
|
||||||
}, (dialogResult) => {
|
}, (dialogResult) => {
|
||||||
if (!dialogResult) {
|
if (!dialogResult) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sender: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
const sender: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
question: sender.getAttribute('data-q-id'),
|
question: sender.getAttribute('data-q-id'),
|
||||||
global: 'true'
|
global: 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
showNotification(data.message);
|
if (!data.success) return false;
|
||||||
},
|
|
||||||
error: (data, status, xhr) => {
|
showNotification(data.message);
|
||||||
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