CategoryFound.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React from 'react';
  2. import {useState} from "react";
  3. import {Button} from "@mui/material";
  4. import Box from "@mui/material/Box";
  5. import Typography from "@mui/material/Typography";
  6. import {CCategoryEdit} from "./CategoryEdit";
  7. import {timeCalc} from "../../ProductPage/timeCalc";
  8. export const CategoryFound = ({item}) => {
  9. let [state, setState] = useState(false)
  10. let formattedTime = 0;
  11. if (['createdAt'] in item) {
  12. formattedTime = timeCalc(+item.createdAt);
  13. }
  14. return (
  15. !state ?
  16. <Button
  17. fullWidth
  18. sx={{
  19. display: 'flex',
  20. justifyContent:'center',
  21. alignItems: 'center',
  22. marginBottom: '20px',
  23. border: '1px dashed #616161',
  24. borderRadius: '20px',
  25. padding: '20px'
  26. }}
  27. onClick={() => setState(true)}
  28. >
  29. <Box sx={{
  30. display: 'flex',
  31. flexDirection: 'column',
  32. justifyContent: 'space-between',
  33. alignItems: 'flex-start'
  34. }}>
  35. <Typography
  36. color='#000'
  37. letterSpacing='1px'
  38. fontFamily='sarif'
  39. fontWeight='600'
  40. variant='h6'
  41. >
  42. {item?.name || 'no name'}
  43. </Typography>
  44. <Typography
  45. letterSpacing='1px'
  46. variant='body1'
  47. fontWeight='300'
  48. color='#616161'
  49. margin='10px 0'
  50. >
  51. { formattedTime
  52. ? `Time of creation: ${formattedTime}`
  53. : ''
  54. }
  55. </Typography>
  56. <Typography
  57. color='#000'
  58. letterSpacing='1px'
  59. variant='body1'
  60. fontWeight='600'
  61. >
  62. { item?.goods?.length
  63. ? `Count of goods: ${item?.goods?.length}`
  64. : ''
  65. }
  66. </Typography>
  67. <Typography
  68. color='#000'
  69. letterSpacing='1px'
  70. variant='body1'
  71. fontWeight='600'
  72. >
  73. { item?.subCategories?.length
  74. ? `Count of sub categories: ${item?.subCategories?.length}`
  75. : ''
  76. }
  77. </Typography>
  78. </Box>
  79. </Button>
  80. :
  81. <Box
  82. sx={{
  83. marginBottom: '30px',
  84. border: '1px solid #616161',
  85. borderRadius: '10px',
  86. padding: '30px 20px'
  87. }}
  88. >
  89. <CCategoryEdit entity={{...item}}/>
  90. <Button
  91. variant='outlined'
  92. sx={{marginTop: '30px'}}
  93. fullWidth
  94. onClick={() => setState(false)}
  95. >
  96. Cansel
  97. </Button>
  98. </Box>
  99. )
  100. }