| 1 |
import $ from 'jquery'; |
| 2 |
import Raven from '../lib/Raven'; |
| 3 |
import { domElements } from '../constants/selectors'; |
| 4 |
import ThickBoxModal from '../feedback/ThickBoxModal'; |
| 5 |
import { submitFeedbackForm } from '../feedback/feedbackFormApi'; |
| 6 |
import { |
| 7 |
getOrCreateBackgroundApp, |
| 8 |
initBackgroundApp, |
| 9 |
} from '../utils/backgroundAppUtils'; |
| 10 |
import { ProxyMessages } from '../iframe/integratedMessages'; |
| 11 |
|
| 12 |
let embedder: any; |
| 13 |
|
| 14 |
function deactivatePlugin() { |
| 15 |
const href = $(domElements.deactivatePluginButton).attr('href'); |
| 16 |
if (href) { |
| 17 |
window.location.href = href; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
function setLoadingState() { |
| 22 |
$(domElements.deactivateFeedbackSubmit).addClass('loading'); |
| 23 |
} |
| 24 |
|
| 25 |
function submitAndDeactivate(e: Event) { |
| 26 |
e.preventDefault(); |
| 27 |
setLoadingState(); |
| 28 |
const feedback = $(domElements.deactivateFeedbackForm) |
| 29 |
.serializeArray() |
| 30 |
.find(field => field.name === 'feedback'); |
| 31 |
|
| 32 |
submitFeedbackForm(domElements.deactivateFeedbackForm) |
| 33 |
.then(() => { |
| 34 |
if (feedback && embedder) { |
| 35 |
embedder.postMessage({ |
| 36 |
key: ProxyMessages.TrackPluginDeactivation, |
| 37 |
payload: { |
| 38 |
type: feedback.value.trim().replace(/[\s']+/g, '_'), |
| 39 |
}, |
| 40 |
}); |
| 41 |
} |
| 42 |
}) |
| 43 |
.catch((err: Error) => { |
| 44 |
Raven.captureException(err); |
| 45 |
}) |
| 46 |
.finally(() => { |
| 47 |
deactivatePlugin(); |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
function init() { |
| 52 |
embedder = getOrCreateBackgroundApp(); |
| 53 |
// eslint-disable-next-line no-new |
| 54 |
new ThickBoxModal( |
| 55 |
domElements.deactivatePluginButton, |
| 56 |
'leadin-feedback-container', |
| 57 |
'leadin-feedback-window', |
| 58 |
'leadin-feedback-content' |
| 59 |
); |
| 60 |
|
| 61 |
$(domElements.deactivateFeedbackForm) |
| 62 |
.off('submit') |
| 63 |
.on('submit', submitAndDeactivate); |
| 64 |
$(domElements.deactivateFeedbackSkip) |
| 65 |
.off('click') |
| 66 |
.on('click', deactivatePlugin); |
| 67 |
} |
| 68 |
|
| 69 |
initBackgroundApp(init); |
| 70 |
|