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 I18n from 'retrospring/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications'; import { showNotification, showErrorNotification } from 'utilities/notifications';
@ -44,16 +44,17 @@ export function banFormHandler(event: Event): void {
} }
} }
Rails.ajax({ post('/ajax/mod/ban', {
url: '/ajax/mod/ban', body: data,
type: 'POST', contentType: 'application/json'
data: new URLSearchParams(data).toString(), })
success: (data) => { .then(async response => {
const data = await response.json;
showNotification(data.message, data.success); showNotification(data.message, data.success);
}, })
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'));
} });
});
} }