Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 11272 | Rev 11911 | 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 }) => {
11272 stevensc 32
				if (!data.success) {
11275 stevensc 33
					return dispatch(addNotification({
11272 stevensc 34
						style: 'danger',
35
						msg: data.data
10513 stevensc 36
					}))
37
				}
11272 stevensc 38
				action && dispatch(action())
39
				onComplete && onComplete()
40
 
41
				closeModal()
42
 
43
				dispatch(addNotification({
44
					style: 'success',
45
					msg: message ? message : 'Se ha eliminado con exito'
46
				}))
10513 stevensc 47
			})
48
			.catch(() => dispatch(addNotification({
49
				style: 'danger',
50
				msg: 'Ha ocurrido un error'
51
			})))
52
	}
7427 stevensc 53
 
10513 stevensc 54
	return (
55
		<Modal
56
			size="md"
57
			show={isOpen}
58
			onHide={closeModal}
59
			autoFocus={false}
60
		>
61
			<form onSubmit={handleSubmit(onSubmit)}>
62
				<Modal.Body>
63
					<h2>{title}</h2>
64
				</Modal.Body>
65
				<Modal.Footer>
66
					<Button
67
						variant="success"
68
						type="submit"
69
					>
11272 stevensc 70
10513 stevensc 71
					</Button>
72
					<Button
73
						variant="danger"
74
						onClick={closeModal}
75
					>
11272 stevensc 76
						No
10513 stevensc 77
					</Button>
78
				</Modal.Footer>
79
			</form>
80
		</Modal >
81
	)
7427 stevensc 82
}
83
 
84
export default DeleteModal