Skip to content

Instantly share code, notes, and snippets.

@Y-Taras
Created July 4, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Y-Taras/4c7279a95f232bc5df19f12d0b24138f to your computer and use it in GitHub Desktop.
Save Y-Taras/4c7279a95f232bc5df19f12d0b24138f to your computer and use it in GitHub Desktop.
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