Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React from 'react';
2
import { useDispatch } from 'react-redux';
3
import parse from 'html-react-parser';
4
 
5
import { axios } from '@utils/index.js';
6
import { addNotification } from '@store/notification/notification.actions';
7
import Modal from '@components/UI/modal/modal';
8
import { Box } from '@mui/material';
9
 
10
const EventModal = ({ event, show, onClose }) => {
11
  const dispatch = useDispatch();
12
 
13
  const getBackendVarUrl = (url = '') => {
14
    if (!url) return;
15
 
16
    axios
17
      .get(url)
18
      .then((response) => {
19
        const { data, success } = response.data;
20
 
21
        if (!success) {
22
          const errorMessage =
23
            typeof data === 'string' ? data : 'Error interno. Por favor, intente más tarde.';
24
          throw new Error(errorMessage);
25
        }
26
 
27
        window.open(data, '_blank');
28
      })
29
      .catch((err) => {
30
        dispatch(addNotification({ style: 'danger', message: err.message }));
31
      });
32
  };
33
 
34
  return (
35
    <Modal title={event?.title} show={show} onClose={onClose}>
36
      <Box
37
        sx={{ cursor: event?.ur ? 'pointer' : 'default' }}
38
        onClick={() => getBackendVarUrl(event?.url)}
39
      >
40
        {event?.agenda && parse(event?.agenda)}
41
      </Box>
42
    </Modal>
43
  );
44
};
45
 
46
export default EventModal;