diff --git a/app/javascript/retrospring/features/answerbox/comment/destroy.ts b/app/javascript/retrospring/features/answerbox/comment/destroy.ts index d6147193..36c29842 100644 --- a/app/javascript/retrospring/features/answerbox/comment/destroy.ts +++ b/app/javascript/retrospring/features/answerbox/comment/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'; @@ -25,24 +25,23 @@ export function commentDestroyHandler(event: Event): void { return; } - Rails.ajax({ - url: '/ajax/destroy_comment', - type: 'POST', - data: new URLSearchParams({ + post('/ajax/destroy_comment', { + body: { comment: id - }).toString(), - success: (data) => { - if (!data.success) return false; + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; showNotification(data.message); document.querySelector(`[data-comment-id="${id}"]`).remove(); - }, - error: (data, status, xhr) => { - console.log(data, status, xhr); + }) + .catch(err => { + console.log(err); showErrorNotification(I18n.translate('frontend.error.message')); button.disabled = false; - } - }); + }); }); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/answerbox/comment/new.ts b/app/javascript/retrospring/features/answerbox/comment/new.ts index 1dca489b..6f729165 100644 --- a/app/javascript/retrospring/features/answerbox/comment/new.ts +++ b/app/javascript/retrospring/features/answerbox/comment/new.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'; @@ -19,14 +19,16 @@ export function commentCreateHandler(event: KeyboardEvent): boolean { input.disabled = true; - Rails.ajax({ - url: '/ajax/create_comment', - type: 'POST', - data: new URLSearchParams({ + post('/ajax/create_comment', { + body: { answer: id, comment: input.value - }).toString(), - success: (data) => { + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + if (data.success) { document.querySelector(`#ab-comments-${id}`).innerHTML = data.render; document.querySelector(`#ab-comment-count-${id}`).innerHTML = data.count; @@ -39,14 +41,13 @@ export function commentCreateHandler(event: KeyboardEvent): boolean { } 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(() => { input.disabled = false; - } - }); + }); } } \ No newline at end of file diff --git a/app/javascript/retrospring/features/answerbox/comment/smile.ts b/app/javascript/retrospring/features/answerbox/comment/smile.ts index f78c8747..b80d5bd5 100644 --- a/app/javascript/retrospring/features/answerbox/comment/smile.ts +++ b/app/javascript/retrospring/features/answerbox/comment/smile.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'; @@ -22,25 +22,27 @@ export function commentSmileHandler(event: Event): void { button.disabled = true; - Rails.ajax({ - url: targetUrl, - type: 'POST', - data: new URLSearchParams({ + post(targetUrl, { + body: { id: id - }).toString(), - success: (data) => { + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + success = data.success; if (success) { document.querySelector(`#ab-comment-smile-count-${id}`).innerHTML = String(count); } 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(() => { button.disabled = false; if (success) { @@ -53,6 +55,5 @@ export function commentSmileHandler(event: Event): void { break; } } - } - }); + }); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/answerbox/destroy.ts b/app/javascript/retrospring/features/answerbox/destroy.ts index 4baaa39d..0d244cf0 100644 --- a/app/javascript/retrospring/features/answerbox/destroy.ts +++ b/app/javascript/retrospring/features/answerbox/destroy.ts @@ -1,4 +1,4 @@ -import Rails from '@rails/ujs'; +import { post } from '@rails/request.js'; import { showErrorNotification, showNotification } from 'utilities/notifications'; import swal from 'sweetalert'; @@ -23,24 +23,25 @@ export function answerboxDestroyHandler(event: Event): void { button.disabled = false; return; } - - Rails.ajax({ - url: '/ajax/destroy_answer', - type: 'POST', - data: new URLSearchParams({ + + post('/ajax/destroy_answer', { + body: { answer: answerId - }).toString(), - success: (data) => { + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + if (data.success) { document.querySelector(`.answerbox[data-id="${answerId}"]`).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/answerbox/smile.ts b/app/javascript/retrospring/features/answerbox/smile.ts index 9f49144f..fc154b0d 100644 --- a/app/javascript/retrospring/features/answerbox/smile.ts +++ b/app/javascript/retrospring/features/answerbox/smile.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'; @@ -22,25 +22,27 @@ export function answerboxSmileHandler(event: Event): void { button.disabled = true; - Rails.ajax({ - url: targetUrl, - type: 'POST', - data: new URLSearchParams({ + post(targetUrl, { + body: { id: id - }).toString(), - success: (data) => { + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + success = data.success; if (success) { document.querySelector(`#ab-smile-count-${id}`).innerHTML = String(count); } 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(() => { button.disabled = false; if (success) { @@ -53,6 +55,5 @@ export function answerboxSmileHandler(event: Event): void { break; } } - } - }); + }); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/answerbox/subscribe.ts b/app/javascript/retrospring/features/answerbox/subscribe.ts index 0229cc9a..977d410e 100644 --- a/app/javascript/retrospring/features/answerbox/subscribe.ts +++ b/app/javascript/retrospring/features/answerbox/subscribe.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'; @@ -20,13 +20,15 @@ export function answerboxSubscribeHandler(event: Event): void { targetUrl = '/ajax/unsubscribe'; } - Rails.ajax({ - url: targetUrl, - type: 'POST', - data: new URLSearchParams({ + post(targetUrl, { + body: { answer: id - }).toString(), - success: (data) => { + }, + contentType: 'application/json' + }) + .then(async response => { + const data = await response.json; + if (data.success) { button.dataset.torpedo = ["yes", "no"][torpedo]; button.children[0].nextSibling.textContent = ' ' + (torpedo ? I18n.translate('voc.unsubscribe') : I18n.translate('voc.subscribe')); @@ -34,10 +36,9 @@ export function answerboxSubscribeHandler(event: Event): void { } else { showErrorNotification(I18n.translate(`frontend.subscription.fail.${torpedo ? 'subscribe' : 'unsubscribe'}`)); } - }, - 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/settings/mute.ts b/app/javascript/retrospring/features/settings/mute.ts index 8456c49d..91fbfe5e 100644 --- a/app/javascript/retrospring/features/settings/mute.ts +++ b/app/javascript/retrospring/features/settings/mute.ts @@ -1,4 +1,3 @@ -import Rails from '@rails/ujs'; import { destroy, post } from '@rails/request.js'; function createSubmitEvent(