Move destroying and deleting questions to question/
This commit is contained in:
parent
dba817c8b6
commit
d116e338a3
|
@ -1,10 +1,10 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import { post } from '@rails/request.js';
|
||||
import { showErrorNotification, showNotification } from 'utilities/notifications';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import I18n from 'retrospring/i18n';
|
||||
|
||||
export function questionboxDestroyHandler(event: Event): void {
|
||||
export function questionDestroyHandler(event: Event): void {
|
||||
event.preventDefault();
|
||||
const button = event.target as HTMLButtonElement;
|
||||
const questionId = button.dataset.qId;
|
||||
|
@ -24,13 +24,15 @@ export function questionboxDestroyHandler(event: Event): void {
|
|||
return;
|
||||
}
|
||||
|
||||
Rails.ajax({
|
||||
url: '/ajax/destroy_question',
|
||||
type: 'POST',
|
||||
data: new URLSearchParams({
|
||||
post('/ajax/destroy_question', {
|
||||
body: {
|
||||
question: questionId
|
||||
}).toString(),
|
||||
success: (data) => {
|
||||
},
|
||||
contentType: 'application/json'
|
||||
})
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (data.success) {
|
||||
if (button.dataset.redirect !== undefined) {
|
||||
window.location.pathname = button.dataset.redirect;
|
||||
|
@ -43,11 +45,10 @@ export function questionboxDestroyHandler(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'));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
import registerEvents from 'utilities/registerEvents';
|
||||
import { questionAnswerHandler, questionAnswerInputHandler } from './answer';
|
||||
import { questionDestroyHandler } from './destroy';
|
||||
import { questionReportHandler } from './report';
|
||||
|
||||
export default (): void => {
|
||||
registerEvents([
|
||||
{ type: 'click', target: '[data-action=ab-question-report]', handler: questionReportHandler, global: true },
|
||||
{ type: 'click', target: '[data-action=ab-question-destroy]', handler: questionDestroyHandler, global: true },
|
||||
{ type: 'click', target: '#q-answer-btn', handler: questionAnswerHandler, global: true },
|
||||
{ type: 'keydown', target: '#q-answer-text', handler: questionAnswerInputHandler, global: true }
|
||||
]);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { reportDialog } from 'utilities/reportDialog';
|
||||
|
||||
export function questionboxReportHandler(event: Event): void {
|
||||
export function questionReportHandler(event: Event): void {
|
||||
event.preventDefault();
|
||||
const button = event.target as HTMLButtonElement;
|
||||
const questionId = button.dataset.qId;
|
|
@ -1,15 +1,11 @@
|
|||
import registerEvents from 'utilities/registerEvents';
|
||||
import { questionboxAllHandler, questionboxAllInputHandler } from './all';
|
||||
import { questionboxDestroyHandler } from './destroy';
|
||||
import { questionboxReportHandler } from './report';
|
||||
import { questionboxPromoteHandler, questionboxUserHandler, questionboxUserInputHandler } from './user';
|
||||
|
||||
export default (): void => {
|
||||
registerEvents([
|
||||
{ type: 'click', target: '[data-action=ab-question-report]', handler: questionboxReportHandler, global: true },
|
||||
{ type: 'click', target: '[name=qb-ask]', handler: questionboxUserHandler, global: true },
|
||||
{ type: 'click', target: '#new-question', handler: questionboxPromoteHandler, global: true },
|
||||
{ type: 'click', target: '[data-action=ab-question-destroy]', handler: questionboxDestroyHandler, global: true },
|
||||
{ type: 'click', target: '[name=qb-all-ask]', handler: questionboxAllHandler, global: true },
|
||||
{ type: 'keydown', target: '[name=qb-question]', handler: questionboxUserInputHandler, global: true },
|
||||
{ type: 'keydown', target: '[name=qb-all-question]', handler: questionboxAllInputHandler, global: true }
|
||||
|
|
Loading…
Reference in New Issue