Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
4189 stevensc 1
import React, { useEffect, useState } from 'react'
4191 stevensc 2
import axios from '../../utils/axios'
4189 stevensc 3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../redux/notification/notification.actions'
4188 stevensc 5
 
6
const EventsList = () => {
4982 stevensc 7
    const [eventsAndTasks, setEventsAndTasks] = useState([])
4189 stevensc 8
    const dispatch = useDispatch()
9
 
4188 stevensc 10
    const getEvents = async () => {
11
        try {
4702 stevensc 12
            const { data: response } = await axios.get('/helpers/next-events')
4188 stevensc 13
 
4189 stevensc 14
            if (!response.success) {
15
                dispatch(addNotification({ style: 'danger', message: response.data }))
16
                return
17
            }
4188 stevensc 18
 
4982 stevensc 19
            setEventsAndTasks(response.data)
4188 stevensc 20
        } catch (error) {
4189 stevensc 21
            dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
22
            console.log(`Error: ${error.message}`)
4188 stevensc 23
        }
24
    }
4189 stevensc 25
 
4188 stevensc 26
    useEffect(() => {
27
        getEvents()
28
    }, [])
29
 
4705 stevensc 30
    return (
4982 stevensc 31
        <div className='task-widget'>
32
            <div className="sd-title d-flex align-items-center justify-content-between">
4983 stevensc 33
                <h3>Eventos y Tareas</h3>
4982 stevensc 34
            </div>
35
            <div className="d-flex flex-column" style={{ gap: '.5rem', maxHeight: 300, overflow: 'hidden scroll' }}>
36
                {eventsAndTasks.length
37
                    ? eventsAndTasks.map((event) => {
38
                        const eventStart = new Date(event.start).toLocaleString()
39
                        const eventEnd = new Date(event.end).toLocaleString()
4701 stevensc 40
 
4982 stevensc 41
                        return (
42
                            <a
43
                                key={event.id}
44
                                href={event.url}
45
                                target='_blank'
46
                                rel="noreferrer"
47
                            >
48
                                <div className='calendar-event' style={{ color: event.textColor, background: event.backgroundColor }}>
49
                                    <h4>
50
                                        <b>Evento: </b> {event.title}
51
                                    </h4>
52
                                    <span>
53
                                        <b>Inicio: </b>{eventStart}
54
                                    </span>
55
                                    {event.end &&
4705 stevensc 56
                                        <span>
57
                                            <b>Fin: </b>{eventEnd}
58
                                        </span>
4982 stevensc 59
                                    }
60
                                </div>
61
                            </a>
62
                        )
63
                    })
64
                    : <div className="view-more">No hay eventos</div>
65
                }
4189 stevensc 66
            </div>
4982 stevensc 67
        </div>
4188 stevensc 68
    )
69
}
70
 
71
export default EventsList