index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { IconButton } from "@material-ui/core";
  3. import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
  4. import FileDownloadIcon from '@mui/icons-material/FileDownload';
  5. import { useState } from "react";
  6. import { timeStampMessage } from '../../../../../../helpers'
  7. const FileViewer = require('react-file-viewer')
  8. const useStyles = makeStyles({
  9. container: {
  10. display: "flex",
  11. justifyContent: "flex-start",
  12. width:'auto',
  13. maxWidth: '80%',
  14. marginBottom:15
  15. },
  16. wrapper: {
  17. position: 'relative',
  18. display: 'flex',
  19. justifyContent: 'space-between',
  20. alignContent: 'center',
  21. alignItems: 'center',
  22. width: 200,
  23. padding: '5px 5px 12px 5px',
  24. backgroundColor: '#ffffff',
  25. borderRadius: 7,
  26. "&:after": {
  27. content: "''",
  28. position: "absolute",
  29. width: "0",
  30. height: "0",
  31. borderBottom: "15px solid #ffffff",
  32. borderLeft: "15px solid transparent",
  33. borderRight: "15px solid transparent",
  34. bottom: '0px',
  35. left: "-15px"
  36. },
  37. "&:before": {
  38. content: "''",
  39. position: "absolute",
  40. width: "0",
  41. height: "0",
  42. borderBottom: "17px solid #ffffff",
  43. borderLeft: "16px solid transparent",
  44. borderRight: "16px solid transparent",
  45. bottom: "0px",
  46. left: "-17px"
  47. }
  48. },
  49. bntDownload: {
  50. backgroundColor: '#ffffff',
  51. color: '#54b0fc',
  52. width: 30,
  53. height:30,
  54. '&:hover': {
  55. backgroundColor: '#54b0fc',
  56. color:'#ffffff'
  57. }
  58. },
  59. title: {
  60. margin: '0 30px 0 5px',
  61. color: '#0e0d0d',
  62. cursor: 'pointer',
  63. '&:hover': {
  64. color: '#54b0fc',
  65. }
  66. },
  67. time: {
  68. position: "absolute",
  69. fontSize: ".65em",
  70. fontWeight:600,
  71. bottom: 0,
  72. right: 6,
  73. color: '#414141',
  74. padding: 3,
  75. borderRadius: 5,
  76. zIndex:10
  77. },
  78. overlay: {
  79. position: 'absolute',
  80. top: 0,
  81. left: 0,
  82. width: '100%',
  83. height:'100%',
  84. zIndex: 100,
  85. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  86. border: 'solid 1px rgba(179, 179, 179, 0.6)',
  87. overflowY: 'hidden'
  88. },
  89. });
  90. interface IMessageLeftFile {
  91. url:string,
  92. updatedAt: string,
  93. }
  94. const MessageLeftFile = ({ url,updatedAt }:IMessageLeftFile) => {
  95. const classes = useStyles();
  96. const [read,setRead] = useState<boolean>(false)
  97. const handleOpenRead = () => !read&&setRead(true)
  98. const handleCloseRead = () => read && setRead(false)
  99. return (
  100. <div className={classes.container}>
  101. {read&&<div className={classes.overlay} id='overlay' onClick={handleCloseRead}>
  102. <FileViewer
  103. allowFullScreen={true}
  104. fileType='pdf'
  105. filePath={url}
  106. onError={handleCloseRead}
  107. />
  108. </div>}
  109. <div className={classes.wrapper}>
  110. <InsertDriveFileIcon fontSize='large' style={{ color: '#99b401' }} />
  111. {!read && <span className={classes.title} onClick={handleOpenRead}>Read File</span>}
  112. <a href={url} target="_blank" rel="noreferrer" download>
  113. <IconButton className={classes.bntDownload} >
  114. <FileDownloadIcon fontSize='medium'/>
  115. </IconButton>
  116. </a>
  117. <div className={classes.time}>{timeStampMessage(updatedAt)}</div>
  118. </div>
  119. </div>
  120. )};
  121. export default MessageLeftFile