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.3KB

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