Merge pull request #660 from Retrospring/feature/request-js-moderation
Refactor moderation TS functionality to use `@rails/request.js`
This commit is contained in:
commit
67546ec857
|
@ -59,7 +59,7 @@ class Ajax::ModerationController < AjaxController
|
|||
raise Errors::InvalidBanDuration unless %w[hours days weeks months].include? duration_unit
|
||||
|
||||
expiry = DateTime.now + duration.public_send(duration_unit)
|
||||
@response[:message] = I18n.t(".success.temporary", date: expiry.to_s)
|
||||
@response[:message] = t(".success.temporary", date: expiry.to_s)
|
||||
end
|
||||
|
||||
UseCase::User::Ban.call(
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import { post } from '@rails/request.js';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import { showErrorNotification, showNotification } from "utilities/notifications";
|
||||
|
@ -28,19 +28,20 @@ export function blockAnonEventHandler(event: Event): void {
|
|||
global: 'true'
|
||||
};
|
||||
|
||||
Rails.ajax({
|
||||
url: '/ajax/block_anon',
|
||||
type: 'POST',
|
||||
data: new URLSearchParams(data).toString(),
|
||||
success: (data) => {
|
||||
post('/ajax/block_anon', {
|
||||
body: data,
|
||||
contentType: 'application/json'
|
||||
})
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (!data.success) return false;
|
||||
|
||||
showNotification(data.message);
|
||||
},
|
||||
error: (data, status, xhr) => {
|
||||
console.log(data, status, xhr);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import { post } from '@rails/request.js';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import I18n from 'retrospring/i18n';
|
||||
|
@ -18,22 +18,24 @@ export function destroyReportHandler(event: Event): void {
|
|||
cancelButtonText: I18n.translate('voc.cancel'),
|
||||
closeOnConfirm: true
|
||||
}, () => {
|
||||
Rails.ajax({
|
||||
url: '/ajax/mod/destroy_report',
|
||||
type: 'POST',
|
||||
data: new URLSearchParams({
|
||||
post('/ajax/mod/destroy_report', {
|
||||
body: {
|
||||
id: id
|
||||
}).toString(),
|
||||
success: (data) => {
|
||||
},
|
||||
contentType: 'application/json'
|
||||
})
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (data.success) {
|
||||
document.querySelector(`.moderationbox[data-id="${id}"]`).remove();
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -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';
|
||||
|
@ -9,29 +9,29 @@ export function privilegeCheckHandler(event: Event): void {
|
|||
|
||||
const privilegeType = checkbox.dataset.type;
|
||||
|
||||
Rails.ajax({
|
||||
url: '/ajax/mod/privilege',
|
||||
type: 'POST',
|
||||
data: new URLSearchParams({
|
||||
post('/ajax/mod/privilege', {
|
||||
body: {
|
||||
user: checkbox.dataset.user,
|
||||
type: privilegeType,
|
||||
status: String(checkbox.checked)
|
||||
}).toString(),
|
||||
success: (data) => {
|
||||
},
|
||||
contentType: 'application/json'
|
||||
})
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (data.success) {
|
||||
checkbox.checked = data.checked;
|
||||
}
|
||||
|
||||
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'));
|
||||
checkbox.checked = false;
|
||||
},
|
||||
complete: () => {
|
||||
})
|
||||
.finally(() => {
|
||||
checkbox.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
Loading…
Reference in New Issue