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 CoverModal = ({
8
const CoverModal = ({
7
	isOpen,
9
	isOpen,
8
	closeModal,
10
	closeModal,
9
	coverUploadUrl,
11
	coverUploadUrl,
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 = ({ cover }) => {
19
	const onSubmit = ({ cover }) => {
17
		const data = new FormData()
20
		const data = new FormData()
18
		data.append('cover', cover[0])
21
		data.append('cover', cover[0])
-
 
22
		axios.post(coverUploadUrl, data)
-
 
23
			.then(({ data }) => {
-
 
24
				if (!data.success) {
-
 
25
					typeof data.data === 'string'
19
		axios.post(coverUploadUrl, 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)
Línea 57... Línea 74...
57
				<Modal.Footer>
74
				<Modal.Footer>
58
					<Button
75
					<Button
59
						variant="primary"
76
						variant="primary"
60
						type="submit"
77
						type="submit"
61
					>
78
					>
62
                        Enviar
79
						Enviar
63
					</Button>
80
					</Button>
64
					<Button
81
					<Button
65
						className='btn-tertiary'
82
						className='btn-tertiary'
66
						onClick={closeModal}
83
						onClick={closeModal}
67
					>
84
					>
68
                        Cancelar
85
						Cancelar
69
					</Button>
86
					</Button>
70
				</Modal.Footer>
87
				</Modal.Footer>
71
			</form>
88
			</form>
72
		</Modal >
89
		</Modal >
73
	)
90
	)