Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 11152 Rev 14843
Línea 1... Línea 1...
1
import axios from 'axios'
1
import axios from 'axios'
2
import React, { useState } from 'react'
2
import React, { useState } from 'react'
3
import { Modal, Button } from 'react-bootstrap'
3
import { Modal, Button } from 'react-bootstrap'
4
import { useForm } from 'react-hook-form'
4
import { useForm } from 'react-hook-form'
-
 
5
import { useDispatch } from 'react-redux'
-
 
6
import { addNotification } from '../../../redux/notification/notification.actions'
Línea 5... Línea 7...
5
 
7
 
6
const HeaderModal = ({
8
const HeaderModal = ({
7
	isOpen,
9
	isOpen,
8
	closeModal,
10
	closeModal,
9
	headerUploadUrl,
11
	headerUploadUrl,
10
	action
12
	action
Línea 11... Línea 13...
11
}) => {
13
}) => {
12
 
14
 
-
 
15
	const { handleSubmit, register } = useForm()
Línea 13... Línea 16...
13
	const { handleSubmit, register } = useForm()
16
	const [error, setError] = useState(null)
14
	const [error, setError] = useState(null)
17
	const dispatch = useDispatch()
15
 
18
 
16
	const onSubmit = ({ header }) => {
19
	const onSubmit = ({ header }) => {
17
		const data = new FormData()
20
		const data = new FormData()
18
		data.append('header', header[0])
21
		data.append('header', header[0])
-
 
22
		axios.post(headerUploadUrl, data)
-
 
23
			.then(({ data }) => {
-
 
24
				if (!data.success) {
-
 
25
					typeof data.data === 'string'
19
		axios.post(headerUploadUrl, data)
26
						?
-
 
27
						dispatch(addNotification({
-
 
28
							style: 'danger',
-
 
29
							msg: data.data
-
 
30
						}))
-
 
31
						: Object.entries(data.data).map(([key, value]) =>
-
 
32
							value.map(err =>
-
 
33
								dispatch(addNotification({
-
 
34
									style: 'danger',
-
 
35
									msg: `${key}: ${err}`
-
 
36
								}))
20
			.then(({ data }) => {
37
							)
21
				if (!data.success) {
38
						)
22
					return setError(data.data)
39
					return
23
				}
40
				}
24
				action(data.data)
41
				action(data.data)