Created
September 12, 2019 17:04
-
-
Save stoneboyindc/29fcb96a95189dc0c33c857667fedf64 to your computer and use it in GitHub Desktop.
Revised Cart component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import Total from './Total'; | |
const USCurrencyFormat = new Intl.NumberFormat('en-US', { | |
style: 'currency', | |
currency: 'USD' | |
}); | |
class Cart extends Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
let summary = null; | |
if (this.props == null || this.props.selected == null) { | |
summary = ""; | |
} else { | |
const summary = Object.keys(this.props.selected).map((feature, idx) => { | |
const featureHash = feature + '-' + idx; | |
const selectedOption = this.props.selected[feature]; | |
return ( | |
<div className="summary__option" key={featureHash}> | |
<div className="summary__option__label">{feature} </div> | |
<div className="summary__option__value">{selectedOption.name}</div> | |
<div className="summary__option__cost"> | |
{USCurrencyFormat.format(selectedOption.cost)} | |
</div> | |
</div> | |
); | |
}); | |
} | |
return ( | |
<section className="main__summary"> | |
<h2>Your cart</h2> | |
{summary} | |
<Total selected={this.props.selected}/> | |
</section> | |
) | |
} | |
} | |
export default Cart; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment