Rev 14358 | Rev 15412 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
import axios from 'axios'
import { Modal } from 'react-bootstrap'
import { useForm } from 'react-hook-form'
import { useDispatch } from 'react-redux'
import { addNotification } from '../redux/notification/notification.actions'
const DeleteModal = ({
isOpen = false,
closeModal = function () { },
title = 'Estas seguro?',
action,
onComplete,
url,
message
}) => {
const { handleSubmit } = useForm()
const dispatch = useDispatch()
const onSubmit = () => {
if (!url && action) {
dispatch(action())
closeModal()
return
}
if (!url && onComplete) {
onComplete()
closeModal()
return
}
axios.post(url)
.then(({ data }) => {
if (!data.success) {
return dispatch(addNotification({
style: 'danger',
msg: data.data
}))
}
action && dispatch(action())
onComplete && onComplete()
closeModal()
dispatch(addNotification({
style: 'success',
msg: message ? message : 'Se ha eliminado con exito'
}))
})
.catch(() => dispatch(addNotification({
style: 'danger',
msg: 'Ha ocurrido un error'
})))
}
return (
<Modal
size="lg"
show={isOpen}
onHide={closeModal}
autoFocus={false}
>
{/* <form onSubmit={handleSubmit(onSubmit)}> */}
<Modal.Body>
<h3>{title}</h3>
</Modal.Body>
<Modal.Footer>
<button
className='btn btn-primary'
// type="submit"
onClick={onSubmit}
>
Sí
</button>
<button
className='btn btn-secondary'
onClick={closeModal}
>
No
</button>
</Modal.Footer>
{/* </form> */}
</Modal >
)
}
export default DeleteModal