Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15266 Rev 15267
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 { useEffect } from 'react'
3
import { Modal, Button } from 'react-bootstrap'
4
import { Modal, Button } from 'react-bootstrap'
4
import { useForm } from 'react-hook-form'
5
import { useForm } from 'react-hook-form'
5
import { useDispatch } from 'react-redux'
6
import { useDispatch } from 'react-redux'
6
import { addNotification } from '../../../redux/notification/notification.actions'
7
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
8
import DropzoneComponent from '../../../shared/Dropzone/DropzoneComponent'
Línea 7... Línea 9...
7
 
9
 
8
const CoverModal = ({
10
const CoverModal = ({
9
	isOpen,
11
	isOpen,
10
	closeModal,
12
	closeModal,
11
	coverUploadUrl,
13
	coverUploadUrl,
12
	action
14
	action
Línea 13... Línea 15...
13
}) => {
15
}) => {
14
 
16
 
15
	const { handleSubmit, register } = useForm()
17
	const { handleSubmit, register, getValues, setValue, clearErrors } = useForm()
Línea 16... Línea 18...
16
	const [error, setError] = useState(null)
18
	const [error, setError] = useState(null)
17
	const dispatch = useDispatch()
19
	const dispatch = useDispatch()
Línea 43... Línea 45...
43
				closeModal()
45
				closeModal()
44
			})
46
			})
45
			.catch((err) => console.log(err))
47
			.catch((err) => console.log(err))
46
	}
48
	}
Línea -... Línea 49...
-
 
49
 
-
 
50
	const onUploadedHandler = (file) => {
-
 
51
		setValue('cover', file)
-
 
52
		clearErrors('cover')
-
 
53
	}
-
 
54
 
-
 
55
	useEffect(() => {
-
 
56
		if (getValues('cover')) setValue('cover', '')
-
 
57
	}, [isOpen])
-
 
58
 
-
 
59
	useEffect(() => {
-
 
60
		register('cover', {
-
 
61
			required: { value: 'true', message: 'El campo es requerido' },
-
 
62
		})
-
 
63
	}, [isOpen])
47
 
64
 
48
	return (
65
	return (
49
		<Modal
66
		<Modal
50
			size="md"
67
			size="md"
51
			show={isOpen}
68
			show={isOpen}
52
			onHide={closeModal}
69
			onHide={closeModal}
53
			autoFocus={false}
70
			autoFocus={false}
54
		>
71
		>
55
			<Modal.Header closeButton>
72
			<Modal.Header closeButton>
56
				<Modal.Title>Portada - Imagen recomendada de (2480 x 268px)</Modal.Title>
73
				<Modal.Title>Portada</Modal.Title>
57
			</Modal.Header>
74
			</Modal.Header>
58
			<form onSubmit={handleSubmit(onSubmit)}>
75
			<form onSubmit={handleSubmit(onSubmit)}>
59
				<Modal.Body>
76
				<Modal.Body>
60
					<div className="form-group">
-
 
61
						<input
-
 
62
							className="form-control form-control-sm"
77
					<div className="form-group">
63
							id="formFileSm"
78
						<DropzoneComponent
64
							type="file"
-
 
65
							name="cover"
79
							modalType='IMAGE'
66
							accept='.jpg, .jpeg, .png, .gif'
80
							onUploaded={onUploadedHandler}
67
							ref={register}
81
							settedFile={getValues('cover')}
68
							style={{ padding: '1px' }}
82
							recomendationText='Imagen recomendada de (2480 x 268px)'
69
						/>
83
						/>
70
					</div>
84
					</div>
71
					{error && <p>{error}</p>}
85
					{error && <p>{error}</p>}
72
				</Modal.Body>
86
				</Modal.Body>