mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 12:39:53 +01:00
Refactor global anon blocks to use request.js
This commit is contained in:
parent
6639519905
commit
389e1271d7
1 changed files with 36 additions and 35 deletions
|
@ -1,46 +1,47 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import { post } from '@rails/request.js';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import { showErrorNotification, showNotification } from "utilities/notifications";
|
||||
import I18n from "retrospring/i18n";
|
||||
|
||||
export function blockAnonEventHandler(event: Event): void {
|
||||
event.preventDefault();
|
||||
|
||||
swal({
|
||||
title: I18n.translate('frontend.mod_mute.confirm.title'),
|
||||
text: I18n.translate('frontend.mod_mute.confirm.text'),
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: I18n.translate('voc.y'),
|
||||
cancelButtonText: I18n.translate('voc.n'),
|
||||
closeOnConfirm: true,
|
||||
}, (dialogResult) => {
|
||||
if (!dialogResult) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
|
||||
swal({
|
||||
title: I18n.translate('frontend.mod_mute.confirm.title'),
|
||||
text: I18n.translate('frontend.mod_mute.confirm.text'),
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: I18n.translate('voc.y'),
|
||||
cancelButtonText: I18n.translate('voc.n'),
|
||||
closeOnConfirm: true,
|
||||
}, (dialogResult) => {
|
||||
if (!dialogResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sender: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
||||
const sender: HTMLAnchorElement = event.target as HTMLAnchorElement;
|
||||
|
||||
const data = {
|
||||
question: sender.getAttribute('data-q-id'),
|
||||
global: 'true'
|
||||
};
|
||||
const data = {
|
||||
question: sender.getAttribute('data-q-id'),
|
||||
global: 'true'
|
||||
};
|
||||
|
||||
Rails.ajax({
|
||||
url: '/ajax/block_anon',
|
||||
type: 'POST',
|
||||
data: new URLSearchParams(data).toString(),
|
||||
success: (data) => {
|
||||
if (!data.success) return false;
|
||||
post('/ajax/block_anon', {
|
||||
body: data,
|
||||
contentType: 'application/json'
|
||||
})
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
showNotification(data.message);
|
||||
},
|
||||
error: (data, status, xhr) => {
|
||||
console.log(data, status, xhr);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!data.success) return false;
|
||||
|
||||
showNotification(data.message);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue