Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 703 Rev 704
Línea 25... Línea 25...
25
 
25
 
26
  useEffect(() => {
26
  useEffect(() => {
27
    register('description', { required: 'Este campo es requerido' })
27
    register('description', { required: 'Este campo es requerido' })
Línea 28... Línea 28...
28
  }, [])
28
  }, [])
29
 
29
 
30
  const onSubmitHandler = async ({ description }) => {
30
  const onSubmitHandler = ({ description }) => {
31
    const typesUrl = {
31
    const typesUrl = {
32
      profile: `/profile/my-profiles/extended/${id}`,
32
      profile: `/profile/my-profiles/extended/${id}`,
33
      group: `/group/my-groups/extended/${id}`
33
      group: `/group/my-groups/extended/${id}`
Línea 39... Línea 39...
39
    const formData = new FormData()
39
    const formData = new FormData()
40
    formData.append('description', description)
40
    formData.append('description', description)
Línea 41... Línea 41...
41
 
41
 
42
    axios
42
    axios
43
      .post(typesUrl[type], formData)
43
      .post(typesUrl[type], formData)
-
 
44
      .then(({ data: responseData }) => {
44
      .then(({ data }) => {
45
        const { data, success } = responseData
45
        if (!data.success) {
46
        if (!success) {
46
          typeof data.data === 'string'
-
 
47
            ? dispatch(addNotification({ msg: data.data, style: 'danger' }))
47
          const errorMessage =
48
            : Object.entries(data.data).map(([key, value]) =>
48
            typeof data === 'string'
49
                value.map((err) =>
49
              ? data
50
                  dispatch(
50
              : Object.entries(data).map(
51
                    addNotification({ style: 'danger', msg: `${key}: ${err}` })
-
 
52
                  )
51
                  ([key, value]) => `${key}: ${value}`
53
                )
-
 
54
              )
52
                )[0]
55
          return
53
          throw new Error(errorMessage)
Línea 56... Línea 54...
56
        }
54
        }
57
 
55
 
58
        onComplete(data.data.description)
56
        onComplete(data.description)
-
 
57
        closeModal()
-
 
58
      })
-
 
59
      .catch((err) => {
59
        closeModal()
60
        dispatch(addNotification({ style: 'danger', msg: err.message }))
60
      })
61
      })
Línea 61... Línea 62...
61
      .finally(() => setLoading(false))
62
      .finally(() => setLoading(false))
62
  }
63
  }