Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7806 | Rev 11272 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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