<commit_before>React = { findDOMNode } = require 'react'
auth = require '../api/auth'
alert = require '../lib/alert'
LoginDialog = require '../partials/login-dialog'

module.exports = React.createClass
  displayName: 'UnsubscribeFromEmailsPage'

  getDefaultProps: ->
    query: {}

  getInitialState: ->
    inProgress: false
    resetSuccess: false
    resetError: null
    emailSuccess: false
    emailError: false
    emailIsValid: false

  componentDidMount: ->
    @handleEmailChange()

  handleEmailChange: ->
    @setState { emailIsValid: findDOMNode(@refs.email).checkValidity() }

  handleEmailSubmit: (e) ->
    e.preventDefault()

    @setState
      inProgress: true
      emailSuccess: false
      emailError: false

    email = findDOMNode(@refs.email).value

    auth.unsubscribeEmail {email}
      .then =>
        @setState emailSuccess: true
      .catch =>
        @setState emailError: true
      .then =>
        @setState inProgress: false

  render: ->
    <div className="centered-grid">
      <form onSubmit={@handleEmailSubmit}>
        <p><strong>Unsubscribe from all Zooniverse emails.</strong></p>
        <p>We get it, no one like keep getting email they don't want.</p>
        <p>Just enter your email address here and we'll <b>unsubscribe you from all</b> our email lists.</p>
        <p>
          <input ref="email" type="email" required onChange={@handleEmailChange} className="standard-input" defaultValue={@props.query?.email} size="50" />
        </p>
        <p>
          {if @state.emailIsValid
            <button type="submit" className="standard-button">Submit</button>
          else
            <button type="submit" className="standard-button" disabled>Submit</button>}

          {' '}

          {if @state.inProgress
            <i className="fa fa-spinner fa-spin form-help"></i>
          else if @state.emailSuccess
            <i className="fa fa-check-circle form-help success"></i>}
        </p>

        {if @state.emailSuccess
          <p>You've been unsubscribed!</p>
        else if @state.emailError
          <small className="form-help error">There was an error unsubscribing your email.</small>}
      </form>
    </div>
<commit_msg>let the submit button know the disable state<commit_after>React = { findDOMNode } = require 'react'
auth = require '../api/auth'
alert = require '../lib/alert'
LoginDialog = require '../partials/login-dialog'

module.exports = React.createClass
  displayName: 'UnsubscribeFromEmailsPage'

  getDefaultProps: ->
    query: {}

  getInitialState: ->
    inProgress: false
    resetSuccess: false
    resetError: null
    emailSuccess: false
    emailError: false
    emailIsValid: false

  componentDidMount: ->
    @handleEmailChange()

  handleEmailChange: ->
    @setState { emailIsValid: findDOMNode(@refs.email).checkValidity() }

  handleEmailSubmit: (e) ->
    e.preventDefault()

    @setState
      inProgress: true
      emailSuccess: false
      emailError: false

    email = findDOMNode(@refs.email).value

    auth.unsubscribeEmail {email}
      .then =>
        @setState emailSuccess: true
      .catch =>
        @setState emailError: true
      .then =>
        @setState inProgress: false

  render: ->
    <div className="centered-grid">
      <form onSubmit={@handleEmailSubmit}>
        <p><strong>Unsubscribe from all Zooniverse emails.</strong></p>
        <p>We get it, no one like keep getting email they don't want.</p>
        <p>Just enter your email address here and we'll <b>unsubscribe you from all</b> our email lists.</p>
        <p>
          <input ref="email" type="email" required onChange={@handleEmailChange} className="standard-input" defaultValue={@props.query?.email} size="50" />
        </p>
        <p>
          <button type="submit" className="standard-button" disabled={!@state.emailIsValid || @state.emailSuccess}>Submit</button>

          {' '}

          {if @state.inProgress
            <i className="fa fa-spinner fa-spin form-help"></i>
          else if @state.emailSuccess
            <i className="fa fa-check-circle form-help success"></i>}
        </p>

        {if @state.emailSuccess
          <p>You've been unsubscribed!</p>
        else if @state.emailError
          <small className="form-help error">There was an error unsubscribing your email.</small>}
      </form>
    </div>

{'fraction_non_alphanumeric': 0.12744421440073614, 'fraction_numerical': 0.0009201748332183115, 'mean_word_length': 2.669198312236287, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 81, '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': '3919028', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1245, 'n_words': 316}