Files
freeCodeCamp/common/app/routes/Jobs/components/GoToPayPal.jsx

261 lines
6.7 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
2015-10-26 17:39:38 -07:00
import { Button, Input, Col, Panel, Row, Well } from 'react-bootstrap';
import { contain } from 'thundercats-react';
2015-10-21 20:38:11 -07:00
const paypalIds = {
regular: 'ZVU498PLMPHKU',
regularDiscount: '58U7P36W3L2GQ',
highlighted: '3YYSTBAMJYTUW',
highlightedDiscount: 'QGWTUZ9XEE6EL'
};
export default contain(
{
store: 'JobsStore',
2015-10-26 17:39:38 -07:00
actions: 'jobActions',
2015-10-25 15:51:59 -07:00
map({
job: { id, isHighlighted } = {},
2015-10-27 10:21:51 -07:00
buttonId = isHighlighted ?
paypalIds.highlighted :
paypalIds.regular,
2015-10-25 15:51:59 -07:00
price = 200,
2015-10-26 17:39:38 -07:00
discountAmount = 0,
promoCode = '',
promoApplied = false,
promoName
2015-10-25 15:51:59 -07:00
}) {
2015-10-26 17:39:38 -07:00
return {
id,
isHighlighted,
buttonId,
price,
discountAmount,
promoName,
promoCode,
promoApplied
};
}
},
React.createClass({
displayName: 'GoToPayPal',
propTypes: {
2015-10-15 23:06:16 -07:00
id: PropTypes.string,
2015-10-25 15:51:59 -07:00
isHighlighted: PropTypes.bool,
2015-10-25 18:22:26 -07:00
buttonId: PropTypes.string,
price: PropTypes.number,
2015-10-26 17:39:38 -07:00
discountAmount: PropTypes.number,
promoName: PropTypes.string,
promoCode: PropTypes.string,
promoApplied: PropTypes.bool,
jobActions: PropTypes.object
2015-10-25 18:22:26 -07:00
},
renderDiscount(discountAmount) {
if (!discountAmount) {
return null;
}
return (
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
2015-10-26 17:39:38 -07:00
<h4>Promo Discount</h4>
2015-10-25 18:22:26 -07:00
</Col>
<Col
md={ 3 }>
<h4>-{ discountAmount }</h4>
</Col>
</Row>
);
},
renderHighlightPrice(isHighlighted) {
if (!isHighlighted) {
return null;
}
return (
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
<h4>Highlighting</h4>
</Col>
<Col
md={ 3 }>
<h4>+ 50</h4>
</Col>
</Row>
);
},
2015-10-26 17:39:38 -07:00
renderPromo() {
const {
promoApplied,
promoCode,
promoName,
isHighlighted,
jobActions
} = this.props;
if (promoApplied) {
return (
<div>
<div className='spacer' />
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
{ promoName } applied
</Col>
</Row>
</div>
);
}
return (
<div>
<div className='spacer' />
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
Have a promo code?
</Col>
</Row>
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
<Input
onChange={ jobActions.setPromoCode }
type='text'
value={ promoCode } />
</Col>
<Col
md={ 3 }>
<Button
block={ true }
onClick={ () => {
jobActions.applyCode({
code: promoCode,
type: isHighlighted ? 'isHighlighted' : null
});
}}>
2015-10-26 18:40:48 -07:00
Apply Promo Code
2015-10-26 17:39:38 -07:00
</Button>
</Col>
</Row>
</div>
);
},
render() {
2015-10-26 17:39:38 -07:00
const {
id,
isHighlighted,
buttonId,
price,
discountAmount
} = this.props;
return (
<div>
<Row>
<Col
2015-10-15 23:06:16 -07:00
md={ 10 }
mdOffset={ 1 }
sm={ 8 }
smOffset={ 2 }
xs={ 12 }>
<Panel>
2015-10-15 23:06:16 -07:00
<Row>
<Col
md={ 6 }
mdOffset={ 3 }>
<h2 className='text-center'>
One more step
</h2>
<div className='spacer' />
You're Awesome! just one more step to go.
Clicking on the link below will redirect to paypal.
</Col>
</Row>
2015-10-25 15:51:59 -07:00
<div className='spacer' />
<Well>
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
<h4>Job Posting</h4>
</Col>
<Col
md={ 6 }>
2015-10-26 18:00:33 -07:00
<h4>+ { price }</h4>
2015-10-25 15:51:59 -07:00
</Col>
</Row>
2015-10-25 18:22:26 -07:00
{ this.renderHighlightPrice(isHighlighted) }
2015-10-26 18:00:33 -07:00
{ this.renderDiscount(discountAmount) }
2015-10-25 15:51:59 -07:00
<Row>
<Col
md={ 3 }
mdOffset={ 3 }>
<h4>Total</h4>
</Col>
<Col
md={ 6 }>
2015-10-25 18:22:26 -07:00
<h4>${
price - discountAmount + (isHighlighted ? 50 : 0)
}</h4>
2015-10-25 15:51:59 -07:00
</Col>
</Row>
</Well>
2015-10-26 17:39:38 -07:00
{ this.renderPromo() }
2015-10-15 23:06:16 -07:00
<div className='spacer' />
<Row>
<Col
md={ 6 }
mdOffset={ 3 }>
<form
action='https://www.sandbox.paypal.com/cgi-bin/webscr'
method='post'
target='_top'>
<input
name='cmd'
type='hidden'
value='_s-xclick' />
<input
name='hosted_button_id'
type='hidden'
2015-10-25 15:51:59 -07:00
value={ buttonId } />
2015-10-15 23:06:16 -07:00
<input
name='custom'
type='hidden'
value={ '' + id } />
<Button
block={ true }
2015-10-25 18:58:58 -07:00
bsSize='large'
2015-10-15 23:06:16 -07:00
className='signup-btn'
type='submit'>
<i className='fa fa-paypal' />
Continue to PayPal
</Button>
<div className='spacer' />
<img
alt='An array of credit cards'
border='0'
src='http://i.imgur.com/Q2SdSZG.png'
style={{
width: '100%'
}} />
</form>
</Col>
</Row>
<div className='spacer' />
</Panel>
</Col>
</Row>
</div>
);
}
})
);