<commit_before>// @flow
import $ from 'jquery';

type Response = {
  double_opt_in: boolean,
  follow_up: string,
};

let version = 1;

const showNotice = () => {
  const banner = $('.cc-banner');
  const headerLogo = $('.header-logo');

  headerLogo.fadeOut(() => banner.fadeIn('slow'));

  banner.find('.cc-btn').on('click', () => {
    banner.hide();
    headerLogo.show();
  });
};

const DoubleOptIn = {
  version(versionNumber?: number) {
    if (versionNumber) {
      version = versionNumber;
      $('.action-form').append(
        `<input type='hidden' name='test_version' value='${version}' />`
      );
    }
    return version;
  },

  handleActionSuccess(resp: Response) {
    if (!resp.double_opt_in) return;

    if (DoubleOptIn.version() === 2) {
      showNotice();
    } else {
      window.location.href = resp.follow_up;
    }
  },
};

$(() =>
  $('.action-form').on('ajax:success', (e, data) =>
    DoubleOptIn.handleActionSuccess(data)
  )
);
<commit_msg>return if success data is undefined<commit_after>// @flow
import $ from 'jquery';

type Response = {
  double_opt_in: boolean,
  follow_up: string,
};

let version = 1;

const showNotice = () => {
  const banner = $('.cc-banner');
  const headerLogo = $('.header-logo');

  headerLogo.fadeOut(() => banner.fadeIn('slow'));

  banner.find('.cc-btn').on('click', () => {
    banner.hide();
    headerLogo.show();
  });
};

const DoubleOptIn = {
  version(versionNumber?: number) {
    if (versionNumber) {
      version = versionNumber;
      $('.action-form').append(
        `<input type='hidden' name='test_version' value='${version}' />`
      );
    }
    return version;
  },

  handleActionSuccess(resp: Response) {
    if (!resp || !resp.double_opt_in) return;

    if (DoubleOptIn.version() === 2) {
      showNotice();
    } else {
      window.location.href = resp.follow_up;
    }
  },
};

$(() =>
  $('.action-form').on('ajax:success', (e, data) =>
    DoubleOptIn.handleActionSuccess(data)
  )
);

{'fraction_non_alphanumeric': 0.19677906391545041, 'fraction_numerical': 0.0020130850528434826, 'mean_word_length': 3.1074380165289255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5441783', 'n_tokens_mistral': 701, 'n_tokens_neox': 670, 'n_words': 122}