diff --git a/app/controllers/ajax/moderation_controller.rb b/app/controllers/ajax/moderation_controller.rb index dc34405b..3c1fe669 100644 --- a/app/controllers/ajax/moderation_controller.rb +++ b/app/controllers/ajax/moderation_controller.rb @@ -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( diff --git a/app/javascript/retrospring/features/moderation/ban.ts b/app/javascript/retrospring/features/moderation/ban.ts index 41449ceb..d286dac4 100644 --- a/app/javascript/retrospring/features/moderation/ban.ts +++ b/app/javascript/retrospring/features/moderation/ban.ts @@ -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')); - } - }); + }); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/moderation/blockAnon.ts b/app/javascript/retrospring/features/moderation/blockAnon.ts index 5c587300..4f04004c 100644 --- a/app/javascript/retrospring/features/moderation/blockAnon.ts +++ b/app/javascript/retrospring/features/moderation/blockAnon.ts @@ -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')); + }); + }); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/moderation/destroy.ts b/app/javascript/retrospring/features/moderation/destroy.ts index 765f2387..77c1376e 100644 --- a/app/javascript/retrospring/features/moderation/destroy.ts +++ b/app/javascript/retrospring/features/moderation/destroy.ts @@ -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')); - } - }); + }); }); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/moderation/privilege.ts b/app/javascript/retrospring/features/moderation/privilege.ts index 6446da88..07b0d822 100644 --- a/app/javascript/retrospring/features/moderation/privilege.ts +++ b/app/javascript/retrospring/features/moderation/privilege.ts @@ -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; - } - }); - + }); } \ No newline at end of file