Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 4353 Rev 5185
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';
3
import { axios } from '../../utils'
4
import { addNotification } from '../../redux/notification/notification.actions';
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import { useDispatch } from 'react-redux';
5
import { useDispatch } from 'react-redux'
6
import { useForm } from 'react-hook-form';
6
import { useForm } from 'react-hook-form'
7
import SendIcon from '@mui/icons-material/Send';
7
import SendIcon from '@mui/icons-material/Send'
8
import AttachFileIcon from '@mui/icons-material/AttachFile';
8
import AttachFileIcon from '@mui/icons-material/AttachFile'
9
import FileModal from '../../mobile-chat/mobile-chat/chat/fileModal/FileModal';
9
import FileModal from '../../mobile-chat/mobile-chat/chat/fileModal/FileModal'
10
 
10
 
11
const permittedFiles = "video/mp4, video/mpeg, video/webm, application/pdf, image/jpeg, image/png, image/jpg";
11
const permittedFiles = 'video/mp4, video/mpeg, video/webm, application/pdf, image/jpeg, image/png, image/jpg'
12
 
12
 
13
const MessageBox = ({ onSend, backendVars, sendLink, setMsgs }) => {
13
const MessageBox = ({ onSend, sendLink, setMsgs }) => {
14
 
-
 
15
    const fileInputEl = useRef(null);
14
  const fileInputEl = useRef(null)
16
    const [selectedFile, setSelectedFile] = useState("");
15
  const [selectedFile, setSelectedFile] = useState('')
17
    const { handleSubmit, register, reset } = useForm()
16
  const { handleSubmit, register, reset } = useForm()
18
    const dispatch = useDispatch()
17
  const dispatch = useDispatch()
19
 
18
 
20
    const handleUploadFile = (e) => {
19
  const handleUploadFile = (e) => {
21
        const file = e.target.files[0];
20
    const file = e.target.files[0]
22
        if (file) setSelectedFile(file)
21
    if (file) setSelectedFile(file)
23
    };
22
  }
24
 
23
 
25
    const removeSelectedFile = () => setSelectedFile("")
24
  const removeSelectedFile = () => setSelectedFile('')
26
 
25
 
27
    const handleSendFile = () => {
26
  const handleSendFile = () => {
28
        const formData = new FormData();
27
    const formData = new FormData()
29
        formData.append("filename", selectedFile);
28
    formData.append('filename', selectedFile)
30
        formData.append("message", 'File');
29
    formData.append('message', 'File')
31
 
30
 
32
        axios.post(sendLink, formData)
31
    axios.post(sendLink, formData)
33
            .then(({ data }) => {
32
      .then(({ data }) => {
34
                if (!data.success) {
33
        if (!data.success) {
35
                    return dispatch(addNotification({
34
          return dispatch(addNotification({
36
                        style: "danger",
35
            style: 'danger',
37
                        msg: "Ha ocurrido un error"
36
            msg: 'Ha ocurrido un error'
38
                    }))
37
          }))
39
                }
38
        }
40
 
39
 
41
                setMsgs(prev => [data.data, ...prev])
40
        setMsgs(prev => [data.data, ...prev])
42
                setSelectedFile("");
41
        setSelectedFile('')
43
            });
42
      })
44
    };
43
  }
45
 
44
 
46
    const handleSend = ({ message }) => {
45
  const handleSend = ({ message }) => {
47
        onSend(message)
46
    onSend(message)
48
        reset()
47
    reset()
49
    }
48
  }
Línea 50... Línea 49...
50
 
49
 
51
    return (
50
  return (
52
        <div className="chat__input-container">
51
        <div className="chat__input-container">
53
            <form onSubmit={handleSubmit(handleSend)}>
52
            <form onSubmit={handleSubmit(handleSend)}>
54
                <input
53
                <input
55
                    type="file"
54
                    type="file"
Línea 69... Línea 68...
69
                <input
68
                <input
70
                    type="text"
69
                    type="text"
71
                    name="message"
70
                    name="message"
72
                    className="chatInput"
71
                    className="chatInput"
73
                    ref={register({ required: true })}
72
                    ref={register({ required: true })}
74
                    placeholder={backendVars.labelWriteMessage}
73
                    placeholder={LABELS.WRITE_YOUR_MESSAGE_HERE}
75
                />
74
                />
76
                <button type="submit" className="send_btn">
75
                <button type="submit" className="send_btn">
77
                    <SendIcon />
76
                    <SendIcon />
78
                </button>
77
                </button>
79
            </form>
78
            </form>
Línea 83... Línea 82...
83
                    onCancel={removeSelectedFile}
82
                    onCancel={removeSelectedFile}
84
                    onSend={handleSendFile}
83
                    onSend={handleSendFile}
85
                />
84
                />
86
            }
85
            }
87
        </div >
86
        </div >
88
    )
87
  )
89
}
88
}
90
export default MessageBox
-
 
91
89
export default MessageBox
-
 
90