import { CompositeDisposable } from 'rx'; import React, { PropTypes } from 'react'; import { Button, Input, Col, Row, Well } from 'react-bootstrap'; import { connect } from 'react-redux'; import { push } from 'react-router-redux'; import PureComponent from 'react-pure-render/component'; import { createSelector } from 'reselect'; import { applyPromo, clearPromo, updatePromo } from '../redux/actions'; // real paypal buttons // will take your money const paypalIds = { regular: 'Q8Z82ZLAX3Q8N', highlighted: 'VC8QPSKCYMZLN' }; const bindableActions = { applyPromo, clearPromo, push, updatePromo }; const mapStateToProps = createSelector( state => state.jobsApp.newJob, state => state.jobsApp, ( { id, isHighlighted } = {}, { buttonId, price = 1000, discountAmount = 0, promoCode = '', promoApplied = false, promoName = '' } ) => { if (!buttonId) { buttonId = isHighlighted ? paypalIds.highlighted : paypalIds.regular; } return { id, isHighlighted, price, discountAmount, promoName, promoCode, promoApplied }; } ); export class JobTotal extends PureComponent { constructor(...args) { super(...args); this._subscriptions = new CompositeDisposable(); } static displayName = 'JobTotal'; static propTypes = { id: PropTypes.string, isHighlighted: PropTypes.bool, buttonId: PropTypes.string, price: PropTypes.number, discountAmount: PropTypes.number, promoName: PropTypes.string, promoCode: PropTypes.string, promoApplied: PropTypes.bool }; componentWillMount() { if (!this.props.id) { this.props.push('/jobs'); } this.props.clearPromo(); } componentWillUnmount() { this._subscriptions.dispose(); } renderDiscount(discountAmount) { if (!discountAmount) { return null; } return (

Promo Discount

-{ discountAmount }

); } renderHighlightPrice(isHighlighted) { if (!isHighlighted) { return null; } return (

Highlighting

+ 250

); } renderPromo() { const { id, promoApplied, promoCode, promoName, isHighlighted, applyPromo, updatePromo } = this.props; if (promoApplied) { return (
{ promoName } applied
); } return (
Have a promo code?
); } render() { const { id, isHighlighted, buttonId, price, discountAmount, push } = this.props; return (

One more step

You're Awesome! just one more step to go. Clicking on the link below will redirect to paypal.

Job Posting

+ { price }

{ this.renderHighlightPrice(isHighlighted) } { this.renderDiscount(discountAmount) }

Total

${ price - discountAmount + (isHighlighted ? 250 : 0) }

{ this.renderPromo() }
setTimeout(push, 0, '/jobs') } target='_blank'>
An array of credit cards
); } } export default connect(mapStateToProps, bindableActions)(JobTotal);