Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 1904 Rev 1921
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect } from 'react'
2
import { useSelector } from 'react-redux'
2
import { useDispatch, useSelector } from 'react-redux'
3
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form'
Línea -... Línea 4...
-
 
4
 
-
 
5
import { axios } from '@app/utils'
-
 
6
import { addNotification } from '@app/redux/notification/notification.actions'
4
 
7
 
5
import Modal from '../modal/Modal'
8
import Modal from '../modal/Modal'
6
import DropzoneComponent from '../../dropzone/DropzoneComponent'
9
import DropzoneComponent from '../../dropzone/DropzoneComponent'
Línea 7... Línea 10...
7
import FormErrorFeedback from '../form/FormErrorFeedback'
10
import FormErrorFeedback from '../form/FormErrorFeedback'
8
 
11
 
9
const CoverModal = ({
12
const CoverModal = ({
10
  show = false,
13
  show = false,
11
  sizes = '',
14
  sizes = '',
-
 
15
  onClose = () => {},
12
  onClose = () => {},
16
  onChange = () => {},
13
  onConfirm = async () => {}
17
  url = ''
-
 
18
}) => {
Línea 14... Línea 19...
14
}) => {
19
  const labels = useSelector(({ intl }) => intl.labels)
Línea 15... Línea 20...
15
  const labels = useSelector(({ intl }) => intl.labels)
20
  const dispatch = useDispatch()
16
 
21
 
17
  const { register, errors, handleSubmit, setValue } = useForm()
22
  const { register, errors, handleSubmit, setValue, reset } = useForm()
Línea 18... Línea 23...
18
 
23
 
-
 
24
  const onUploadedHandler = (files) => {
-
 
25
    setValue('cover', files)
-
 
26
  }
-
 
27
 
-
 
28
  const onSubmit = handleSubmit(({ cover }) => {
-
 
29
    const formData = new FormData()
-
 
30
    formData.append('cover', cover)
-
 
31
 
-
 
32
    axios
-
 
33
      .post(url, formData)
-
 
34
      .then(({ data: response }) => {
-
 
35
        const { data, success } = response
-
 
36
 
-
 
37
        if (!success) {
-
 
38
          const errorMessage =
-
 
39
            typeof data === 'string' ? data : 'Intente mas tarde'
-
 
40
          throw new Error(errorMessage)
-
 
41
        }
-
 
42
 
-
 
43
        onChange(data)
-
 
44
        onClose()
-
 
45
        reset()
-
 
46
      })
Línea 19... Línea 47...
19
  const onUploadedHandler = (files) => {
47
      .catch((error) => {
20
    setValue('cover', files)
48
        console.log(error)
21
  }
49
        dispatch(addNotification({ style: 'danger', msg: error.message }))
22
 
50
      })