Rev 706 | Rev 709 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
import { axios } from '../../utils'
import { useDispatch } from 'react-redux'
import { addNotification } from '../../redux/notification/notification.actions'
import styled from 'styled-components'
import WidgetLayout from '../widgets/WidgetLayout'
import EmptySection from '../UI/EmptySection'
import useFetch from '../../hooks/useFetch'
const StyledContainer = styled(WidgetLayout)`
padding: 1rem;
h2 {
font-size: 1.1rem;
font-weight: 600;
color: var(--title-color);
}
ul {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-top: 1rem;
}
a {
display: block;
}
`
const EventsList = () => {
const { data: eventsAndTasks } = useFetch('/helpers/next-events', [])
const dispatch = useDispatch()
const getBackendVarUrl = (url) => {
axios
.get(url)
.then(({ data: responseData }) => {
const { data, success } = responseData
if (!success) {
throw new Error('Error interno. Por favor, intente más tarde.')
}
window.open(data, '_blank')
})
.catch((err) => {
dispatch(addNotification({ style: 'danger', msg: err.message }))
})
}
return (
<StyledContainer>
<h2>Eventos y Tareas</h2>
<ul>
{eventsAndTasks.length ? (
eventsAndTasks.map(
({ id, url, title, backgroundColor, start, end, textColor }) => {
return (
<li key={id}>
<div
className='calendar-event'
style={{
color: textColor,
background: backgroundColor
}}
onClick={() => getBackendVarUrl(url)}
>
<h4>
<b>Evento: </b>
{title}
</h4>
<span>
<b>Inicio: </b>
{start}
</span>
{end && (
<span>
<b>Fin: </b>
{end}
</span>
)}
</div>
</li>
)
}
)
) : (
<EmptySection message='No hay eventos disponibles' />
)}
</ul>
</StyledContainer>
)
}
export default EventsList