You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CartCard.jsx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { Box, Button, ButtonGroup, Card, Typography } from '@mui/material';
  2. import Image from 'next/image';
  3. import PropType from 'prop-types';
  4. import { useState } from 'react';
  5. const CartCard = ({ product, initialQuantity, remove, updateQuantity }) => {
  6. const [quantity, setQuantity] = useState(initialQuantity);
  7. // useEffect(() => {
  8. // updateQuantity(product?.customID, quantity);
  9. // }, [quantity]);
  10. return (
  11. <Card
  12. sx={{
  13. backgroundColor: '#f2f2f2',
  14. p: 2,
  15. mb: 2,
  16. }}
  17. >
  18. <Box
  19. sx={{
  20. display: 'flex',
  21. flexDirection: { xs: 'column', md: 'row' },
  22. justifyContent: { xs: 'center' },
  23. }}
  24. >
  25. <Box sx={{ display: { xs: 'none', md: 'flex', width: '20%' } }}>
  26. <Image src={product.image} alt="profile" width={500} height={300} />
  27. </Box>
  28. <Box
  29. sx={{
  30. display: 'flex',
  31. alignItems: 'center',
  32. justifyItems: 'center',
  33. width: { md: '40%' },
  34. }}
  35. >
  36. <Typography
  37. align="center"
  38. sx={{
  39. mb: { xs: 10, sm: 5, md: 0 },
  40. mr: { md: 5 },
  41. width: '100%',
  42. fontWeight: 600,
  43. fontSize: { xs: 16, sm: 20 },
  44. }}
  45. >
  46. {product?.name}
  47. </Typography>
  48. </Box>
  49. <Box
  50. sx={{
  51. display: 'flex',
  52. flexDirection: 'column',
  53. justifyContent: 'center',
  54. alignItems: 'center',
  55. mb: { xs: 10, sm: 5, md: 0 },
  56. mr: { md: 5 },
  57. }}
  58. >
  59. <Typography
  60. sx={{
  61. width: '100%',
  62. textAlign: 'center',
  63. height: 16,
  64. fontSize: 14,
  65. }}
  66. >
  67. Quantity
  68. </Typography>
  69. <ButtonGroup
  70. size="small"
  71. aria-label="small outlined button group"
  72. sx={{
  73. height: 35,
  74. mt: 1,
  75. backgroundColor: 'primary.main',
  76. color: 'white',
  77. border: 0,
  78. }}
  79. >
  80. <Button
  81. sx={{
  82. color: 'white',
  83. fontSize: 17,
  84. width: 25,
  85. }}
  86. onClick={() => {
  87. if (quantity > 0) {
  88. updateQuantity(product?.customID, quantity - 1);
  89. setQuantity((prevState) => prevState - 1);
  90. }
  91. }}
  92. >
  93. -
  94. </Button>
  95. <Button
  96. sx={{
  97. color: 'white',
  98. fontSize: 15,
  99. width: 25,
  100. }}
  101. >
  102. {quantity}
  103. </Button>
  104. <Button
  105. sx={{
  106. color: 'white',
  107. fontSize: 17,
  108. width: 25,
  109. }}
  110. onClick={() => {
  111. updateQuantity(product?.customID, quantity + 1);
  112. setQuantity((prevState) => prevState + 1);
  113. }}
  114. >
  115. +
  116. </Button>
  117. </ButtonGroup>
  118. <Button
  119. disableRipple
  120. sx={{
  121. height: 35,
  122. mt: 1,
  123. width: 118,
  124. fontSize: 15,
  125. textTransform: 'none',
  126. backgroundColor: '#C6453E',
  127. color: 'white',
  128. }}
  129. startIcon={
  130. <Image src="/images/x.svg" alt="remove" width={15} height={15} />
  131. }
  132. onClick={() => remove(product.customID)}
  133. >
  134. Remove
  135. </Button>
  136. </Box>
  137. <Box
  138. sx={{
  139. display: 'flex',
  140. flexDirection: 'column',
  141. justifyContent: 'center',
  142. alignItems: 'center',
  143. }}
  144. >
  145. <Typography
  146. sx={{
  147. width: '100%',
  148. textAlign: 'center',
  149. height: 25,
  150. fontSize: { xs: 15, md: 18 },
  151. }}
  152. >
  153. Price: ${product?.price}
  154. </Typography>
  155. </Box>
  156. </Box>
  157. </Card>
  158. );
  159. };
  160. CartCard.propTypes = {
  161. product: PropType.shape({
  162. category: PropType.string,
  163. name: PropType.string,
  164. image: PropType.string,
  165. description: PropType.string,
  166. place: PropType.string,
  167. people: PropType.string,
  168. process: PropType.string,
  169. pairing: PropType.string,
  170. available: PropType.Boolean,
  171. isFeatured: PropType.Boolean,
  172. price: PropType.number,
  173. customID: PropType.string,
  174. }),
  175. initialQuantity: PropType.number,
  176. remove: PropType.func,
  177. updateQuantity: PropType.func,
  178. };
  179. export default CartCard;