diff --git a/app/javascript/retrospring/features/questionbox/user.ts b/app/javascript/retrospring/features/questionbox/user.ts index 68d7170e..127f0295 100644 --- a/app/javascript/retrospring/features/questionbox/user.ts +++ b/app/javascript/retrospring/features/questionbox/user.ts @@ -1,4 +1,4 @@ -import Rails from '@rails/ujs'; +import { post } from '@rails/request.js'; import { showErrorNotification, showNotification } from 'utilities/notifications'; import I18n from 'retrospring/i18n'; @@ -15,15 +15,17 @@ export function questionboxUserHandler(event: Event): void { document.querySelector('textarea[name=qb-question]').readOnly = true; button.disabled = true; - Rails.ajax({ - url: '/ajax/ask', - type: 'POST', - data: new URLSearchParams({ + post('/ajax/ask', { + body: { rcpt: document.querySelector('input[name=qb-to]').value, question: document.querySelector('textarea[name=qb-question]').value, - anonymousQuestion: String(anonymousQuestion) - }).toString(), - success: (data) => { + anonymousQuestion: String(anonymousQuestion) + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + if (data.success) { document.querySelector('textarea[name=qb-question]').value = ''; @@ -37,16 +39,15 @@ export function questionboxUserHandler(event: Event): void { } 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')); - }, - complete: () => { + }) + .finally(() => { document.querySelector('textarea[name=qb-question]').readOnly = false; button.disabled = false; - } - }); + }); } export function questionboxPromoteHandler(): void {