Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 1979 Rev 2521
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect } from 'react'
2
import { useDispatch, 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'
4
import { CKEditor } from 'ckeditor4-react'
-
 
Línea 5... Línea 4...
5
 
4
 
6
import { CKEDITOR_OPTIONS, axios } from 'utils/index'
5
import { axios } from 'utils/index'
Línea -... Línea 6...
-
 
6
import { addNotification } from '../../redux/notification/notification.actions'
7
import { addNotification } from '../../redux/notification/notification.actions'
7
 
8
 
8
import CKEditor from '@app/components/UI/Ckeditor'
Línea 9... Línea 9...
9
import Modal from 'components/UI/modal/Modal'
9
import Modal from 'components/UI/modal/Modal'
10
import FormErrorFeedback from 'components/UI/form/FormErrorFeedback'
10
import FormErrorFeedback from 'components/UI/form/FormErrorFeedback'
Línea 23... Línea 23...
23
 
23
 
24
  const onSubmit = handleSubmit(({ description }) => {
24
  const onSubmit = handleSubmit(({ description }) => {
25
    const formData = new FormData()
25
    const formData = new FormData()
Línea 26... Línea -...
26
    formData.append('description', description)
-
 
27
 
-
 
28
    axios
26
    formData.append('description', description)
29
      .post(url, formData)
27
 
30
      .then((response) => {
28
    axios.post(url, formData).then((response) => {
31
        const { data, success } = response.data
29
      const { data, success } = response.data
32
 
30
 
33
        if (!success) {
31
      if (!success) {
34
          const errorMessage =
32
        const errorMessage =
35
            typeof data === 'string'
33
          typeof data === 'string'
36
              ? data
34
            ? data
37
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
35
            : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
38
 
36
 
39
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
37
        dispatch(addNotification({ style: 'danger', msg: errorMessage }))
40
          return
38
        return
41
        }
39
      }
42
 
40
 
43
        onComplete(data)
41
      onComplete(data)
44
        onClose()
42
      onClose()
Línea 45... Línea 43...
45
      })
43
    })
46
  })
44
  })
47
 
45
 
Línea 61... Línea 59...
61
      show={show}
59
      show={show}
62
      onClose={onClose}
60
      onClose={onClose}
63
      onAccept={onSubmit}
61
      onAccept={onSubmit}
64
    >
62
    >
65
      <CKEditor
63
      <CKEditor
66
        onChange={(e) => setValue('description', e.editor.getData())}
64
        defaultValue={currentAnswer}
67
        onInstanceReady={(e) => e.editor.setData(currentAnswer)}
65
        onChange={(value) => setValue('description', value)}
68
        config={CKEDITOR_OPTIONS}
-
 
69
      />
66
      />
70
      {errors.description && (
67
      {errors.description && (
71
        <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
68
        <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
72
      )}
69
      )}
73
 
-
 
74
    </Modal>
70
    </Modal>
75
  )
71
  )
76
}
72
}
Línea 77... Línea 73...
77
 
73