Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 8063 Rev 11142
Línea 1... Línea 1...
1
import React, { useState } from 'react';
1
import React, { useState } from 'react'
2
import { Modal, Button } from 'react-bootstrap';
2
import { Modal, Button } from 'react-bootstrap'
3
import axios from 'axios';
3
import axios from 'axios'
4
import { addNotification } from '../../../redux/notification/notification.actions';
4
import { addNotification } from '../../../redux/notification/notification.actions'
5
import { useDispatch } from 'react-redux';
5
import { useDispatch } from 'react-redux'
Línea 6... Línea 6...
6
 
6
 
7
const SubmitModal = ({
7
const SubmitModal = ({
8
    children,
8
	children,
9
    closeModal = function () { },
9
	closeModal = function () { },
10
    postLink = '',
10
	postLink = '',
11
    submitData = '',
11
	submitData = '',
12
    title = ''
12
	title = ''
Línea 13... Línea 13...
13
}) => {
13
}) => {
14
 
14
 
Línea 15... Línea 15...
15
    const [error, setError] = useState('');
15
	const [error, setError] = useState('')
Línea 16... Línea 16...
16
    const dispatch = useDispatch()
16
	const dispatch = useDispatch()
17
 
17
 
18
    const onSubmit = () => {
18
	const onSubmit = () => {
19
 
19
 
20
        const formData = new FormData()
20
		const formData = new FormData()
21
        Object.entries(submitData).forEach((entries) => {
21
		Object.entries(submitData).forEach((entries) => {
22
            formData.append(entries[0], entries[1])
22
			formData.append(entries[0], entries[1])
23
        })
23
		})
24
 
24
 
25
        axios.post(postLink, formData)
25
		axios.post(postLink, formData)
26
            .then(({ data }) => {
26
			.then(({ data }) => {
27
                if (!data.success) {
27
				if (!data.success) {
28
                    dispatch(addNotification({
28
					dispatch(addNotification({
29
                        style: "error",
29
						style: 'error',
30
                        msg: typeof data.data === "string"
30
						msg: typeof data.data === 'string'
31
                            ? data.data
31
							? data.data
32
                            : Object.values(data.data)[0]
32
							: Object.values(data.data)[0]
33
                    }))
33
					}))
34
                    return
34
					return
35
                }
35
				}
36
 
36
 
37
 
37
 
38
                dispatch(addNotification({
38
				dispatch(addNotification({
39
                    style: "success",
39
					style: 'success',
40
                    msg: "Envio completado"
40
					msg: 'Envio completado'
41
                }))
41
				}))
42
                setError(null)
42
				setError(null)
43
                closeModal()
43
				closeModal()
44
            })
44
			})
45
            .catch((err) => setError(err))
45
			.catch((err) => setError(err))
46
    };
46
	}
47
 
47
 
48
    return (
48
	return (
49
        <Modal size="lg" show onHide={closeModal}>
49
		<Modal size="lg" show onHide={closeModal}>
50
            <Modal.Header closeButton>
50
			<Modal.Header closeButton>
51
                <Modal.Title>{title}</Modal.Title>
-
 
52
            </Modal.Header>
51
				<Modal.Title>{title}</Modal.Title>
53
            <Modal.Body>
52
			</Modal.Header>
54
                <div className='form-group'>
53
			<Modal.Body>
55
                    <label className="form-label">{title}</label>
54
				<div className='form-group'>
56
                    {children}
55
					{children}
57
                </div>
56
				</div>
58
                {error && <p>{error}</p>}
57
				{error && <p>{error}</p>}
59
            </Modal.Body>
58
			</Modal.Body>
60
            <Modal.Footer>
59
			<Modal.Footer>
61
                <Button
60
				<Button
62
                    variant="primary"
61
					variant="primary"
63
                    onClick={onSubmit}
62
					onClick={onSubmit}
64
                >
63
				>
65
                    Enviar
64
                    Enviar
66
                </Button>
65
				</Button>
67
                <Button variant="danger" onClick={closeModal}>
66
				<Button variant="danger" onClick={closeModal}>
68
                    Cancelar
67
                    Cancelar
69
                </Button>
68
				</Button>
Línea 70... Línea 69...
70
            </Modal.Footer>
69
			</Modal.Footer>
71
        </Modal >
70
		</Modal >