Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2909 Rev 3271
Línea 22... Línea 22...
22
    register,
22
    register,
23
    handleSubmit,
23
    handleSubmit,
24
    setValue,
24
    setValue,
25
    watch,
25
    watch,
26
    reset,
26
    reset,
27
    formState: { errors }
27
    formState: { errors, isSubmitting }
28
  } = useForm({
28
  } = useForm({
29
    defaultValues: {
29
    defaultValues: {
30
      image: ''
30
      image: ''
31
    }
31
    }
32
  })
32
  })
Línea 33... Línea 33...
33
 
33
 
-
 
34
  const onSubmit = async ({ image }) => {
34
  const onSubmitHandler = handleSubmit(({ image }) => {
35
    try {
35
    const formData = new FormData()
36
      const formData = new FormData()
36
    formData.append('image', image)
37
      formData.append('image', image)
37
 
-
 
38
    axios
38
 
39
      .post(url, formData)
-
 
-
 
39
      const response = axios.post(url, formData)
40
      .then(({ data: response }) => {
40
 
41
        const { data, success } = response
41
      const { data, success } = response
42
 
-
 
43
        if (!success) {
42
 
44
          throw new Error('Error al actualizar la imagen')
-
 
45
        }
43
      if (!success) throw new Error('Error al actualizar la imagen')
46
 
44
 
47
        const newImage = data.profile ?? data
45
      const newImage = data.profile ?? data
48
 
46
 
49
        if (data.update_navbar) {
47
      if (data.update_navbar) {
50
          sessionStorage.setItem('user_session_image', data.user)
48
        sessionStorage.setItem('user_session_image', data.user)
51
        }
-
 
52
 
-
 
53
        onComplete(newImage)
49
      }
54
 
-
 
55
        dispatch(
50
 
56
          addNotification({ style: 'success', msg: 'Registro actualizado' })
51
      dispatch(addNotification({ style: 'success', msg: 'Imagen actualizada' }))
57
        )
52
      onComplete(newImage)
58
        reset()
53
      reset()
59
        onClose()
-
 
60
      })
54
      onClose()
61
      .catch((err) => {
55
    } catch (error) {
62
        addNotification({ style: 'error', msg: err.message })
56
      dispatch(addNotification({ style: 'error', msg: error.message }))
63
      })
57
    }
Línea 64... Línea 58...
64
  })
58
  }
65
 
59
 
66
  useEffect(() => {
60
  useEffect(() => {
67
    register('image', {
61
    register('image', {
Línea 73... Línea 67...
73
    <Modal
67
    <Modal
74
      show={show}
68
      show={show}
75
      title='Imagen'
69
      title='Imagen'
76
      onClose={onClose}
70
      onClose={onClose}
77
      onReject={onClose}
71
      onReject={onClose}
78
      onAccept={onSubmitHandler}
72
      onAccept={handleSubmit(onSubmit)}
-
 
73
      loading={isSubmitting}
79
    >
74
    >
80
      <DropzoneComponent
75
      <DropzoneComponent
81
        modalType='IMAGE'
76
        modalType='IMAGE'
82
        onUploaded={(file) => setValue('image', file)}
77
        onUploaded={(file) => setValue('image', file)}
83
        settedFile={watch('image')}
78
        settedFile={watch('image')}