Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 1976 Rev 1977
Línea 18... Línea 18...
18
  const labels = useSelector(({ intl }) => intl.labels)
18
  const labels = useSelector(({ intl }) => intl.labels)
19
  const dispatch = useDispatch()
19
  const dispatch = useDispatch()
Línea 20... Línea 20...
20
 
20
 
Línea 21... Línea 21...
21
  const { register, handleSubmit, getValues, setValue, errors } = useForm()
21
  const { register, handleSubmit, getValues, setValue, errors } = useForm()
-
 
22
 
-
 
23
  const onSubmit = handleSubmit(({ category_id, ...data }) => {
22
 
24
    axios
-
 
25
      .post(url, {
-
 
26
        ...data,
23
  const onSubmit = handleSubmit((data) => {
27
        'category_id[]': category_id
24
    console.log(data)
28
      })
Línea 25... Línea 29...
25
    axios.post(url, data).then((response) => {
29
      .then((response) => {
26
      const { data, success } = response.data
30
        const { data, success } = response.data
27
 
31
 
28
      if (!success) {
32
        if (!success) {
29
        const errorMessage =
33
          const errorMessage =
Línea 30... Línea 34...
30
          typeof data === 'string'
34
            typeof data === 'string'
31
            ? data
35
              ? data
32
            : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
36
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
Línea 33... Línea 37...
33
 
37
 
34
        dispatch(addNotification({ style: 'danger', msg: errorMessage }))
38
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
35
        return
39
          return
36
      }
40
        }
Línea 37... Línea 41...
37
 
41
 
38
      onComplete()
42
        onComplete()
39
      onClose()
43
        onClose()
Línea 68... Línea 72...
68
      })
72
      })
69
  }
73
  }
Línea 70... Línea 74...
70
 
74
 
71
  const onTagsChange = (tags) => {
75
  const onTagsChange = (tags) => {
72
    const categories = tags.map((tag) => tag.value)
76
    const categories = tags.map((tag) => tag.value)
73
    setValue('category_id[]', categories)
77
    setValue('category_id', categories)
Línea 74... Línea 78...
74
  }
78
  }
75
 
79
 
Línea 76... Línea 80...
76
  useEffect(() => {
80
  useEffect(() => {
77
    getCategories()
81
    getCategories()
78
 
82
 
79
    register('description', { required: 'Este campo es requerido.' })
83
    register('description', { required: 'Este campo es requerido.' })
80
    register('category_id[]', {
84
    register('category_id', {
81
      required: 'Este campo es requerido.',
85
      required: 'Este campo es requerido.',
82
      validate: (val) =>
86
      validate: (val) =>
Línea 117... Línea 121...
117
  }, [url, show, isEdit, questionsCategories])
121
  }, [url, show, isEdit, questionsCategories])
Línea 118... Línea 122...
118
 
122
 
119
  useEffect(() => {
123
  useEffect(() => {
120
    if (!show) {
124
    if (!show) {
121
      setCurrentCategories([])
125
      setCurrentCategories([])
122
      setValue('category_id[]', [])
126
      setValue('category_id', [])
123
      setValue('description', '')
127
      setValue('description', '')
124
      setValue('title', '')
128
      setValue('title', '')
125
    }
129
    }
Línea 150... Línea 154...
150
        <TagsInput
154
        <TagsInput
151
          suggestions={questionsCategories}
155
          suggestions={questionsCategories}
152
          settedTags={currentCategories}
156
          settedTags={currentCategories}
153
          onChange={onTagsChange}
157
          onChange={onTagsChange}
154
        />
158
        />
155
        {errors['category_id[]'] && (
159
        {errors.category_id && (
156
          <FormErrorFeedback>
-
 
157
            {errors['category_id[]']?.message}
160
          <FormErrorFeedback>{errors.category_id?.message}</FormErrorFeedback>
158
          </FormErrorFeedback>
-
 
159
        )}
161
        )}
160
      </Box>
162
      </Box>
Línea 161... Línea 163...
161
 
163
 
162
      <CKEditor
164
      <CKEditor