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

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