TableLine.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import {Box, Button, Grid, Typography} from "@mui/material";
  2. import Link from "react-router-dom/es/Link";
  3. import {backURL} from "../actions/PathDB";
  4. import imgNotFound from "../img/catalog/imgNotFound.png";
  5. import CloseIcon from "@mui/icons-material/Close";
  6. export const ItemHeaderLine = ({text, align='left'}) => {
  7. return (
  8. <Typography
  9. color='#616161'
  10. variant='body1'
  11. letterSpacing='1px'
  12. textAlign={align}
  13. >
  14. {text || ''}
  15. </Typography>
  16. )
  17. }
  18. export const LinkProductItem = ({item: [_id, name, images], children=''}) => {
  19. return (
  20. <Link
  21. style={{
  22. textDecoration: 'none',
  23. display: 'flex',
  24. alignItems: 'center'
  25. }}
  26. to={`/good/${_id}`}
  27. >
  28. <Box
  29. minWidth='60px'
  30. maxWidth='60px'
  31. height='60px'
  32. borderRadius='10px'
  33. overflow='hidden'
  34. marginRight='20px'
  35. >
  36. <img
  37. style={{
  38. width: '100%',
  39. height: '100%',
  40. objectFit: 'cover'
  41. }}
  42. src={
  43. Array.isArray(images) && images[0]?.url ?
  44. backURL + '/' + images[0]?.url
  45. :
  46. imgNotFound
  47. }
  48. alt={name}
  49. />
  50. </Box>
  51. {children ?
  52. <Box
  53. display='flex'
  54. flexDirection='column'
  55. height='50px'
  56. justifyContent='space-around'
  57. >
  58. <ItemHeaderLine text={name}/>
  59. <ItemHeaderLine text={children}/>
  60. </Box>
  61. :
  62. <ItemHeaderLine text={name}/>
  63. }
  64. </Link>
  65. )
  66. }
  67. const AddToCart = ({good, addToCart}) => {
  68. return (
  69. <Button
  70. sx={{
  71. height: '40px',
  72. width: '70%',
  73. borderRadius: '0',
  74. color: '#000',
  75. borderColor: '#000',
  76. fontSize: '16px',
  77. fontWeight: '300'
  78. }}
  79. variant="outlined"
  80. color={"inherit"}
  81. onClick={() => addToCart(good)}
  82. >
  83. ADD TO CART
  84. </Button>
  85. )
  86. }
  87. export const RemoveFromList = ({good, onRemove}) => {
  88. return (
  89. <Button
  90. size="small"
  91. color="inherit"
  92. onClick={() => onRemove(good)}
  93. >
  94. <CloseIcon/>
  95. </Button>
  96. )
  97. }
  98. export const TableLine = ({columnName, role='header', customSizeCol}) => {
  99. const good = {
  100. '_id': columnName[0][0],
  101. 'name': columnName[0][1],
  102. 'images': columnName[0][2],
  103. 'price': columnName[1]
  104. }
  105. return (
  106. <Grid
  107. container
  108. justifyContent='space-between'
  109. marginBottom='20px'
  110. alignItems='center'
  111. >
  112. <Grid
  113. item xs={3}
  114. md={customSizeCol ? customSizeCol[0] : 5}
  115. >
  116. {
  117. role === 'header' ?
  118. <ItemHeaderLine text={columnName[0]}/>
  119. :
  120. <LinkProductItem item={columnName[0]}/>
  121. }
  122. </Grid>
  123. <Grid
  124. item xs={3}
  125. md={customSizeCol ? customSizeCol[1] : 2}
  126. >
  127. <ItemHeaderLine
  128. text={role === 'header' ? columnName[1] : '$'+columnName[1]}
  129. align={'center'}
  130. />
  131. </Grid>
  132. <Grid
  133. item xs={3}
  134. md={customSizeCol ? customSizeCol[2] : 3}
  135. display='flex'
  136. justifyContent='center'
  137. >
  138. {
  139. role === 'header' ?
  140. <ItemHeaderLine text={columnName[3]} align={'center'}/>
  141. :
  142. <AddToCart good={good} addToCart={columnName[3]}/>
  143. }
  144. </Grid>
  145. <Grid
  146. item xs={3}
  147. md={customSizeCol ? customSizeCol[3] : 1}
  148. display='flex'
  149. justifyContent='center'
  150. >
  151. {
  152. role === 'header' ?
  153. <ItemHeaderLine text={columnName[2]} align={'center'}/>
  154. :
  155. <RemoveFromList good={good} onRemove={columnName[2]}/>
  156. }
  157. </Grid>
  158. </Grid>
  159. )
  160. }