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.tsx 4.8KB

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