Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 655 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React from 'react'
2
import { Modal } from 'react-bootstrap'
3
import parse from 'html-react-parser'
4
import { axios } from '../../utils'
5
import { addNotification } from '../../redux/notification/notification.actions'
6
import { useDispatch } from 'react-redux'
7
 
8
const EventModal = ({ event, show, onClose }) => {
9
  const dispatch = useDispatch()
10
 
11
  const getBackendVarUrl = (url = '') => {
12
    if (!url) {
13
      return
14
    }
15
 
16
    axios
17
      .get(url)
18
      .then((response) => {
19
        const { data, success } = response.data
20
 
21
        if (!success) {
22
          dispatch(
23
            addNotification({
24
              style: 'danger',
25
              msg: 'Error interno. Por favor, intente más tarde.',
26
            })
27
          )
28
          return
29
        }
30
 
31
        window.open(data, '_blank')
32
      })
33
      .catch((error) => {
34
        dispatch(
35
          addNotification({ style: 'danger', message: 'Ha ocurrido un error' })
36
        )
37
        throw new Error(error)
38
      })
39
  }
40
 
41
  return (
42
    <Modal show={show} onHide={onClose}>
43
      <Modal.Header className="pb-0" closeButton>
44
        <Modal.Title>{event?.title}</Modal.Title>
45
      </Modal.Header>
46
      <Modal.Body>
47
        <div
48
          className={event?.url && 'cursor-pointer'}
49
          onClick={() => getBackendVarUrl(event?.url)}
50
        >
51
          {event && parse(event?.agenda)}
52
        </div>
53
      </Modal.Body>
54
    </Modal>
55
  )
56
}
57
 
58
export default EventModal