<commit_before>import React from 'react';
import { Paper, TextField, Button, InputAdornment, Typography, IconButton, Snackbar } from '@material-ui/core';
import CloseIcon from '@material-ui/icons/Close';
import PropTypes from 'prop-types';
import RegisterLogin from '../Register/RegisterLogin.jsx';
import SponsorPresentation from './SponsorPresentation.jsx';
import SponsorInformation from '../Sponsor/SponsorInformation.jsx';
import { styleChallenge } from './ListOfChallenges.jsx';

const style = styleChallenge('black');
style.title = {
  padding: '10px 10px 5px',
};
style.icon = {
  marginRight: 10,
  width: 50,
};
style.top.padding = 10;
style.top.flexWrap = 'wrap';
style.inputLeft = {
  marginRight: 10,
  minWidth: 110,
  width: 'calc(50% - 5px)',
};
style.inputRight = {
  width: 'calc(50% - 5px)',
  maxWidth: 'calc(100% - 120px)'
};
style.description.width = '100%';
style.buttons = {
  display: 'flex',
  justifyContent: 'flex-end'
};

class AddSponsoring extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      renderAll: false,
      renderRegisterLogin: false,
      renderSponsorInformation: false,
      amount: '0,10',
      limit: '',
      me: null,
      errors: {},
      isAdding: false,
      justAdded: false,
    };
    this.validate = this.validate.bind(this);
    this.onSuccessRegisterLogin = this.onSuccessRegisterLogin.bind(this);
    this.onSuccessSponsorInformation = this.onSuccessSponsorInformation.bind(this);
    this.addSponsoring = this.addSponsoring.bind(this);
    this.t = (content) => this.props.i18next.t(`client.sponsor.addSponsoring.${content}`);
  }

  async componentDidMount() {
    this.setState({
      me: await this.props.api.getMe()
    });
  }

  onSuccessRegisterLogin() {
    this.setState({
      renderRegisterLogin: false,
    });
    this.addSponsoring();
  }

  addSponsoring(event) {
    if(event) event.preventDefault();

    if (!this.validate('amount', this.state.amount)
        || !this.validate('limit', this.state.limit) ) return false;
    this.setState({isAdding: true});

    this.props.api.getMe().then(me => {
      if(!me.firstname) {
        this.setState({renderSponsorInformation: true});
        return;
      }

      this.props.api.addSponsoring(this.props.teamId,
        {
          limit: (this.state.limit ? this.state.limit.replace(',', '.') : 9999999999),
          amountPerKm: this.state.amount.replace(',', '.')
        })<commit_msg>set limit to 1000000000 when no limit is set<commit_after>import React from 'react';
import { Paper, TextField, Button, InputAdornment, Typography, IconButton, Snackbar } from '@material-ui/core';
import CloseIcon from '@material-ui/icons/Close';
import PropTypes from 'prop-types';
import RegisterLogin from '../Register/RegisterLogin.jsx';
import SponsorPresentation from './SponsorPresentation.jsx';
import SponsorInformation from '../Sponsor/SponsorInformation.jsx';
import { styleChallenge } from './ListOfChallenges.jsx';

const style = styleChallenge('black');
style.title = {
  padding: '10px 10px 5px',
};
style.icon = {
  marginRight: 10,
  width: 50,
};
style.top.padding = 10;
style.top.flexWrap = 'wrap';
style.inputLeft = {
  marginRight: 10,
  minWidth: 110,
  width: 'calc(50% - 5px)',
};
style.inputRight = {
  width: 'calc(50% - 5px)',
  maxWidth: 'calc(100% - 120px)'
};
style.description.width = '100%';
style.buttons = {
  display: 'flex',
  justifyContent: 'flex-end'
};

class AddSponsoring extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      renderAll: false,
      renderRegisterLogin: false,
      renderSponsorInformation: false,
      amount: '0,10',
      limit: '',
      me: null,
      errors: {},
      isAdding: false,
      justAdded: false,
    };
    this.validate = this.validate.bind(this);
    this.onSuccessRegisterLogin = this.onSuccessRegisterLogin.bind(this);
    this.onSuccessSponsorInformation = this.onSuccessSponsorInformation.bind(this);
    this.addSponsoring = this.addSponsoring.bind(this);
    this.t = (content) => this.props.i18next.t(`client.sponsor.addSponsoring.${content}`);
  }

  async componentDidMount() {
    this.setState({
      me: await this.props.api.getMe()
    });
  }

  onSuccessRegisterLogin() {
    this.setState({
      renderRegisterLogin: false,
    });
    this.addSponsoring();
  }

  addSponsoring(event) {
    if(event) event.preventDefault();

    if (!this.validate('amount', this.state.amount)
        || !this.validate('limit', this.state.limit) ) return false;
    this.setState({isAdding: true});

    this.props.api.getMe().then(me => {
      if(!me.firstname) {
        this.setState({renderSponsorInformation: true});
        return;
      }

      this.props.api.addSponsoring(this.props.teamId,
        {
          limit: (this.state.limit ? this.state.limit.replace(',', '.') : 1000000000),
          amountPerKm: this.state.amount.replace(',', '.')
        })
{'fraction_non_alphanumeric': 0.15198548679701673, 'fraction_numerical': 0.020560370892965127, 'mean_word_length': 3.4582210242587603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '4330019', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1608, 'n_words': 300}