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 5.1KB

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