From 721ff425b2d5bc581dfd1d1453abcfe86f354e28 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 3 Jan 2022 03:28:21 +0100 Subject: [PATCH] Port inbox question generation functionality to TypeScript --- .../retrospring/features/inbox/generate.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/javascript/retrospring/features/inbox/generate.ts diff --git a/app/javascript/retrospring/features/inbox/generate.ts b/app/javascript/retrospring/features/inbox/generate.ts new file mode 100644 index 00000000..779282de --- /dev/null +++ b/app/javascript/retrospring/features/inbox/generate.ts @@ -0,0 +1,23 @@ +import Rails from '@rails/ujs'; + +import I18n from '../../../legacy/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) => { + if (!data.success) return false; + + document.querySelector('#entries').insertAdjacentHTML('afterbegin', data.render); + updateDeleteButton(); + }, + error: (data, status, xhr) => { + console.log(data, status, xhr); + showErrorNotification(I18n.t('frontend.error.message')); + } + }); +} \ No newline at end of file