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, useState } from 'react'
1
import React, { useEffect, useState } 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'
-
 
5
import { Form } from 'react-bootstrap'
4
import { Form } from 'react-bootstrap'
6
import { Box } from '@mui/material'
5
import { Box } from '@mui/material'
Línea 7... Línea 6...
7
 
6
 
8
import { CKEDITOR_OPTIONS, axios } from 'utils/index'
7
import { axios } from 'utils/index'
Línea -... Línea 8...
-
 
8
import { addNotification } from '../../redux/notification/notification.actions'
9
import { addNotification } from '../../redux/notification/notification.actions'
9
 
10
 
10
import CKEditor from '@app/components/UI/Ckeditor'
11
import Modal from 'components/UI/modal/Modal'
11
import Modal from 'components/UI/modal/Modal'
Línea 12... Línea 12...
12
import TagsInput from 'components/UI/TagsInput'
12
import TagsInput from 'components/UI/TagsInput'
13
import FormErrorFeedback from 'components/UI/form/FormErrorFeedback'
13
import FormErrorFeedback from 'components/UI/form/FormErrorFeedback'
14
 
14
 
15
const QuestionModal = ({ show, url, isEdit, onClose, onComplete }) => {
15
const QuestionModal = ({ show, url, isEdit, onClose, onComplete }) => {
16
  const [questionsCategories, setQuestionsCategories] = useState([])
16
  const [questionsCategories, setQuestionsCategories] = useState([])
Línea 17... Línea 17...
17
  const [currentCategories, setCurrentCategories] = useState([])
17
  const [currentCategories, setCurrentCategories] = useState([])
-
 
18
  const labels = useSelector(({ intl }) => intl.labels)
Línea 18... Línea 19...
18
  const labels = useSelector(({ intl }) => intl.labels)
19
  const dispatch = useDispatch()
19
  const dispatch = useDispatch()
20
 
Línea 20... Línea 21...
20
 
21
  const { register, handleSubmit, setValue, errors, watch } = useForm()
21
  const { register, handleSubmit, getValues, setValue, errors } = useForm()
22
  const watchedDescription = watch('description')
Línea 22... Línea -...
22
 
-
 
23
  const onSubmit = handleSubmit(({ category_id, ...data }) => {
-
 
24
    const formData = new FormData()
23
 
25
 
24
  const onSubmit = handleSubmit(({ category_id, ...data }) => {
Línea 26... Línea 25...
26
    category_id.map((value) => formData.append('category_id[]', value))
25
    const formData = new FormData()
27
    Object.entries(data).map(([key, value]) => formData.append(key, value))
26
 
28
 
27
    category_id.map((value) => formData.append('category_id[]', value))
29
    axios
28
    Object.entries(data).map(([key, value]) => formData.append(key, value))
30
      .post(url, formData)
29
 
Línea 31... Línea 30...
31
      .then((response) => {
30
    axios.post(url, formData).then((response) => {
32
        const { data, success } = response.data
31
      const { data, success } = response.data
33
 
32
 
Línea 34... Línea 33...
34
        if (!success) {
33
      if (!success) {
35
          const errorMessage =
34
        const errorMessage =
36
            typeof data === 'string'
35
          typeof data === 'string'
37
              ? data
36
            ? data
Línea 38... Línea 37...
38
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
37
            : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
39
 
38
 
40
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
39
        dispatch(addNotification({ style: 'danger', msg: errorMessage }))
Línea 162... Línea 161...
162
          <FormErrorFeedback>{errors.category_id?.message}</FormErrorFeedback>
161
          <FormErrorFeedback>{errors.category_id?.message}</FormErrorFeedback>
163
        )}
162
        )}
164
      </Box>
163
      </Box>
Línea 165... Línea 164...
165
 
164
 
166
      <CKEditor
165
      <CKEditor
167
        onChange={(e) => setValue('description', e.editor.getData())}
166
        defaultValue={watchedDescription}
168
        onInstanceReady={(e) => e.editor.setData(getValues('description'))}
-
 
169
        config={CKEDITOR_OPTIONS}
167
        onChange={(value) => setValue('description', value)}
170
      />
168
      />
171
      {errors.description && (
169
      {errors.description && (
172
        <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
170
        <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
173
      )}
171
      )}