<commit_before>var React = require(`react`);
var ga = require('react-ga');
import { FormattedHTMLMessage } from 'react-intl';

module.exports = React.createClass({
  contextTypes: {
    intl: React.PropTypes.object
  },
  propTypes: {
    submitButtonText: React.PropTypes.string,
    formName: React.PropTypes.string,
    onSubmission: React.PropTypes.func,
    dataToPrefill: React.PropTypes.object
  },
  mixins: [require(`react-addons-linked-state-mixin`)],
  getInitialState() {
    return {
      isSubmitting: false,
      didSignUp: false,
      email: ``,
      country: ``,
      name: ``,
      formPrefilled: false
    };
  },
  componentDidMount: function() {
    this.refs.name.focus();
  },
  componentDidUpdate: function(prevProps, prevState) {
    var dataToPrefill = this.props.dataToPrefill;
    if ( dataToPrefill && !this.state.formPrefilled ) {
      this.setState({
        country: dataToPrefill.country ? dataToPrefill.country.toUpperCase() : "",
        email: dataToPrefill.email ? dataToPrefill.email : "",
        formPrefilled: true
      });
    }
  },
  getDefaultProps() {
    return {
      formName: "form"
    };
  },
  sendEmailToBasket: function(e) {
    e.preventDefault();
    if (this.state.isSubmitting) {
      return;
    }
    this.setState({
      isSubmitting: true
    });
    var request = new XMLHttpRequest();
    var lang = `en`;
    var url = process.env.BASKET_URL;
    var newsletters = `mozilla-foundation`;
    var sourceURL = encodeURIComponent(`https://advocacy.mozilla.org/encrypt`);
    var email = this.state.email;
    var country = this.state.country;
    var firstName = this.state.name;
    var params = `newsletters=` + newsletters + `&source_url=` + sourceURL + `&lang=` + lang + `&email=` + email + `&trigger_welcome=N`;

    if (country) {
      params += `&country=` + country;
    }
    if (firstName) {
      params += `&first_name=` + firstName;
    }
    request.onreadystatechange = () => {
      if (request.readyState === 4) {
        if (request.status === 200) {
          // Optimizely conversion tracking
          window.optimizely = window.optimizely || [];
          window.optimizely.push(['trackEvent', 'advocacysignup']);
          ga.event({ category: "Signup", action: "Submitted the form" });
          this.setState({
            didSignUp: true
          });
          if (this.props.onSubmission) {
            this.props.onSubmission();
          }<commit_msg>Fix issue #210 - Set header form submission<commit_after>var React = require(`react`);
var ga = require('react-ga');
import { FormattedHTMLMessage } from 'react-intl';

module.exports = React.createClass({
  contextTypes: {
    intl: React.PropTypes.object
  },
  propTypes: {
    submitButtonText: React.PropTypes.string,
    formName: React.PropTypes.string,
    onSubmission: React.PropTypes.func,
    dataToPrefill: React.PropTypes.object
  },
  mixins: [require(`react-addons-linked-state-mixin`)],
  getInitialState() {
    return {
      isSubmitting: false,
      didSignUp: false,
      email: ``,
      country: ``,
      name: ``,
      formPrefilled: false
    };
  },
  componentDidMount: function() {
    this.refs.name.focus();
  },
  componentDidUpdate: function(prevProps, prevState) {
    var dataToPrefill = this.props.dataToPrefill;
    if ( dataToPrefill && !this.state.formPrefilled ) {
      this.setState({
        country: dataToPrefill.country ? dataToPrefill.country.toUpperCase() : "",
        email: dataToPrefill.email ? dataToPrefill.email : "",
        formPrefilled: true
      });
    }
  },
  getDefaultProps() {
    return {
      formName: "form"
    };
  },
  sendEmailToBasket: function(e) {
    e.preventDefault();
    if (this.state.isSubmitting) {
      return;
    }
    this.setState({
      isSubmitting: true
    });
    var request = new XMLHttpRequest();
    var lang = `en`;
    var url = process.env.BASKET_URL;
    var newsletters = `mozilla-foundation`;
    var sourceURL = encodeURIComponent(`https://advocacy.mozilla.org/encrypt`);
    var email = this.state.email;
    var country = this.state.country;
    var firstName = this.state.name;
    var params = `newsletters=` + newsletters + `&source_url=` + sourceURL + `&lang=` + lang + `&email=` + email + `&trigger_welcome=N`;

    if (country) {
      params += `&country=` + country;
    }
    if (firstName) {
      params += `&first_name=` + firstName;
    }

    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.onreadystatechange = () => {
      if (request.readyState === 4) {
        if (request.status === 200) {
          // Optimizely conversion tracking
          window.optimizely = window.optimizely || [];
          window.optimizely.push(['trackEvent', 'advocacysignup']);
          ga.event({ category: "Signup", action: "Submitted the form" });
          this.setState({
            didSignUp: true
          });
          if (this.props.onSubmission) {
            this.props.onSubmission();
          }
{'fraction_non_alphanumeric': 0.14211783439490447, 'fraction_numerical': 0.0021894904458598726, 'mean_word_length': 2.7057522123893807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '4418691', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1575, 'n_words': 296}