Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3271 Rev 3272
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React from 'react'
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from 'react-redux'
3
import { useForm } from 'react-hook-form'
3
import { Controller, useForm } from 'react-hook-form'
Línea 4... Línea 4...
4
 
4
 
5
import { axios } from '@utils'
5
import { axios } from '@utils'
Línea 6... Línea 6...
6
import { addNotification } from '@store/notification/notification.actions'
6
import { addNotification } from '@store/notification/notification.actions'
Línea 17... Línea 17...
17
  onClose = () => {}
17
  onClose = () => {}
18
}) => {
18
}) => {
19
  const dispatch = useDispatch()
19
  const dispatch = useDispatch()
Línea 20... Línea 20...
20
 
20
 
21
  const {
21
  const {
-
 
22
    control,
22
    register,
23
    formState: { isSubmitting },
23
    handleSubmit,
-
 
24
    setValue,
-
 
25
    watch,
24
    handleSubmit,
26
    reset,
-
 
27
    formState: { errors, isSubmitting }
25
    reset
28
  } = useForm({
26
  } = useForm({
29
    defaultValues: {
-
 
30
      image: ''
-
 
31
    }
27
    defaultValues: { image: '' }
Línea 32... Línea 28...
32
  })
28
  })
33
 
29
 
34
  const onSubmit = async ({ image }) => {
30
  const onSubmit = handleSubmit(async ({ image }) => {
35
    try {
31
    try {
Línea 36... Línea 32...
36
      const formData = new FormData()
32
      const formData = new FormData()
Línea 37... Línea 33...
37
      formData.append('image', image)
33
      formData.append('image', image)
Línea 38... Línea 34...
38
 
34
 
Línea 53... Línea 49...
53
      reset()
49
      reset()
54
      onClose()
50
      onClose()
55
    } catch (error) {
51
    } catch (error) {
56
      dispatch(addNotification({ style: 'error', msg: error.message }))
52
      dispatch(addNotification({ style: 'error', msg: error.message }))
57
    }
53
    }
58
  }
54
  })
59
 
-
 
60
  useEffect(() => {
-
 
61
    register('image', {
-
 
62
      required: { value: 'true', message: 'El campo es requerido' }
-
 
63
    })
-
 
64
  }, [])
-
 
Línea 65... Línea 55...
65
 
55
 
66
  return (
56
  return (
67
    <Modal
57
    <Modal
68
      show={show}
58
      show={show}
69
      title='Imagen'
59
      title='Imagen'
70
      onClose={onClose}
60
      onClose={onClose}
71
      onReject={onClose}
61
      onReject={onClose}
72
      onAccept={handleSubmit(onSubmit)}
62
      onAccept={onSubmit}
73
      loading={isSubmitting}
63
      loading={isSubmitting}
-
 
64
    >
-
 
65
      <Controller
-
 
66
        name='image'
-
 
67
        control={control}
-
 
68
        rules={{ required: 'Imagen requerida' }}
-
 
69
        render={({ field: { onChange, value }, fieldState: { error } }) => (
74
    >
70
          <>
75
      <DropzoneComponent
71
            <DropzoneComponent
76
        modalType='IMAGE'
72
              modalType='IMAGE'
77
        onUploaded={(file) => setValue('image', file)}
73
              onUploaded={(file) => onChange(file)}
78
        settedFile={watch('image')}
74
              settedFile={value}
-
 
75
              recomendationText={message}
-
 
76
            />
-
 
77
            {error && <FormErrorFeedback>{error.message}</FormErrorFeedback>}
-
 
78
          </>
79
        recomendationText={message}
79
        )}
80
      />
-
 
81
 
-
 
82
      {errors.image && (
-
 
83
        <FormErrorFeedback>{errors.image.message}</FormErrorFeedback>
-
 
84
      )}
80
      />
85
    </Modal>
81
    </Modal>
86
  )
82
  )
Línea 87... Línea 83...
87
}
83
}