import { Box, width } 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 { useDispatch } from 'react-redux'; import { backendURL } from '../../helpers'; const { Typography, Stack, IconButton, TextField, ButtonGroup, Button, TableCell, TableRow, Input, } = require('@mui/material'); export const CartItem = ({ order, onDeleteClick }) => { const { good, count = 1 } = order || {}; const { _id, images = [], name = '', price = 0, amount = 1 } = good; const dispatch = useDispatch(); const [countInput, setCountInput] = useState(count || 1); useEffect(() => { setCountInput(+count); }, [count]); useEffect(() => { dispatch(actionCartChange(good, +countInput)); }, [countInput]); const handleChange = (count) => { if (count >= 0 && count <= 99 && count <= amount) { setCountInput(+count); } }; return ( {name} {price} handleChange(countInput - 1)}> {countInput} handleChange(countInput + 1)}> {price * count} onDeleteClick({ _id, images, name, price })}> ); };