Proyectos de Subversion LeadersLinked - Backend

Rev

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