Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7186 Rev 7190
Línea 5... Línea 5...
5
import { CKEditor } from 'ckeditor4-react'
5
import { CKEditor } from 'ckeditor4-react'
6
import { CKEDITOR_OPTIONS, axios } from '../../utils'
6
import { CKEDITOR_OPTIONS, axios } from '../../utils'
7
import FormErrorFeedback from '../UI/FormErrorFeedback'
7
import FormErrorFeedback from '../UI/FormErrorFeedback'
8
import { useForm } from 'react-hook-form'
8
import { useForm } from 'react-hook-form'
9
import { addNotification } from '../../redux/notification/notification.actions'
9
import { addNotification } from '../../redux/notification/notification.actions'
-
 
10
import TagsInput from '../../../shared/tags-input/TagsInput'
Línea 10... Línea 11...
10
 
11
 
11
const QuestionModal = ({ show, url, isEdit, onClose, onComplete }) => {
12
const QuestionModal = ({ show, url, isEdit, onClose, onComplete }) => {
-
 
13
  const [loading, setLoading] = useState(false)
-
 
14
  const [questionsCategories, setQuestionsCategories] = useState([])
12
  const [loading, setLoading] = useState(false)
15
  const [currentCategories, setCurrentCategories] = useState([])
13
  const labels = useSelector(({ intl }) => intl.labels)
16
  const labels = useSelector(({ intl }) => intl.labels)
Línea 14... Línea 17...
14
  const dispatch = useDispatch()
17
  const dispatch = useDispatch()
Línea 52... Línea 55...
52
        onClose()
55
        onClose()
53
      })
56
      })
54
      .finally(() => setLoading(false))
57
      .finally(() => setLoading(false))
55
  })
58
  })
Línea -... Línea 59...
-
 
59
 
-
 
60
  const getCategories = () => {
-
 
61
    axios
-
 
62
      .get('/my-coach', {
-
 
63
        headers: {
-
 
64
          'Content-Type': 'application/json',
-
 
65
        },
-
 
66
      })
-
 
67
      .then((response) => {
-
 
68
        const { data, success } = response.data
-
 
69
 
-
 
70
        if (!success) {
-
 
71
          const errorMessage =
-
 
72
            typeof data === 'string' ? data : labels.error_there_was_an_error
-
 
73
 
-
 
74
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
-
 
75
          return
-
 
76
        }
-
 
77
 
-
 
78
        const categories = Object.entries(data.categories).map((values) => ({
-
 
79
          name: values[1],
-
 
80
          value: values[0],
-
 
81
        }))
-
 
82
 
-
 
83
        setQuestionsCategories(categories)
-
 
84
      })
-
 
85
      .catch((error) => {
-
 
86
        dispatch(
-
 
87
          addNotification({
-
 
88
            style: 'danger',
-
 
89
            msg: labels.error_there_was_an_error,
-
 
90
          })
-
 
91
        )
-
 
92
        throw new Error(error)
-
 
93
      })
-
 
94
  }
-
 
95
 
-
 
96
  const onTagsChange = (tags) => {
-
 
97
    setValue('category_id', tags)
-
 
98
  }
56
 
99
 
57
  useEffect(() => {
100
  useEffect(() => {
-
 
101
    register('description', { required: true })
58
    register('description', { required: true })
102
    register('category_id', { required: true })
Línea 59... Línea 103...
59
  }, [])
103
  }, [])
60
 
104
 
Línea 74... Línea 118...
74
            msg: errorMessage,
118
            msg: errorMessage,
75
          })
119
          })
76
        )
120
        )
77
        return
121
        return
78
      }
122
      }
-
 
123
      const categories = questionsCategories.map(
-
 
124
        (category) => data.category_id.includes(category.uuid) && category
79
 
125
      )
80
      console.log(data)
126
      setCurrentCategories(categories)
Línea 81... Línea 127...
81
 
127
 
82
      setValue('title', data.title)
-
 
83
      setValue('category_id', data.category_id)
128
      setValue('title', data.title)
84
      setValue('description', data.description)
129
      setValue('description', data.description)
85
    })
130
    })
Línea 86... Línea 131...
86
  }, [url, show, isEdit])
131
  }, [url, show, isEdit])
87
 
132
 
88
  useEffect(() => {
133
  useEffect(() => {
89
    if (!show) {
134
    if (!show) {
90
      setValue('category_id', '')
135
      setValue('category_id', '')
91
      setValue('description', '')
136
      setValue('description', '')
-
 
137
      setValue('title', '')
-
 
138
      setValue('image', '')
92
      setValue('title', '')
139
    } else {
93
      setValue('image', '')
140
      getCategories()
Línea 94... Línea 141...
94
    }
141
    }
95
  }, [show])
142
  }, [show])
Línea 129... Línea 176...
129
            />
176
            />
130
            {errors.description && (
177
            {errors.description && (
131
              <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
178
              <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
132
            )}
179
            )}
Línea -... Línea 180...
-
 
180
 
-
 
181
            <TagsInput
-
 
182
              suggestions={currentCategories}
-
 
183
              settedTags={questionsCategories}
-
 
184
              onChange={onTagsChange}
-
 
185
            />
133
 
186
 
134
            <Button className="mt-3 mr-2" variant="primary" type="submit">
187
            <Button className="mt-3 mr-2" variant="primary" type="submit">
135
              {labels.accept}
188
              {labels.accept}
136
            </Button>
189
            </Button>
137
            <Button className="btn-secondary mt-3" onClick={onClose}>
190
            <Button className="btn-secondary mt-3" onClick={onClose}>