Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CartCard.jsx 5.2KB

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