# leadin/11.1.13/scripts/entries/feedback.ts

HubSpot All-In-One Marketing – Forms, Popups, Live Chat, version 11.1.13. 69 lines.

- Page: https://pluginprobe.com/plugins/leadin/11.1.13/code/scripts/entries/feedback.ts
- Raw: https://pluginprobe.com/plugins/leadin/11.1.13/raw/scripts/entries/feedback.ts
- Modified: 2024-05-23T13:10:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/leadin/11.1.13/code/scripts/entries/feedback.ts#L10-L20`.

```typescript
import $ from 'jquery';
import Raven from '../lib/Raven';
import { domElements } from '../constants/selectors';
import ThickBoxModal from '../feedback/ThickBoxModal';
import { submitFeedbackForm } from '../feedback/feedbackFormApi';
import {
  getOrCreateBackgroundApp,
  initBackgroundApp,
} from '../utils/backgroundAppUtils';
import { refreshToken } from '../constants/leadinConfig';
import { ProxyMessages } from '../iframe/integratedMessages';

function deactivatePlugin() {
  const href = $(domElements.deactivatePluginButton).attr('href');
  if (href) {
    window.location.href = href;
  }
}

function setLoadingState() {
  $(domElements.deactivateFeedbackSubmit).addClass('loading');
}

function submitAndDeactivate(e: Event) {
  e.preventDefault();
  setLoadingState();
  const feedback = $(domElements.deactivateFeedbackForm)
    .serializeArray()
    .find(field => field.name === 'feedback');

  submitFeedbackForm(domElements.deactivateFeedbackForm)
    .then(() => {
      if (feedback && refreshToken) {
        const embedder = getOrCreateBackgroundApp(refreshToken);
        embedder.postMessage({
          key: ProxyMessages.TrackPluginDeactivation,
          payload: {
            type: feedback.value.trim().replace(/[\s']+/g, '_'),
          },
        });
      }
    })
    .catch((err: Error) => {
      Raven.captureException(err);
    })
    .finally(() => {
      deactivatePlugin();
    });
}

function init() {
  // eslint-disable-next-line no-new
  new ThickBoxModal(
    domElements.deactivatePluginButton,
    'leadin-feedback-container',
    'leadin-feedback-window',
    'leadin-feedback-content'
  );

  $(domElements.deactivateFeedbackForm)
    .off('submit')
    .on('submit', submitAndDeactivate);
  $(domElements.deactivateFeedbackSkip)
    .off('click')
    .on('click', deactivatePlugin);
}

initBackgroundApp(init);

```
