Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15227 Rev 15274
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, { useEffect } from 'react'
3
import { Button, Modal } from 'react-bootstrap'
3
import { Button, Modal } from 'react-bootstrap'
4
import { useForm } from 'react-hook-form'
4
import { useForm } from 'react-hook-form'
5
import { useDispatch } from 'react-redux'
5
import { useDispatch } from 'react-redux'
6
import { addNotification } from '../../../redux/notification/notification.actions'
6
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
7
import DropzoneComponent from '../../../shared/Dropzone/DropzoneComponent'
Línea 7... Línea 8...
7
 
8
 
Línea 8... Línea 9...
8
const FooterModal = ({ isOpen, closeModal, footerUploadUrl, action }) => {
9
const FooterModal = ({ isOpen, closeModal, footerUploadUrl, action }) => {
9
 
-
 
10
	const { handleSubmit, register } = useForm()
10
 
Línea 11... Línea 11...
11
	const [error, setError] = useState()
11
	const { handleSubmit, register, getValues, setValue, clearErrors, errors } = useForm()
12
	const dispatch = useDispatch()
12
	const dispatch = useDispatch()
13
 
13
 
Línea 14... Línea 14...
14
	const onSubmit = ({ footer }) => {
14
	const onSubmit = ({ footer }) => {
15
		const data = new FormData()
15
		const data = new FormData()
16
		data.append('footer', footer[0])
16
		data.append('footer', footer)
17
 
17
 
Línea 33... Línea 33...
33
							)
33
							)
34
						)
34
						)
35
					return
35
					return
36
				}
36
				}
37
				action(data.data)
37
				action(data.data)
38
			})
-
 
39
			.then(() => {
-
 
40
				setError(null)
-
 
41
				closeModal()
38
				closeModal()
42
			})
39
			})
43
			.catch(err => console.log(err))
40
			.catch(err => console.log(err))
44
	}
41
	}
Línea -... Línea 42...
-
 
42
 
-
 
43
	const onUploadedHandler = (file) => {
-
 
44
		setValue('footer', file)
-
 
45
		clearErrors('footer')
-
 
46
	}
-
 
47
 
-
 
48
	useEffect(() => {
-
 
49
		if (getValues('footer')) setValue('footer', '')
-
 
50
	}, [isOpen])
-
 
51
 
-
 
52
	useEffect(() => {
-
 
53
		register('footer', { required: true })
-
 
54
	}, [])
45
 
55
 
46
	return (
56
	return (
47
		<Modal
57
		<Modal
48
			size="md"
58
			size="md"
49
			show={isOpen}
59
			show={isOpen}
Línea 53... Línea 63...
53
			<Modal.Header closeButton>
63
			<Modal.Header closeButton>
54
				<Modal.Title>Pie de página</Modal.Title>
64
				<Modal.Title>Pie de página</Modal.Title>
55
			</Modal.Header>
65
			</Modal.Header>
56
			<form onSubmit={handleSubmit(onSubmit)}>
66
			<form onSubmit={handleSubmit(onSubmit)}>
57
				<Modal.Body>
67
				<Modal.Body>
58
					<div className="mb-3">
68
					<div className="form-group">
59
						<label htmlFor="formFileSm" className="form-label">Imagen recomendada de (2480 x 268px)</label>
-
 
60
						<input
-
 
61
							className="form-control form-control-sm"
-
 
62
							id="formFileSm"
69
						<DropzoneComponent
63
							type="file"
70
							modalType='IMAGE'
64
							name="footer"
-
 
65
							accept='.jpg, .jpeg, .png, .gif'
71
							onUploaded={onUploadedHandler}
66
							ref={register}
72
							settedFile={getValues('footer')}
67
							style={{ padding: '1px' }}
73
							recomendationText='Imagen recomendada de (2480 x 268px)'
68
						/>
74
						/>
69
					</div>
75
					</div>
70
					{error && <p>{error}</p>}
76
					{errors.footer && <p>Este campo es requerido</p>}
71
				</Modal.Body>
77
				</Modal.Body>
72
				<Modal.Footer>
78
				<Modal.Footer>
73
					<Button
79
					<Button
74
						variant="primary"
80
						variant="primary"
75
						type="submit"
81
						type="submit"