Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4188 | Rev 4190 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 4188 Rev 4189
Línea 1... Línea 1...
1
import axios from 'axios'
1
import axios from 'axios'
2
import React from 'react'
2
import React, { useEffect, useState } from 'react'
3
import { useEffect } from 'react'
3
import { useDispatch } from 'react-redux'
-
 
4
import { addNotification } from '../../redux/notification/notification.actions'
Línea 4... Línea 5...
4
 
5
 
Línea -... Línea 6...
-
 
6
const EventsList = () => {
-
 
7
 
-
 
8
    const [events, setEvents] = useState([])
5
const EventsList = () => {
9
    const dispatch = useDispatch()
6
 
10
 
7
    const getEvents = async () => {
11
    const getEvents = async () => {
Línea 8... Línea 12...
8
        try {
12
        try {
-
 
13
            const { data: response } = await axios.get('/helpers/next-events')
-
 
14
 
-
 
15
            if (!response.success) {
Línea -... Línea 16...
-
 
16
                dispatch(addNotification({ style: 'danger', message: response.data }))
9
            const { data: response } = await axios.get('/helpers/next-events')
17
                return
-
 
18
            }
10
 
19
 
11
            console.log(response)
20
            setEvents(response.data)
12
 
21
        } catch (error) {
-
 
22
            dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
13
        } catch (error) {
23
            console.log(`Error: ${error.message}`)
14
            console.log(error)
24
        }
15
        }
25
    }
Línea 16... Línea 26...
16
    }
26
 
-
 
27
    useEffect(() => {
-
 
28
        getEvents()
-
 
29
    }, [])
-
 
30
 
-
 
31
    return (
-
 
32
        <div className='$peopleYouMayKnow'>
-
 
33
            <div className="sd-title d-flex align-items-center justify-content-between">
-
 
34
                <h3>Proximos eventos</h3>
-
 
35
            </div>
-
 
36
            <div className="w-100 d-flex flex-column">
-
 
37
                {events.length
-
 
38
                    ? events.map((event) =>
-
 
39
                        <div className='user' key={event.id} style={{ background: event.backgroundColor }}>
-
 
40
                            <div className="d-inline-flex align-items-center flex-column" style={{ gap: '.5rem' }}>
-
 
41
                                <h4 className='break-ellipsis'>{event.title}</h4>
-
 
42
                                <span>{new Date(event.start).toLocaleString()}</span>
-
 
43
                                <span>{new Date(event.end).toLocaleString()}</span>
-
 
44
                            </div>
-
 
45
                            <a
17
    useEffect(() => {
46
                                className="btn btn-primary ml-auto"
-
 
47
                                href={event.url}
-
 
48
                            >
-
 
49
                                Ver Grupo
-
 
50
                            </a>
-
 
51
                        </div>
18
        getEvents()
52
                    )
19
    }, [])
53
                    : <div className="view-more">No hay eventos</div>
Línea 20... Línea 54...
20
 
54
                }
21
    return (
55
            </div>