Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7035 Rev 7037
Línea 16... Línea 16...
16
}) => {
16
}) => {
17
  const [loading, setLoading] = useState(false)
17
  const [loading, setLoading] = useState(false)
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
 
21
  const { handleSubmit, register, setValue, errors, getValues, watch } =
-
 
Línea 22... Línea 21...
22
    useForm()
21
  const { handleSubmit, register, setValue, errors, getValues } = useForm()
23
 
22
 
24
  const onSubmit = handleSubmit((data) => {
23
  const onSubmit = handleSubmit((data) => {
-
 
24
    setLoading(true)
Línea 25... Línea 25...
25
    setLoading(true)
25
    const formData = new FormData()
26
    const formData = new FormData()
26
    Object.entries(data).map(([key, value]) => formData.append(key, value))
27
 
27
 
28
    axios
28
    axios
Línea 52... Línea 52...
52
      })
52
      })
53
      .finally(() => setLoading(false))
53
      .finally(() => setLoading(false))
54
  })
54
  })
Línea 55... Línea 55...
55
 
55
 
56
  useEffect(() => {
-
 
57
    register('category_id')
56
  useEffect(() => {
58
    register('description', { required: true })
-
 
59
    register('title', { required: true })
57
    register('description', { required: true })
Línea 60... Línea 58...
60
  }, [])
58
  }, [])
61
 
59
 
62
  useEffect(() => {
60
  useEffect(() => {
Línea 63... Línea 61...
63
    axios.get(url).then((response) => {
61
    axios.get(url).then((response) => {
64
      const { data, success } = response
62
      const { data, success } = response
65
 
63
 
Línea -... Línea 64...
-
 
64
      if (!success) {
66
      if (!success) {
65
        const errorMessage =
67
        const errorMessage =
66
          typeof data === 'string' ? data : 'Ha ocurrido un error'
68
          typeof data === 'string' ? data : 'Ha ocurrido un error'
67
 
-
 
68
        dispatch(
69
 
69
          addNotification({
-
 
70
            style: 'danger',
70
        addNotification({
71
            msg: errorMessage,
Línea 71... Línea 72...
71
          style: 'danger',
72
          })
72
          msg: errorMessage,
73
        )
73
        })
74
        return
74
      }
75
      }
75
 
76
 
Línea 76... Línea 77...
76
      setValue('category_id', data.category_id)
77
      setValue('category_id', data.category_id)
77
      setValue('description', data.description)
78
      setValue('description', data.description)
78
      setValue('title', data.title)
79
      setValue('title', data.title)
79
    })
80
    })
80
  }, [show])
81
  }, [show])
81
 
82
 
82
  return (
83
  return (
83
    <Modal show={show}>
84
    <Modal show={show}>
Línea 91... Línea 92...
91
            <Form.Control as="select" ref={register} name="category_id">
92
            <Form.Control as="select" ref={register} name="category_id">
92
              {categories.map(({ name, uuid }) => (
93
              {categories.map(({ name, uuid }) => (
93
                <option key={uuid}>{name}</option>
94
                <option key={uuid}>{name}</option>
94
              ))}
95
              ))}
95
            </Form.Control>
96
            </Form.Control>
96
            {errors.description && (
97
            {errors.category_id && (
97
              <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
98
              <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
98
            )}
99
            )}
99
          </Form.Group>
100
          </Form.Group>
Línea 100... Línea 101...
100
 
101
 
101
          <Form.Group>
102
          <Form.Group>
102
            <Form.Label>{labels.title}</Form.Label>
103
            <Form.Label>{labels.title}</Form.Label>
103
            <Form.Control type="text" name="title" ref={register} />
104
            <Form.Control type="text" name="title" ref={register} />
104
            {errors.description && (
105
            {errors.title && (
105
              <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
106
              <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
106
            )}
107
            )}
Línea 107... Línea 108...
107
          </Form.Group>
108
          </Form.Group>
Línea 113... Línea 114...
113
          />
114
          />
114
          {errors.description && (
115
          {errors.description && (
115
            <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
116
            <FormErrorFeedback>{labels.error_field_empty}</FormErrorFeedback>
116
          )}
117
          )}
Línea 117... Línea 118...
117
 
118
 
118
          <Button variant="primary" type="submit">
119
          <Button className="mt-3 mr-3" variant="primary" type="submit">
119
            {labels.accept}
120
            {labels.accept}
120
          </Button>
121
          </Button>
121
          <Button className="btn-secondary mt-3" onClick={onClose}>
122
          <Button className="btn-secondary mt-3" onClick={onClose}>
122
            {labels.cancel}
123
            {labels.cancel}