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

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