diff --git a/app/javascript/retrospring/features/answerbox/index.ts b/app/javascript/retrospring/features/answerbox/index.ts index 61dc7edc..cf088f8b 100644 --- a/app/javascript/retrospring/features/answerbox/index.ts +++ b/app/javascript/retrospring/features/answerbox/index.ts @@ -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 } diff --git a/app/javascript/retrospring/features/answerbox/subscribe.ts b/app/javascript/retrospring/features/answerbox/subscribe.ts deleted file mode 100644 index 977d410e..00000000 --- a/app/javascript/retrospring/features/answerbox/subscribe.ts +++ /dev/null @@ -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')); - }); -} \ No newline at end of file