<commit_before>// @flow
import React, { useState } from 'react';
import { FormField, Form } from 'component/common/form';
import Button from 'component/button';
import analytics from 'analytics';
import { EMAIL_REGEX } from 'constants/email';
import I18nMessage from 'component/i18nMessage';

type Props = {
  errorMessage: ?string,
  isPending: boolean,
  addUserEmail: string => void,
  syncEnabled: boolean,
  setSync: boolean => void,
  balance: number,
  daemonSettings: { share_usage_data: boolean },
  setShareDiagnosticData: boolean => void,
};

function UserEmailNew(props: Props) {
  const { errorMessage, isPending, addUserEmail, setSync, daemonSettings, setShareDiagnosticData } = props;
  const { share_usage_data: shareUsageData } = daemonSettings;
  const [newEmail, setEmail] = useState('');
  const [localShareUsageData, setLocalShareUsageData] = React.useState(false);
  const [formSyncEnabled, setFormSyncEnabled] = useState(true);
  const valid = newEmail.match(EMAIL_REGEX);

  function handleUsageDataChange() {
    setLocalShareUsageData(!localShareUsageData);
  }

  function handleSubmit() {
    setSync(formSyncEnabled);
    addUserEmail(newEmail);
    // @if TARGET='app'
    setShareDiagnosticData(true);
    // @endif
    analytics.emailProvidedEvent();
  }

  return (
    <React.Fragment>
      <h1 className="section__title--large">{__('Sign In to lbry.tv')}</h1>
      <p className="section__subtitle">
        {/* @if TARGET='web' */}
        {__('Create a new account or sign in.')}
        {/* @endif */}
        {/* @if TARGET='app' */}
        {__('An account with lbry.tv allows you to earn rewards and backup your data.')}
        {/* @endif */}
      </p>
      <Form onSubmit={handleSubmit} className="section__body">
        <FormField
          autoFocus
          placeholder={__('<EMAIL>')}
          type="email"
          name="sign_up_email"
          label={__('Email')}
          value={newEmail}
          error={errorMessage}
          onChange={e => setEmail(e.target.value)}
        />

        {!IS_WEB && (
          <FormField
            type="checkbox"
            name="sync_checkbox"
            label={
              <React.Fragment>
                {__('Backup your account and wallet data.')}{' '}
                <Button button="link" href="https://lbry.com/faq/account-sync" label={__('Learn More')} />
              </React.Fragment>
            }
            checked={formSyncEnabled}
            onChange={() => setFormSyncEnabled(!formSyncEnabled)}
          />
        )}

        {!shareUsageData && !IS_WEB && (
          <FormField
            type="checkbox"
            name="share_data_checkbox"
            checked={localShareUsageData}
            onChange={handleUsageDataChange}
            label={
              <React.Fragment>
                {__('Share usage data with LBRY inc.')}{' '}
                <Button button="link" href="https://lbry.com/faq/privacy-and-data" label={__('Learn More')} />
                {!localShareUsageData && <span className="error-text"> ({__('Required')})</span>}
              </React.Fragment>
            }
          />
        )}
        <div className="card__actions">
          <Button
            button="primary"
            type="submit"
            label={__('Continue')}
            disabled={!newEmail || !valid || !setShareDiagnosticData || isPending}
          />
        </div>
      </Form>
      {/* @if TARGET='web' */}
      <p className="help"><commit_msg>fix typo<commit_after>// @flow
import React, { useState } from 'react';
import { FormField, Form } from 'component/common/form';
import Button from 'component/button';
import analytics from 'analytics';
import { EMAIL_REGEX } from 'constants/email';
import I18nMessage from 'component/i18nMessage';

type Props = {
  errorMessage: ?string,
  isPending: boolean,
  addUserEmail: string => void,
  syncEnabled: boolean,
  setSync: boolean => void,
  balance: number,
  daemonSettings: { share_usage_data: boolean },
  setShareDiagnosticData: boolean => void,
};

function UserEmailNew(props: Props) {
  const { errorMessage, isPending, addUserEmail, setSync, daemonSettings, setShareDiagnosticData } = props;
  const { share_usage_data: shareUsageData } = daemonSettings;
  const [newEmail, setEmail] = useState('');
  const [localShareUsageData, setLocalShareUsageData] = React.useState(false);
  const [formSyncEnabled, setFormSyncEnabled] = useState(true);
  const valid = newEmail.match(EMAIL_REGEX);

  function handleUsageDataChange() {
    setLocalShareUsageData(!localShareUsageData);
  }

  function handleSubmit() {
    setSync(formSyncEnabled);
    addUserEmail(newEmail);
    // @if TARGET='app'
    setShareDiagnosticData(true);
    // @endif
    analytics.emailProvidedEvent();
  }

  return (
    <React.Fragment>
      <h1 className="section__title--large">{__('Sign In to lbry.tv')}</h1>
      <p className="section__subtitle">
        {/* @if TARGET='web' */}
        {__('Create a new account or sign in.')}
        {/* @endif */}
        {/* @if TARGET='app' */}
        {__('An account with lbry.tv allows you to earn rewards and backup your data.')}
        {/* @endif */}
      </p>
      <Form onSubmit={handleSubmit} className="section__body">
        <FormField
          autoFocus
          placeholder={__('<EMAIL>')}
          type="email"
          name="sign_up_email"
          label={__('Email')}
          value={newEmail}
          error={errorMessage}
          onChange={e => setEmail(e.target.value)}
        />

        {!IS_WEB && (
          <FormField
            type="checkbox"
            name="sync_checkbox"
            label={
              <React.Fragment>
                {__('Backup your account and wallet data.')}{' '}
                <Button button="link" href="https://lbry.com/faq/account-sync" label={__('Learn More')} />
              </React.Fragment>
            }
            checked={formSyncEnabled}
            onChange={() => setFormSyncEnabled(!formSyncEnabled)}
          />
        )}

        {!shareUsageData && !IS_WEB && (
          <FormField
            type="checkbox"
            name="share_data_checkbox"
            checked={localShareUsageData}
            onChange={handleUsageDataChange}
            label={
              <React.Fragment>
                {__('Share usage data with LBRY inc.')}{' '}
                <Button button="link" href="https://lbry.com/faq/privacy-and-data" label={__('Learn More')} />
                {!localShareUsageData && <span className="error-text"> ({__('Required')})</span>}
              </React.Fragment>
            }
          />
        )}
        <div className="card__actions">
          <Button
            button="primary"
            type="submit"
            label={__('Continue')}
            disabled={!newEmail || !valid || !localShareUsageData || isPending}
          />
        </div>
      </Form>
      {/* @if TARGET='web' */}
      <p className="help">
{'fraction_non_alphanumeric': 0.14126074498567334, 'fraction_numerical': 0.0017191977077363897, 'mean_word_length': 2.378993223620523, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 59, 'https://': 4, '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': '6065838', 'n_tokens_mistral': 2035, 'n_tokens_neox': 2026, 'n_words': 406}