import { Box } from "@mui/system"; import defaultGoodImage from "../../images/default-good-image.png"; import { IoCloseOutline } from "react-icons/io5"; import { AiOutlinePlus, AiOutlineMinus } from "react-icons/ai"; import { actionCartChange } from "../../reducers"; import { useEffect, useState } from "react"; import { backendURL, mediaURL } from "../../helpers"; import { Typography, Stack, IconButton, TableCell, TableRow } from "@mui/material"; import { connect } from "react-redux"; export const CartItem = ({ order, onDeleteClick, onChange }) => { const { good, count = 1 } = order || {}; const { _id, images = [], name = "", price = 0, amount = 1 } = good; const [countInput, setCountInput] = useState(count || 1); useEffect(() => { setCountInput(+count); }, [count]); useEffect(() => { onChange(good, +countInput); }, [countInput]); const handleChange = (count) => { if (count >= 0 && count <= 99 && count <= amount) { setCountInput(+count); } }; return ( { currentTarget.onerror = null; currentTarget.src = defaultGoodImage; }} /> {name} {price} ₴ handleChange(countInput - 1)}> {countInput === amount ? `${countInput}(max)` : countInput} handleChange(countInput + 1)}> {price * count} ₴ onDeleteClick({ _id, images, name, price })}> ); }; export const CCartItem = connect(null, { onChange: (good, countInput) => actionCartChange(good, +countInput) })(CartItem);