2022-01-02 18:28:21 -08:00
|
|
|
import Rails from '@rails/ujs';
|
|
|
|
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-02 18:28:21 -08:00
|
|
|
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);
|
2022-01-02 19:36:45 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2022-01-02 18:28:21 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|