Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
7279 stevensc 1
import React, { useEffect, useState } from 'react'
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'
9
 
10
const StyledContainer = styled(WidgetLayout)`
11
  padding: 1rem;
12
  h2 {
13
    font-size: 1.1rem;
14
    font-weight: 600;
15
    color: var(--title-color);
16
  }
7280 stevensc 17
  ul {
18
    display: flex;
19
    flex-direction: column;
7281 stevensc 20
    gap: 0.5rem;
7280 stevensc 21
    margin-top: 1rem;
22
  }
23
  a {
24
    display: block;
25
  }
7279 stevensc 26
`
27
 
28
const EventsList = () => {
29
  const [eventsAndTasks, setEventsAndTasks] = useState([])
30
  const dispatch = useDispatch()
31
 
32
  const getEvents = () => {
33
    axios
34
      .get('/helpers/next-events')
35
      .then((response) => {
36
        const { success, data } = response.data
37
 
38
        if (!success) {
39
          dispatch(addNotification({ style: 'danger', message: data }))
40
          return
41
        }
42
 
43
        setEventsAndTasks(data)
44
      })
45
      .catch((error) => {
46
        dispatch(
47
          addNotification({ style: 'danger', message: 'Ha ocurrido un error' })
48
        )
49
        throw new Error(error)
50
      })
51
  }
52
 
53
  useEffect(() => {
54
    getEvents()
55
  }, [])
56
 
57
  return (
58
    <StyledContainer>
59
      <h2>Eventos y Tareas</h2>
60
 
61
      <ul>
62
        {eventsAndTasks.length ? (
63
          eventsAndTasks.map((event) => {
64
            return (
65
              <li key={event.id}>
66
                <a href={event.url} target="_blank" rel="noreferrer">
67
                  <div
68
                    className="calendar-event"
69
                    style={{
70
                      color: event.textColor,
71
                      background: event.backgroundColor,
72
                    }}
73
                  >
74
                    <h4>
75
                      <b>Evento: </b> {event.title}
76
                    </h4>
77
                    <span>
78
                      <b>Inicio: </b>
7288 stevensc 79
                      {event.start}
7279 stevensc 80
                    </span>
81
                    {event.end && (
82
                      <span>
83
                        <b>Fin: </b>
7288 stevensc 84
                        {event.end}
7279 stevensc 85
                      </span>
86
                    )}
87
                  </div>
88
                </a>
89
              </li>
90
            )
91
          })
92
        ) : (
93
          <EmptySection message="No hay eventos disponibles" />
94
        )}
95
      </ul>
96
    </StyledContainer>
97
  )
98
}
99
 
100
export default EventsList