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.

ProductInfo.jsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { Button, ButtonGroup, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useTranslation } from 'next-i18next';
  4. import Image from 'next/image';
  5. import PropType from 'prop-types';
  6. import { useState } from 'react';
  7. const ProductInfo = ({ data, bColor, addProductToCart, inCart }) => {
  8. const { t } = useTranslation('home');
  9. const [quantity, setQuantity] = useState(1);
  10. const handleIncrement = () => {
  11. setQuantity((prevState) => prevState + 1);
  12. };
  13. const handleDecrement = () => {
  14. if (quantity > 1) {
  15. setQuantity((prevState) => prevState - 1);
  16. }
  17. };
  18. return (
  19. <Box
  20. sx={{
  21. display: 'flex',
  22. flexDirection: 'column',
  23. alignItems: { xs: 'center', md: 'flex-start' },
  24. width: { xs: '100%', md: '50%' },
  25. height: '100%',
  26. }}
  27. >
  28. <Typography variant="h3" sx={{ mt: { xs: 5 }, color: 'white' }}>
  29. {data.name}
  30. </Typography>
  31. <Box
  32. sx={{
  33. display: 'flex',
  34. alignItems: { xs: 'center', md: 'flex-start' },
  35. justifyContent: { xs: 'center', md: 'flex-start' },
  36. width: '100%',
  37. py: { xs: 2 },
  38. }}
  39. >
  40. <Image
  41. src="/images/Stars.svg"
  42. alt="reviews"
  43. width={100}
  44. height={50}
  45. ></Image>
  46. </Box>
  47. <Typography
  48. sx={{
  49. color: 'white',
  50. }}
  51. >
  52. {data.description}
  53. </Typography>
  54. <Box
  55. sx={{
  56. width: '100%',
  57. display: 'flex',
  58. mt: 6,
  59. flexDirection: { md: 'row' },
  60. alignItems: { xs: 'center' },
  61. justifyContent: { xs: 'center', md: 'flex-start' },
  62. }}
  63. >
  64. <ButtonGroup
  65. disabled={inCart}
  66. size="small"
  67. aria-label="small outlined button group"
  68. sx={{
  69. height: 50,
  70. backgroundColor: bColor === 'light' ? '#664c47' : '#8f7772',
  71. color: 'white',
  72. border: 0,
  73. }}
  74. >
  75. <Button
  76. disableRipple
  77. sx={{
  78. '&.Mui-disabled': {
  79. color: 'rgba(255, 255, 255, 0.6)',
  80. },
  81. color: 'white',
  82. fontSize: 20,
  83. width: 50,
  84. }}
  85. onClick={() => {
  86. handleDecrement();
  87. }}
  88. >
  89. -
  90. </Button>
  91. <Button
  92. disableRipple
  93. sx={{
  94. '&.Mui-disabled': {
  95. color: 'rgba(255, 255, 255, 0.6)',
  96. },
  97. color: 'white',
  98. fontSize: 17,
  99. width: 50,
  100. }}
  101. >
  102. {quantity}
  103. </Button>
  104. <Button
  105. disableRipple
  106. sx={{
  107. '&.Mui-disabled': {
  108. color: 'rgba(255, 255, 255, 0.6)',
  109. },
  110. color: 'white',
  111. fontSize: 20,
  112. width: 50,
  113. }}
  114. onClick={() => {
  115. handleIncrement();
  116. }}
  117. >
  118. +
  119. </Button>
  120. </ButtonGroup>
  121. <Button
  122. disableRipple
  123. sx={{
  124. mt: { md: 0 },
  125. ml: { xs: 2 },
  126. backgroundColor: '#CBA213',
  127. height: 50,
  128. width: 150,
  129. color: 'white',
  130. '&.Mui-disabled': {
  131. backgroundColor: '#f2d675',
  132. color: '#464646',
  133. },
  134. '&:hover': {
  135. backgroundColor: '#f2d675',
  136. color: '#464646',
  137. boxShadow: 'none',
  138. },
  139. }}
  140. disabled={inCart}
  141. onClick={() => addProductToCart(quantity)}
  142. >
  143. {inCart ? t('home:in') : t('home:add')}
  144. </Button>
  145. </Box>
  146. </Box>
  147. );
  148. };
  149. ProductInfo.propTypes = {
  150. data: PropType.shape({
  151. name: PropType.string,
  152. description: PropType.string,
  153. }),
  154. bColor: PropType.string,
  155. side: PropType.string,
  156. addProductToCart: PropType.func,
  157. inCart: PropType.bool,
  158. };
  159. export default ProductInfo;