Refactor user banning to use request.js

This commit is contained in:
Andreas Nedbal 2022-09-03 08:42:17 +02:00
parent eb0271210b
commit 6639519905
1 changed files with 12 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import Rails from '@rails/ujs';
import { post } from '@rails/request.js';
import I18n from 'retrospring/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications';
@ -44,16 +44,17 @@ export function banFormHandler(event: Event): void {
}
}
Rails.ajax({
url: '/ajax/mod/ban',
type: 'POST',
data: new URLSearchParams(data).toString(),
success: (data) => {
post('/ajax/mod/ban', {
body: data,
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
showNotification(data.message, data.success);
},
error: (data, status, xhr) => {
console.log(data, status, xhr);
})
.catch(err => {
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
}
});
});
}