Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5185 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5185 Rev 5187
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React, { useRef, useState } from 'react'
2
import React, { useRef, useState } from 'react'
3
import { axios } from '../../utils'
-
 
4
import { addNotification } from '../../redux/notification/notification.actions'
-
 
5
import { useDispatch } from 'react-redux'
-
 
6
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form'
7
import SendIcon from '@mui/icons-material/Send'
4
import SendIcon from '@mui/icons-material/Send'
8
import AttachFileIcon from '@mui/icons-material/AttachFile'
5
import AttachFileIcon from '@mui/icons-material/AttachFile'
9
import FileModal from '../../mobile-chat/mobile-chat/chat/fileModal/FileModal'
6
import FileModal from '../../mobile-chat/mobile-chat/chat/fileModal/FileModal'
Línea 10... Línea 7...
10
 
7
 
Línea 11... Línea 8...
11
const permittedFiles = 'video/mp4, video/mpeg, video/webm, application/pdf, image/jpeg, image/png, image/jpg'
8
const permittedFiles = 'video/mp4, video/mpeg, video/webm, application/pdf, image/jpeg, image/png, image/jpg'
12
 
9
 
13
const MessageBox = ({ onSend, sendLink, setMsgs }) => {
10
const MessageBox = ({ onSend, sendUrl }) => {
14
  const fileInputEl = useRef(null)
11
  const fileInputEl = useRef(null)
15
  const [selectedFile, setSelectedFile] = useState('')
-
 
Línea 16... Línea 12...
16
  const { handleSubmit, register, reset } = useForm()
12
  const [selectedFile, setSelectedFile] = useState('')
17
  const dispatch = useDispatch()
13
  const { handleSubmit, register, reset } = useForm()
18
 
14
 
19
  const handleUploadFile = (e) => {
15
  const handleUploadFile = (e) => {
Línea 20... Línea 16...
20
    const file = e.target.files[0]
16
    const file = e.target.files[0]
Línea 21... Línea 17...
21
    if (file) setSelectedFile(file)
17
    if (file) setSelectedFile(file)
22
  }
18
  }
23
 
19
 
24
  const removeSelectedFile = () => setSelectedFile('')
-
 
25
 
-
 
26
  const handleSendFile = () => {
-
 
27
    const formData = new FormData()
-
 
28
    formData.append('filename', selectedFile)
-
 
29
    formData.append('message', 'File')
-
 
30
 
20
  const removeSelectedFile = () => setSelectedFile('')
31
    axios.post(sendLink, formData)
-
 
32
      .then(({ data }) => {
-
 
33
        if (!data.success) {
21
 
34
          return dispatch(addNotification({
-
 
35
            style: 'danger',
22
  const handleSendFile = () => {
36
            msg: 'Ha ocurrido un error'
23
    const messages = {
37
          }))
-
 
38
        }
24
      filename: selectedFile,
Línea 39... Línea 25...
39
 
25
      message: 'File'
40
        setMsgs(prev => [data.data, ...prev])
26
    }
41
        setSelectedFile('')
27
    onSend(sendUrl, messages)
42
      })
28
    setSelectedFile('')
Línea 43... Línea 29...
43
  }
29
  }
44
 
30
 
Línea 81... Línea 67...
81
                    file={selectedFile}
67
                    file={selectedFile}
82
                    onCancel={removeSelectedFile}
68
                    onCancel={removeSelectedFile}
83
                    onSend={handleSendFile}
69
                    onSend={handleSendFile}
84
                />
70
                />
85
            }
71
            }
86
        </div >
72
        </div>
87
  )
73
  )
88
}
74
}
89
export default MessageBox
75
export default MessageBox