import React, { useState } from 'react'; import { Link, Redirect } from 'react-router-dom'; import ShowImage from './ShowImage'; import moment from 'moment'; // eslint-disable-next-line import ModalVideo from 'react-modal-video'; import { addItem, updateItem, removeItem } from './cartHelpers'; import StarRating from './StarRating'; import './../../node_modules/react-modal-video/scss/modal-video.scss'; const Card = ({ product, showViewProductButton = true, showAddToCartButton = true, cartUpdate = false, showRemoveProductButton = false, setRun = f => f, run = undefined // changeCartSize }) => { const [redirect, setRedirect] = useState(false); const [count, setCount] = useState(product.count); const showViewButton = showViewProductButton => { return ( showViewProductButton && ( ) ); }; const addToCart = () => { // console.log('added'); addItem(product, setRedirect(true)); }; const shouldRedirect = redirect => { if (redirect) { return ; } }; const showAddToCartBtn = showAddToCartButton => { return ( showAddToCartButton && ( ) ); }; const showStock = quantity => { return quantity > 0 ? ( In season ) : ( Out of Season ); }; const handleChange = productId => event => { setRun(!run); // run useEffect in parent Cart setCount(event.target.value < 1 ? 1 : event.target.value); if (event.target.value >= 1) { updateItem(productId, event.target.value); } }; const showCartUpdateOptions = cartUpdate => { return ( cartUpdate && (
Adjust Quantity
) ); }; const showRemoveButton = showRemoveProductButton => { return ( showRemoveProductButton && ( ) ); }; return (
{shouldRedirect(redirect)} {/* */}
{product.name}
{product.subname}

Price : ₹ {product.price}

{product.description.substring(0, 400)}

{showViewButton(showViewProductButton)} {showAddToCartBtn(showAddToCartButton)} {showRemoveButton(showRemoveProductButton)} {showCartUpdateOptions(cartUpdate)}
{showStock(product.quantity)}

Added on {moment(product.createdAt).fromNow()}

Category: {product.category && product.category.name}

); }; export default Card;