From 3b6ade483f8cdb2d39be0bbfd70e7844220b25c7 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 3 Sep 2022 06:58:08 +0200 Subject: [PATCH] Refactor question generating to use request.js --- .../retrospring/features/inbox/generate.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/javascript/retrospring/features/inbox/generate.ts b/app/javascript/retrospring/features/inbox/generate.ts index 5cdd5e5c..abbc4d83 100644 --- a/app/javascript/retrospring/features/inbox/generate.ts +++ b/app/javascript/retrospring/features/inbox/generate.ts @@ -1,23 +1,21 @@ -import Rails from '@rails/ujs'; +import { post } from '@rails/request.js'; import I18n from 'retrospring/i18n'; import { updateDeleteButton } from './delete'; import { showErrorNotification } from 'utilities/notifications'; export function generateQuestionHandler(): void { - Rails.ajax({ - url: '/ajax/generate_question', - type: 'POST', - dataType: 'json', - success: (data) => { + post('/ajax/generate_question') + .then(async response => { + const data = await response.json; + if (!data.success) return false; document.querySelector('#entries').insertAdjacentHTML('afterbegin', data.render); updateDeleteButton(); - }, - error: (data, status, xhr) => { - console.log(data, status, xhr); - showErrorNotification(I18n.translate('frontend.error.message')); - } - }); + }) + .catch(err => { + console.log(err); + showErrorNotification(I18n.translate('frontend.error.message')); + }); } \ No newline at end of file