Skip to content

Instantly share code, notes, and snippets.

@puppybits
Forked from mjackson/ternary.js
Last active March 5, 2016 05:59
Show Gist options
  • Save puppybits/65408bbc36fa3d978ca1 to your computer and use it in GitHub Desktop.
Save puppybits/65408bbc36fa3d978ca1 to your computer and use it in GitHub Desktop.
const PurchaseComplete = (props) =>
(<div className="purchase-complete">
<h2>Thanks!</h2>
<p>
Thank you for your purchase of {formatPrice(this.state.total)}.
We’ll send you a receipt shortly.
</p>
<p>
<button
className="cta-button outlined-button"
onClick={() => this.replaceState(this.getInitialState())}
>
Buy more tickets
</button>
</p>
</div>)
const PromoAvailable = (props) =>
(<PurchaseBlock
price={promo}
regularPrice={regular}
title={`Promo: ${query.c}`}
getAvailableSeats={() => getAvailableSeatsWithPromo(training, promo)}
onPurchase={this.purchaseWithPromo}
/>)
const EarlyBirdAvailable = (props) =>
(<PurchaseBlock
price={earlyBird}
regularPrice={regular}
title="Early Bird Price"
getAvailableSeats={() => getAvailableSeats(training)}
onPurchase={this.purchaseEarlyBird}
/>)
const PurchaseBlock = (props) =>
(<PurchaseBlock
price={regular}
title="Ticket Price"
getAvailableSeats={() => getAvailableSeats(training)}
onPurchase={this.purchaseRegular}
/>)
render(){
// or a bit fancier/cleaner, a self-executing function w/ a switch that returns a stateless component
return <div className="pricing" style={{ opacity: purchasing ? 0.25 : '' }}>
{(props => {
switch(props.enum){
case "PurchaseComplete":
return <PurchaseComplete {...props} />
case "PromoAvailable":
return <PromoAvailable {...props} />
case "EarlyBirdAvailable":
return <EarlyBirdAvailable {...props} />
default:
return <PurchaseBlock {...props} />
}
})(this.props)}
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment