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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { Box, Button, ButtonGroup, Card, Typography } from '@mui/material';
  2. import { useTranslation } from 'next-i18next';
  3. import Image from 'next/image';
  4. import { useState } from 'react';
  5. const CartCard = ({ product, initialQuantity, remove, updateQuantity }) => {
  6. const [quantity, setQuantity] = useState(initialQuantity);
  7. const { t } = useTranslation('cart');
  8. return (
  9. <Card
  10. sx={{
  11. backgroundColor: '#f2f2f2',
  12. p: 2,
  13. mb: 2,
  14. }}
  15. >
  16. <Box
  17. sx={{
  18. display: 'flex',
  19. flexDirection: { xs: 'column', md: 'row' },
  20. justifyContent: { xs: 'center' },
  21. }}
  22. >
  23. <Box
  24. sx={{
  25. display: 'flex',
  26. justifyContent: 'center',
  27. mb: { xs: 2, md: 0 },
  28. }}
  29. >
  30. <Image src={product.image} alt="profile" width={200} height={200} />
  31. </Box>
  32. <Box
  33. sx={{
  34. display: 'flex',
  35. alignItems: 'center',
  36. justifyItems: 'center',
  37. width: { md: '40%' },
  38. }}
  39. >
  40. <Typography
  41. align="center"
  42. sx={{
  43. mb: { xs: 5, sm: 5, md: 0 },
  44. mr: { md: 5 },
  45. width: '100%',
  46. fontWeight: 600,
  47. fontSize: { xs: 20, sm: 20 },
  48. }}
  49. >
  50. {product?.name}
  51. </Typography>
  52. </Box>
  53. <Box
  54. sx={{
  55. display: 'flex',
  56. flexDirection: { xs: 'row', md: 'column' },
  57. justifyContent: 'center',
  58. alignItems: { xs: 'flex-end', md: 'center' },
  59. mb: { xs: 5, sm: 5, md: 0 },
  60. mr: { md: 5 },
  61. }}
  62. >
  63. <Box
  64. sx={{
  65. display: 'flex',
  66. flexDirection: 'column',
  67. alignItems: 'flex-end',
  68. mr: { xs: 2, md: 0 },
  69. }}
  70. >
  71. <Typography
  72. sx={{
  73. width: '100%',
  74. textAlign: 'center',
  75. height: 16,
  76. fontSize: 14,
  77. }}
  78. >
  79. {t('cart:quantity')}
  80. </Typography>
  81. <ButtonGroup
  82. size="small"
  83. aria-label="small outlined button group"
  84. sx={{
  85. height: 35,
  86. mt: 1,
  87. backgroundColor: 'primary.main',
  88. color: 'white',
  89. border: 0,
  90. }}
  91. >
  92. <Button
  93. sx={{
  94. color: 'white',
  95. fontSize: 17,
  96. width: 25,
  97. }}
  98. onClick={() => {
  99. if (quantity > 1) {
  100. updateQuantity(product?.customID, quantity - 1);
  101. setQuantity((prevState) => prevState - 1);
  102. }
  103. }}
  104. >
  105. -
  106. </Button>
  107. <Button
  108. sx={{
  109. color: 'white',
  110. fontSize: 15,
  111. width: 25,
  112. }}
  113. >
  114. {quantity}
  115. </Button>
  116. <Button
  117. sx={{
  118. color: 'white',
  119. fontSize: 17,
  120. width: 25,
  121. }}
  122. onClick={() => {
  123. updateQuantity(product?.customID, quantity + 1);
  124. setQuantity((prevState) => prevState + 1);
  125. }}
  126. >
  127. +
  128. </Button>
  129. </ButtonGroup>
  130. </Box>
  131. <Button
  132. disableRipple
  133. sx={{
  134. height: 35,
  135. mt: 1,
  136. width: 118,
  137. fontSize: 15,
  138. textTransform: 'none',
  139. backgroundColor: '#C6453E',
  140. color: 'white',
  141. }}
  142. startIcon={
  143. <Image src="/images/x.svg" alt="remove" width={15} height={15} />
  144. }
  145. onClick={() => remove(product.customID)}
  146. >
  147. {t('cart:remove')}
  148. </Button>
  149. </Box>
  150. <Box
  151. sx={{
  152. display: 'flex',
  153. flexDirection: 'column',
  154. justifyContent: 'center',
  155. alignItems: 'center',
  156. }}
  157. >
  158. <Typography
  159. sx={{
  160. width: '100%',
  161. textAlign: 'center',
  162. height: 25,
  163. fontSize: { xs: 15, md: 18 },
  164. }}
  165. >
  166. {t('cart:priceTag')}
  167. {product?.price}
  168. </Typography>
  169. </Box>
  170. </Box>
  171. </Card>
  172. );
  173. };
  174. export default CartCard;