import React, { useState } from 'react'; import Button from '@mui/material/Button'; import { styled } from '@mui/material/styles'; import { Container, Typography, Grid, CardActionArea, Card, CardContent, CardMedia, AvatarGroup, CardActions, Collapse, IconButton } from '@mui/material'; import { getFullImageUrl } from "./../utills"; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import { AvatarAnimated } from './AvatarAnimated'; import { actionAddGoodToCart } from '../reducers'; import { connect, useDispatch } from 'react-redux'; import { useGetGoodByIdQuery } from '../reducers'; import { useParams } from 'react-router-dom'; import { actionSetCurrentGood } from '../reducers/frontEndReducer'; export const ExpandMore = styled(props => { const { expand, ...other } = props; return ; })(({ theme, expand }) => ({ transform: !expand ? 'rotate(0deg)' : 'rotate(180deg)', marginLeft: 'auto', transition: theme.transitions.create('transform', { duration: theme.transitions.duration.shortest }) })) export const AvatarGroupOriented = styled((props) => { const { vertical, ...other } = props; return ; })(({ theme, vertical }) => (vertical && { display: 'flex', flexDirection: 'column', marginLeft: 10, '& >:first-child': { marginTop: 10, }, '& >*': { marginLeft: 1, marginTop: theme.spacing(1), }, ".MuiAvatar-root": { /*width: 20, height: 20,*/ marginLeft: 1 } })); const Good = ({ /*good = {},*/ maxWidth = 'md', showAddToCard = true, addToCart = undefined }) => { const { _id } = useParams(); const { isLoading, data } = useGetGoodByIdQuery(_id); let good = isLoading ? { name: 'loading', goods: [] } : data?.GoodFindOne; const dispatch = useDispatch(); dispatch(actionSetCurrentGood(_id)); let [currentImageIndex, setCurrentImageIndex] = useState(0); let [expanded, setExpanded] = useState(false); const handleExpandClick = () => setExpanded(!expanded); return good && ( { good.images?.map((image, index) => ( { setCurrentImageIndex(index) }} /> )) } 0 ? getFullImageUrl(good.images[currentImageIndex]) : ''} title={good.name} /> {good.name} {`Price: $${good.price}`} { showAddToCard && ( ) } Description: {good.description} ) } const CGood = connect(state => ({}), { addToCart: actionAddGoodToCart })(Good); export { CGood };