Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 6547 Rev 11152
Línea 2... Línea 2...
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'
Línea 5... Línea 5...
5
 
5
 
6
const CompanyImgModal = ({
6
const CompanyImgModal = ({
7
    isOpen,
7
	isOpen,
8
    closeModal,
8
	closeModal,
9
    imageUploadUrl,
9
	imageUploadUrl,
10
    action
10
	action
Línea 11... Línea 11...
11
}) => {
11
}) => {
12
 
12
 
Línea 13... Línea 13...
13
    const { handleSubmit, register } = useForm()
13
	const { handleSubmit, register } = useForm()
14
    const [error, setError] = useState(null);
14
	const [error, setError] = useState(null)
15
 
15
 
16
    const onSubmit = ({ image }) => {
16
	const onSubmit = ({ image }) => {
17
        const data = new FormData()
17
		const data = new FormData()
18
        data.append("image", image[0])
18
		data.append('image', image[0])
19
        axios.post(imageUploadUrl, data)
19
		axios.post(imageUploadUrl, data)
20
            .then(({ data }) => {
20
			.then(({ data }) => {
21
                if (!data.success) {
21
				if (!data.success) {
22
                    return setError(data.data)
22
					return setError(data.data)
23
                }
23
				}
24
                action(data.data)
24
				action(data.data)
25
                setError(null)
25
				setError(null)
26
                closeModal()
26
				closeModal()
Línea 27... Línea 27...
27
            })
27
			})
28
            .catch((err) => console.log(err))
28
			.catch((err) => console.log(err))
29
    }
29
	}
30
 
30
 
31
    return (
31
	return (
32
        <Modal
32
		<Modal
33
            size="md"
33
			size="md"
34
            show={isOpen}
34
			show={isOpen}
35
            onHide={closeModal}
35
			onHide={closeModal}
36
            autoFocus={false}
36
			autoFocus={false}
37
        >
37
		>
38
            <Modal.Header closeButton>
38
			<Modal.Header closeButton>
39
                <Modal.Title>Cambiar</Modal.Title>
39
				<Modal.Title>Cambiar</Modal.Title>
40
            </Modal.Header>
40
			</Modal.Header>
41
            <form onSubmit={handleSubmit(onSubmit)}>
41
			<form onSubmit={handleSubmit(onSubmit)}>
42
                <Modal.Body>
42
				<Modal.Body>
43
                    <div className="mb-3">
43
					<div className="mb-3">
44
                        <label className="form-label">Imagen recomendada de (180 x 180px)</label>
44
						<label className="form-label">Imagen recomendada de (180 x 180px)</label>
45
                        <input
45
						<input
46
                            className="form-control form-control-sm"
46
							className="form-control form-control-sm"
47
                            id="formFileSm"
47
							id="formFileSm"
48
                            type="file"
48
							type="file"
49
                            name="image"
49
							name="image"
50
                            accept='.jpg, .jpeg, .png, .gif'
50
							accept='.jpg, .jpeg, .png, .gif'
51
                            ref={register}
51
							ref={register}
52
                            style={{ padding: '1px' }}
52
							style={{ padding: '1px' }}
53
                        />
53
						/>
54
                    </div>
54
					</div>
55
                    {error && <p>{error}</p>}
55
					{error && <p>{error}</p>}
56
                </Modal.Body>
56
				</Modal.Body>
57
                <Modal.Footer>
57
				<Modal.Footer>
58
                    <Button
58
					<Button
59
                        variant="primary"
59
						variant="primary"
60
                        type="submit"
60
						type="submit"
61
                    >
61
					>
62
                        Enviar
62
                        Enviar
63
                    </Button>
63
					</Button>
64
                    <Button
64
					<Button
65
                        variant="default"
65
						className='btn-tertiary'
66
                        onClick={closeModal}
66
						onClick={closeModal}
67
                    >
67
					>
68
                        Cancelar
68
                        Cancelar
69
                    </Button>
69
					</Button>
70
                </Modal.Footer>
70
				</Modal.Footer>
Línea 71... Línea 71...
71
            </form>
71
			</form>
72
        </Modal >
72
		</Modal >