Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 7806 Rev 10513
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react'
2
import axios from 'axios';
2
import axios from 'axios'
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';
5
import { useDispatch } from 'react-redux'
6
import { addNotification } from '../redux/notification/notification.actions';
6
import { addNotification } from '../redux/notification/notification.actions'
Línea 7... Línea 7...
7
 
7
 
8
const DeleteModal = ({
8
const DeleteModal = ({
9
    isOpen = false,
9
	isOpen = false,
10
    closeModal = function () { },
10
	closeModal = function () { },
11
    title = 'Estas seguro?',
11
	title = 'Estas seguro?',
12
    action,
12
	action,
13
    onComplete,
13
	onComplete,
14
    url,
14
	url,
15
    message
15
	message
Línea 16... Línea 16...
16
}) => {
16
}) => {
17
 
17
 
Línea 18... Línea 18...
18
    const { handleSubmit } = useForm();
18
	const { handleSubmit } = useForm()
19
    const dispatch = useDispatch();
19
	const dispatch = useDispatch()
20
 
20
 
21
    const onSubmit = () => {
21
	const onSubmit = () => {
22
        if (!url && action) {
22
		if (!url && action) {
23
            return dispatch(action())
23
			return dispatch(action())
24
        }
24
		}
25
 
25
 
26
        if (!url && onComplete) {
26
		if (!url && onComplete) {
27
            return onComplete()
27
			return onComplete()
28
        }
28
		}
29
 
29
 
30
        axios.post(url)
30
		axios.post(url)
31
            .then(({ data }) => {
31
			.then(({ data }) => {
32
                if (data.success) {
32
				if (data.success) {
33
                    action && dispatch(action())
33
					action && dispatch(action())
34
                    onComplete && onComplete()
34
					onComplete && onComplete()
35
 
35
 
36
                    closeModal()
36
					closeModal()
37
 
37
 
38
                    dispatch(addNotification({
38
					dispatch(addNotification({
39
                        style: "success",
39
						style: 'success',
40
                        msg: message ? message : 'Se ha eliminado con exito'
40
						msg: message ? message : 'Se ha eliminado con exito'
41
                    }))
41
					}))
42
                }
42
				}
43
            })
43
			})
44
            .catch((err) => dispatch(addNotification({
44
			.catch(() => dispatch(addNotification({
45
                style: "danger",
45
				style: 'danger',
46
                msg: "Ha ocurrido un error"
46
				msg: 'Ha ocurrido un error'
47
            })))
47
			})))
48
    };
48
	}
49
 
49
 
50
    return (
50
	return (
51
        <Modal
51
		<Modal
52
            size="md"
52
			size="md"
53
            show={isOpen}
53
			show={isOpen}
54
            onHide={closeModal}
54
			onHide={closeModal}
55
            autoFocus={false}
55
			autoFocus={false}
56
        >
56
		>
57
            <form onSubmit={handleSubmit(onSubmit)}>
57
			<form onSubmit={handleSubmit(onSubmit)}>
58
                <Modal.Body>
58
				<Modal.Body>
59
                    <h2>{title}</h2>
59
					<h2>{title}</h2>
60
                </Modal.Body>
60
				</Modal.Body>
61
                <Modal.Footer>
61
				<Modal.Footer>
62
                    <Button
62
					<Button
63
                        variant="success"
63
						variant="success"
64
                        type="submit"
64
						type="submit"
65
                    >
65
					>
66
66
67
                    </Button>
67
					</Button>
68
                    <Button
68
					<Button
69
                        variant="danger"
69
						variant="danger"
70
                        onClick={closeModal}
70
						onClick={closeModal}
71
                    >
71
					>
72
                        No
72
                        No
73
                    </Button>
73
					</Button>
74
                </Modal.Footer>
74
				</Modal.Footer>
75
            </form>
75
			</form>
Línea 76... Línea 76...
76
        </Modal >
76
		</Modal >
77
    )
77
	)