<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { pushState } from 'redux-router';
import getUniqueValues from '../lib/get_unique_values';

import rejectError from '../lib/reject_error';

import Content from './Content';

import Header from '../components/Header';
import Notification from '../components/Notification';
import DonationForm from '../components/DonationForm';

import validateTransaction from '../actions/form/validate_transaction';
import createTransaction from '../actions/transactions/create';
import appendDonationForm from '../actions/form/append_donation';
import setDonationCustom from '../actions/form/set_donation_custom';
import resetNotifications from '../actions/notification/reset';
import fetchGroup from '../actions/groups/fetch_by_id';
import fetchUser from '../actions/users/fetch_by_id';
import fetchCards from '../actions/users/fetch_cards';
import notify from '../actions/notification/notify';

export class Donation extends Component {
  render() {
    const backLink = `/groups/${this.props.groupid}/transactions/`;

    return (
      <div className='Donation'>
        <Header
          title='Add funds'
          backLink={backLink} />
        <Content>
          <Notification {...this.props} />
          <div className='padded'>
            <DonationForm {...this.props} donate={donate.bind(this)}/>
          </div>
        </Content>
      </div>
    );
  }

  componentWillMount() {
    this.props.fetchGroup(this.props.groupid);
    this.props.fetchUser(this.props.userid);
    this.props.fetchCards(this.props.userid);
  }

}

export function donate() {
  const {
    validateTransaction,
    createTransaction,
    groupid,
    amount,
    group,
    user,
    notify,
    pushState,
    description
  } = this.props;

  const transaction = {
    amount,
    description: description || `Donation from ${user.email} to ${group.name}`,
    tags: ['Donation'],
    approvedAt: Date.now(),
    approved: true,
    createdAt: Date.now()
  };

  return validateTransaction(transaction)
  .then(rejectError.bind(this, 'validationError'))
  .then(() => createTransaction(groupid, transaction))
  .then(rejectError.bind(this, 'serverError'))
  .then(() => pushState(null, `/groups/${groupid}/transactions`))
  .catch(error => notify('error', error.message));
}

export default connect(mapStateToProps, {
  resetNotifications,
  fetchUser,
  fetchGroup,
  fetchCards,
  setDonationCustom,
  createTransaction,
  validateTransaction,
  notify,
  pushState,
  appendDonationForm
})(Donation);

function mapStateToProps({router, groups, form, session, users, transactions, notification}) {
  const groupid = router.params.groupid;
  const userid = session.user.id;
  const currentUser = users[userid];
 
  let userCardsLabels = [];
  if (currentUser) {
    userCardsLabels = getUniqueValues(currentUser.cards, 'number'); 
  }
  
  return {
    groupid,
    userid,
    notification,
    form,
    transactions,
    isCustomMode: form.donation.isCustomMode,
    description: form.donation.attributes.description,
    amount: form.donation.attributes.amount,
    group: groups[groupid] || {},
    userCardsLabels: userCardsLabels,
    validationError: form.transaction.error,
    serverError: transactions.error
  };
}<commit_msg>clean up syntax<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { pushState } from 'redux-router';
import getUniqueValues from '../lib/get_unique_values';

import rejectError from '../lib/reject_error';

import Content from './Content';

import Header from '../components/Header';
import Notification from '../components/Notification';
import DonationForm from '../components/DonationForm';

import validateTransaction from '../actions/form/validate_transaction';
import createTransaction from '../actions/transactions/create';
import appendDonationForm from '../actions/form/append_donation';
import setDonationCustom from '../actions/form/set_donation_custom';
import resetNotifications from '../actions/notification/reset';
import fetchGroup from '../actions/groups/fetch_by_id';
import fetchUser from '../actions/users/fetch_by_id';
import fetchCards from '../actions/users/fetch_cards';
import notify from '../actions/notification/notify';

export class Donation extends Component {
  render() {
    const backLink = `/groups/${this.props.groupid}/transactions/`;

    return (
      <div className='Donation'>
        <Header
          title='Add funds'
          backLink={backLink} />
        <Content>
          <Notification {...this.props} />
          <div className='padded'>
            <DonationForm {...this.props} donate={donate.bind(this)}/>
          </div>
        </Content>
      </div>
    );
  }

  componentWillMount() {
    this.props.fetchGroup(this.props.groupid);
    this.props.fetchUser(this.props.userid);
    this.props.fetchCards(this.props.userid);
  }

}

export function donate() {
  const {
    validateTransaction,
    createTransaction,
    groupid,
    amount,
    group,
    user,
    notify,
    pushState,
    description
  } = this.props;

  const transaction = {
    amount,
    description: description || `Donation from ${user.email} to ${group.name}`,
    tags: ['Donation'],
    approvedAt: Date.now(),
    approved: true,
    createdAt: Date.now()
  };

  return validateTransaction(transaction)
  .then(rejectError.bind(this, 'validationError'))
  .then(() => createTransaction(groupid, transaction))
  .then(rejectError.bind(this, 'serverError'))
  .then(() => pushState(null, `/groups/${groupid}/transactions`))
  .catch(error => notify('error', error.message));
}

export default connect(mapStateToProps, {
  resetNotifications,
  fetchUser,
  fetchGroup,
  fetchCards,
  setDonationCustom,
  createTransaction,
  validateTransaction,
  notify,
  pushState,
  appendDonationForm
})(Donation);

function mapStateToProps({router, groups, form, session, users, transactions, notification}) {
  const groupid = router.params.groupid;
  const userid = session.user.id;
  const currentUser = users[userid];
  const userCardsLabels = currentUser ?
    getUniqueValues(currentUser.cards, 'number') : [];

  return {
    groupid,
    userid,
    notification,
    form,
    transactions,
    isCustomMode: form.donation.isCustomMode,
    description: form.donation.attributes.description,
    amount: form.donation.attributes.amount,
    group: groups[groupid] || {},
    userCardsLabels,
    validationError: form.transaction.error,
    serverError: transactions.error
  };
}
{'fraction_non_alphanumeric': 0.133262583383869, 'fraction_numerical': 0.0, 'mean_word_length': 3.725644699140401, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '7449219', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1884, 'n_words': 417}