Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 1979 Rev 2459
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from 'react'
2
import { Link } from 'react-router-dom'
2
import { Link } from 'react-router-dom'
3
import { axios } from '../../utils'
-
 
4
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form'
5
import { useDispatch } from 'react-redux'
-
 
6
import { addNotification } from '../../redux/notification/notification.actions'
-
 
7
import styled from 'styled-components'
4
import styled from 'styled-components'
8
import SendIcon from '@mui/icons-material/Send'
5
import SendIcon from '@mui/icons-material/Send'
9
import IconButton from '@mui/material/IconButton'
6
import IconButton from '@mui/material/IconButton'
10
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
7
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
11
import AttachFileIcon from '@mui/icons-material/AttachFile'
8
import AttachFileIcon from '@mui/icons-material/AttachFile'
Línea 105... Línea 102...
105
      <StyledTitle>{children}</StyledTitle>
102
      <StyledTitle>{children}</StyledTitle>
106
    </Link>
103
    </Link>
107
  )
104
  )
108
}
105
}
Línea 109... Línea 106...
109
 
106
 
110
const SubmitForm = ({ sendUrl, uploadUrl, onSubmit: onComplete }) => {
107
const SubmitForm = ({ onSend }) => {
111
  const [showEmojione, setShowEmojione] = useState(false)
108
  const [showEmojione, setShowEmojione] = useState(false)
112
  const [isShowFileModal, setIsShowFileModal] = useState(false)
109
  const [isShowFileModal, setIsShowFileModal] = useState(false)
113
  const [isSending, setIsSending] = useState(false)
-
 
Línea 114... Línea 110...
114
  const dispatch = useDispatch()
110
  const [isSending, setIsSending] = useState(false)
Línea 115... Línea 111...
115
 
111
 
116
  const { handleSubmit, setValue, register, reset, getValues } = useForm()
-
 
117
 
-
 
118
  const onSubmit = handleSubmit(({ message }) => {
-
 
119
    const formData = new FormData()
-
 
120
 
-
 
121
    formData.append('message', emojione.toShort(message))
-
 
122
 
-
 
123
    axios.post(sendUrl, formData).then((response) => {
-
 
124
      const { success, data } = response.data
-
 
125
 
-
 
126
      if (!success) {
-
 
127
        const errorMessage =
-
 
128
          typeof data === 'string' ? data : 'Ha ocurrido un error'
-
 
129
 
-
 
130
        setShowEmojione(false)
-
 
131
        dispatch(addNotification({ style: 'danger', msg: errorMessage }))
-
 
132
        return
-
 
133
      }
112
  const { handleSubmit, setValue, register, reset, getValues } = useForm()
134
 
113
 
135
      setShowEmojione(false)
-
 
136
      onComplete()
114
  const onSubmit = handleSubmit(({ message }) => {
Línea 137... Línea 115...
137
      reset()
115
    onSend(message)
138
    })
116
    reset()
139
  })
-
 
140
 
-
 
141
  const sendFile = (file) => {
-
 
142
    setIsSending(true)
-
 
143
    const formData = new FormData()
-
 
144
    formData.append('file', file)
-
 
145
 
-
 
146
    axios
-
 
147
      .post(uploadUrl, formData)
-
 
148
      .then(({ data: response }) => {
-
 
149
        const { success, data } = response
-
 
150
        if (!success) {
-
 
151
          const errorMessage =
-
 
152
            typeof data === 'string' ? data : 'Ha ocurrido un error'
-
 
153
          dispatch(addNotification({ style: 'success', msg: errorMessage }))
-
 
154
          return
117
  })
155
        }
-
 
156
 
-
 
157
        toggleFileModal()
118
 
Línea 158... Línea 119...
158
        onComplete()
119
  const sendFile = (file) => {
159
      })
120
    setIsSending(true)
160
      .finally(() => setIsSending(false))
121
    onSend(file)