<commit_before>const React = require('react')
const { map, dissoc } = require('ramda')
const { types, type_order } = require('../form_fields/charge_form.js')

const PaymentsTable = require('../../shared/components/payments_table')
const ChargeForm = require('./charge_form.js')

var MemberPayments = (
  { payments
  , payment_defaults
  , switch_charge_type
  , charge_type
  , add_payment
  , remove_payment
  }
) =>
  <div>
    <div className='inner-section-divider-medium'></div>
    <div className='inner-section-divider-medium'></div>
    <PaymentsTable
      payments={payments}
      remove_payment={remove_payment}
    />
    { charge_type
      ? <ChargeForm
          fields={types[charge_type]}
          type={charge_type}
          initialValues={with_amount(charge_type, payment_defaults)}
          onSubmit={add_payment}
        />
      : ''
    }
    <div className='flex payment-buttons'>
      { map
        ( (type) =>
            <button
              onClick={(_) => switch_charge_type(type)}
              key={type}
            >
              { '+ ' + type }
            </button>
          , type_order
        )
      }
      <a href="#/" className="flex-button">
        <button className="btn-primary">Home</button>
      </a>
    </div>
  </div>

const with_amount = (type, defaults) => {
  return type === 'subscription' ? defaults : dissoc('amount', defaults)
}

module.exports = MemberPayments
<commit_msg>refactor member_payments<commit_after>const React = require('react')
const { map, dissoc } = require('ramda')
const { types, type_order } = require('../form_fields/charge_form.js')

const PaymentsTable = require('../../shared/components/payments_table')
const ChargeForm = require('./charge_form.js')

var MemberPayments = (
  { payments
  , payment_defaults
  , switch_charge_type
  , charge_type
  , add_payment
  , remove_payment
  }
) =>
  <div>
    <div className='inner-section-divider-medium'></div>
    <div className='inner-section-divider-medium'></div>
    <PaymentsTable
      payments={payments}
      remove_payment={remove_payment}
    />
    {charge_type &&
      <ChargeForm
        fields={types[charge_type]}
        type={charge_type}
        initialValues={with_amount(charge_type, payment_defaults)}
        onSubmit={add_payment}
      />
    }
    <div className='flex payment-buttons'>
      { map
        (type =>
          <button
            onClick={() => switch_charge_type(type)}
            key={type}
          >
            { '+ ' + type }
          </button>
          , type_order
        )
      }
      <a href='#/' className='flex-button'>
        <button className='btn-primary'>Home</button>
      </a>
    </div>
  </div>

const with_amount = (type, defaults) => type === 'subscription' ? defaults : dissoc('amount', defaults)

module.exports = MemberPayments

{'fraction_non_alphanumeric': 0.14562082307421736, 'fraction_numerical': 0.0, 'mean_word_length': 2.532919254658385, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, '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': '1450276', 'n_tokens_mistral': 855, 'n_tokens_neox': 857, 'n_words': 144}