Remove TypeScript subscription functionality
This commit is contained in:
parent
563f834287
commit
42b5b6ccc2
|
@ -3,11 +3,9 @@ import registerAnswerboxCommentEvents from './comment';
|
|||
import { answerboxDestroyHandler } from './destroy';
|
||||
import { answerboxReportHandler } from './report';
|
||||
import { answerboxSmileHandler } from './smile';
|
||||
import { answerboxSubscribeHandler } from './subscribe';
|
||||
|
||||
export default (): void => {
|
||||
registerEvents([
|
||||
{ type: 'click', target: '[data-action=ab-submarine]', handler: answerboxSubscribeHandler, global: true },
|
||||
{ type: 'click', target: '[data-action=ab-report]', handler: answerboxReportHandler, global: true },
|
||||
{ type: 'click', target: '[data-action=ab-destroy]', handler: answerboxDestroyHandler, global: true },
|
||||
{ type: 'click', target: '[name=ab-smile]', handler: answerboxSmileHandler, global: true }
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
import { post } from '@rails/request.js';
|
||||
|
||||
import I18n from 'retrospring/i18n';
|
||||
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
||||
|
||||
export function answerboxSubscribeHandler(event: Event): void {
|
||||
const button = event.target as HTMLButtonElement;
|
||||
const id = button.dataset.aId;
|
||||
let torpedo = 0;
|
||||
let targetUrl;
|
||||
event.preventDefault();
|
||||
|
||||
if (button.dataset.torpedo === 'yes') {
|
||||
torpedo = 1;
|
||||
}
|
||||
|
||||
if (torpedo) {
|
||||
targetUrl = '/ajax/subscribe';
|
||||
} else {
|
||||
targetUrl = '/ajax/unsubscribe';
|
||||
}
|
||||
|
||||
post(targetUrl, {
|
||||
body: {
|
||||
answer: id
|
||||
},
|
||||
contentType: 'application/json'
|
||||
})
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (data.success) {
|
||||
button.dataset.torpedo = ["yes", "no"][torpedo];
|
||||
button.children[0].nextSibling.textContent = ' ' + (torpedo ? I18n.translate('voc.unsubscribe') : I18n.translate('voc.subscribe'));
|
||||
showNotification(I18n.translate(`frontend.subscription.${torpedo ? 'subscribe' : 'unsubscribe'}`));
|
||||
} else {
|
||||
showErrorNotification(I18n.translate(`frontend.subscription.fail.${torpedo ? 'subscribe' : 'unsubscribe'}`));
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue