Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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