Created
July 4, 2017 11:50
-
-
Save Y-Taras/4c7279a95f232bc5df19f12d0b24138f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 from "react"; | |
import PropTypes from 'prop-types' | |
import {Card, CardImg, CardBlock, CardTitle, CardText, Button} from 'reactstrap'; | |
const ProductCard = ({elem, cartIds, quantity, addItemToCart, history}) => ( | |
<Card className="m-1" style={{width: '18rem'}} | |
onClick={() => { | |
history.push(`/products/${elem.id}`) | |
}}> | |
<CardImg top width="100%" src={`/public/img/${elem.image}`} alt="Card image cap"/> | |
<CardBlock> | |
<CardTitle>{elem.name}</CardTitle> | |
<CardText>{elem.price}</CardText> | |
<CardText>isAvailable</CardText> | |
<CardText>{JSON.stringify(cartIds, null, 4)}</CardText> | |
<CardText>{JSON.stringify(quantity, null, 4)}</CardText> | |
{(cartIds.indexOf(elem.id) === -1) ? | |
<Button | |
onClick={() => {event.stopPropagation(); addItemToCart(elem.id)}}>Add to Cart</Button> : | |
<Button>Remove from Cart</Button>} | |
</CardBlock> | |
</Card> | |
); | |
export default ProductCard; | |
ProductCard.propTypes = { | |
elem: PropTypes.shape({ | |
name: PropTypes.string, | |
price: PropTypes.number, | |
id: PropTypes.string | |
}).isRequired, | |
cartIds: PropTypes.arrayOf(PropTypes.string).isRequired, | |
addItemToCart: PropTypes.func.isRequired, | |
quantity: PropTypes.objectOf(PropTypes.number).isRequired, | |
history: PropTypes.shape({ | |
push: PropTypes.func | |
}).isRequired, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment