pd-web/src/views/shops/shopCard.js
ROSHAN GARG 279e8842e9
Some checks failed
NPM Installation / build (16.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (16.x, windows-latest) (push) Has been cancelled
NPM Installation / build (17.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (17.x, windows-latest) (push) Has been cancelled
NPM Installation / build (18.x, ubuntu-latest) (push) Has been cancelled
NPM Installation / build (18.x, windows-latest) (push) Has been cancelled
all requested changs done
2024-11-22 10:59:02 +05:30

36 lines
985 B
JavaScript

/* eslint-disable react/prop-types */
import { Button, Card, CardContent, CardMedia, Typography } from '@mui/material'
import React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { addToCart, selectIsProductInCart } from '../../redux-store/CartStore/ducs'
import Swal from 'sweetalert2'
// eslint-disable-next-line react/prop-types
const ShopCard = ({ item }) => {
const dispatch = useDispatch()
const isProductInCart = useSelector(selectIsProductInCart(item._id))
const handleAddToCart = () => {
if (!isProductInCart) {
dispatch(addToCart(item))
Swal.fire('Product added to cart ')
}
}
return (
<div>
<Button
variant="contained"
color="primary"
// fullWidth
disabled={isProductInCart}
onClick={handleAddToCart}
sx={{ marginTop: '10px' }}
>
{isProductInCart ? 'Already in Cart' : 'Add to Cart'}
</Button>
</div>
)
}
export default ShopCard