CartGoodLine.jsx 1.6 KB

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