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