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 5.1KB

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