CartGoodLine.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {useEffect, useState} from "react";
  2. import {Grid, Typography} from "@mui/material";
  3. import {ItemHeaderLine, LinkProductItem, RemoveFromList} from "../../components/TableLine";
  4. import {SetCount} from "../../components/SetCount";
  5. export const CartGoodLine = ({item, onCartRemove, onCardChange}) => {
  6. let [count, setCount] = useState(item?.count)
  7. useEffect(() => {
  8. onCardChange(item?.good, count)
  9. }, [count])
  10. return(
  11. <Grid
  12. container
  13. alignItems='center'
  14. marginBottom='20px'
  15. >
  16. <Grid item xs={6}>
  17. <LinkProductItem
  18. item={[item?.good?._id, item?.good?.name, item?.good?.images]}
  19. children={`$${ item?.good?.price }`}
  20. />
  21. </Grid>
  22. <Grid item xs={3}
  23. display='flex'
  24. justifyContent="center"
  25. >
  26. <SetCount
  27. height={40}
  28. width={40}
  29. defaultValue={item?.count}
  30. onCount={value => setCount(value)}
  31. />
  32. </Grid>
  33. <Grid item xs={2}>
  34. <ItemHeaderLine
  35. align={'center'}
  36. text={(`$${parseFloat(item?.good?.price * count).toFixed(2)}`) || 'NaN'}
  37. />
  38. </Grid>
  39. <Grid item xs={1}>
  40. <RemoveFromList
  41. good={item?.good}
  42. onRemove={onCartRemove}
  43. />
  44. </Grid>
  45. </Grid>
  46. )
  47. }