Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
707 stevensc 1
import React from 'react'
5 stevensc 2
import { axios } from '../../utils'
3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import styled from 'styled-components'
6
 
7
import WidgetLayout from '../widgets/WidgetLayout'
8
import EmptySection from '../UI/EmptySection'
707 stevensc 9
import useFetch from '../../hooks/useFetch'
5 stevensc 10
 
11
const StyledContainer = styled(WidgetLayout)`
12
  padding: 1rem;
13
  ul {
14
    display: flex;
15
    flex-direction: column;
16
    gap: 0.5rem;
709 stevensc 17
    margin-top: 0.5rem;
5 stevensc 18
  }
19
`
20
 
709 stevensc 21
const StyledEventContainer = styled.div`
22
  display: flex;
23
  flex-direction: column;
24
  cursor: pointer;
25
  padding: 0.5rem;
26
  border-radius: ${(props) => props.theme.border.radius};
27
  background-color: ${(props) => props.background || 'transparent'};
711 stevensc 28
  h4 {
712 stevensc 29
    color: ${(props) => props.theme.font.color.title};
711 stevensc 30
  }
710 stevensc 31
  b {
32
    color: ${(props) => props.theme.font.color.title};
712 stevensc 33
    font-weight: 600;
710 stevensc 34
  }
35
  span {
36
    color: ${(props) => props.color || props.theme.font.color.primary};
711 stevensc 37
    font-weight: 400;
710 stevensc 38
  }
709 stevensc 39
`
40
 
5 stevensc 41
const EventsList = () => {
707 stevensc 42
  const { data: eventsAndTasks } = useFetch('/helpers/next-events', [])
5 stevensc 43
  const dispatch = useDispatch()
44
 
709 stevensc 45
  const getAdminAuth = (url) => {
5 stevensc 46
    axios
47
      .get(url)
706 stevensc 48
      .then(({ data: responseData }) => {
49
        const { data, success } = responseData
5 stevensc 50
 
51
        if (!success) {
707 stevensc 52
          throw new Error('Error interno. Por favor, intente más tarde.')
5 stevensc 53
        }
54
 
55
        window.open(data, '_blank')
56
      })
655 stevensc 57
      .catch((err) => {
707 stevensc 58
        dispatch(addNotification({ style: 'danger', msg: err.message }))
5 stevensc 59
      })
60
  }
61
 
62
  return (
63
    <StyledContainer>
64
      <h2>Eventos y Tareas</h2>
65
 
66
      <ul>
67
        {eventsAndTasks.length ? (
707 stevensc 68
          eventsAndTasks.map(
710 stevensc 69
            ({
70
              id,
71
              url,
72
              title,
73
              backgroundColor,
74
              start,
75
              end,
76
              textColor,
77
              source
78
            }) => {
707 stevensc 79
              return (
80
                <li key={id}>
709 stevensc 81
                  <StyledEventContainer
82
                    color={textColor}
83
                    background={backgroundColor}
710 stevensc 84
                    onClick={() =>
85
                      source === 'external'
86
                        ? window.open(url, '_blank')
87
                        : getAdminAuth(url)
88
                    }
5 stevensc 89
                  >
90
                    <h4>
707 stevensc 91
                      <b>Evento: </b>
92
                      {title}
5 stevensc 93
                    </h4>
94
                    <span>
95
                      <b>Inicio: </b>
707 stevensc 96
                      {start}
5 stevensc 97
                    </span>
707 stevensc 98
                    {end && (
5 stevensc 99
                      <span>
100
                        <b>Fin: </b>
707 stevensc 101
                        {end}
5 stevensc 102
                      </span>
103
                    )}
709 stevensc 104
                  </StyledEventContainer>
707 stevensc 105
                </li>
106
              )
107
            }
108
          )
5 stevensc 109
        ) : (
655 stevensc 110
          <EmptySection message='No hay eventos disponibles' />
5 stevensc 111
        )}
112
      </ul>
113
    </StyledContainer>
114
  )
115
}
116
 
117
export default EventsList