| 6830 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
|
|
2 |
import React, { useEffect, useState } from 'react'
|
|
|
3 |
import axios from '../../../../utils/axios'
|
|
|
4 |
import Avatar from '../../../../shared/Avatar/Avatar'
|
|
|
5 |
import EmptySection from '../../../../shared/empty-section/EmptySection'
|
|
|
6 |
import ExpandLessIcon from '@mui/icons-material/ExpandLess'
|
|
|
7 |
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
|
|
|
8 |
|
|
|
9 |
const GroupsInfo = ({
|
|
|
10 |
url = '/helpers/my-groups',
|
|
|
11 |
title = 'Mis grupos',
|
|
|
12 |
display = false,
|
|
|
13 |
}) => {
|
|
|
14 |
const [widgetData, setWidgetData] = useState([])
|
|
|
15 |
const [displayMenu, setDisplayMenu] = useState(display)
|
|
|
16 |
const [lookMore, setLookMore] = useState(false)
|
|
|
17 |
|
|
|
18 |
const getData = () => {
|
|
|
19 |
axios.get(url).then(({ data: response }) => {
|
|
|
20 |
const { success, data } = response
|
|
|
21 |
if (success) {
|
|
|
22 |
setWidgetData(data.sort((a, b) => a.priority - b.priority).reverse())
|
|
|
23 |
}
|
|
|
24 |
})
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
useEffect(() => {
|
|
|
28 |
getData()
|
|
|
29 |
}, [])
|
|
|
30 |
|
|
|
31 |
const dataSlice = () => {
|
|
|
32 |
let infoFollows = [...widgetData]
|
|
|
33 |
if (!lookMore) {
|
|
|
34 |
infoFollows = infoFollows.slice(0, 3)
|
|
|
35 |
}
|
|
|
36 |
return infoFollows
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
return (
|
|
|
40 |
<div className="sidebar__recent-item__container">
|
|
|
41 |
<section className="sidebar__recent-item">
|
|
|
42 |
<p>{title}</p>
|
|
|
43 |
<button
|
|
|
44 |
className="sidebar__recent-icon"
|
|
|
45 |
onClick={() => setDisplayMenu(!displayMenu)}
|
|
|
46 |
>
|
|
|
47 |
{displayMenu ? <ExpandLessIcon /> : <ExpandMoreIcon />}
|
|
|
48 |
</button>
|
|
|
49 |
</section>
|
|
|
50 |
|
|
|
51 |
<ul className={`helper__list ${displayMenu ? 'show' : 'hide'}`}>
|
|
|
52 |
{widgetData.length ? (
|
|
|
53 |
dataSlice().map(({ id, name, profile, image }) => (
|
|
|
54 |
<li key={id}>
|
|
|
55 |
<a
|
|
|
56 |
href={profile}
|
|
|
57 |
className="helper__list-item"
|
|
|
58 |
target="secondary"
|
|
|
59 |
>
|
|
|
60 |
<Avatar imageUrl={image} size="md" name={name} />
|
|
|
61 |
<span>{name}</span>
|
|
|
62 |
</a>
|
|
|
63 |
</li>
|
|
|
64 |
))
|
|
|
65 |
) : (
|
|
|
66 |
<EmptySection message={LABELS.DATATABLE_EMPTY} />
|
|
|
67 |
)}
|
|
|
68 |
|
|
|
69 |
{widgetData.length >= 3 && (
|
|
|
70 |
<li
|
|
|
71 |
className="helper__list-item justify-content-center cursor-pointer py-2"
|
|
|
72 |
onClick={() => setLookMore(!lookMore)}
|
|
|
73 |
>
|
|
|
74 |
<span>{lookMore ? LABELS.VIEW_LESS : LABELS.VIEW_MORE}</span>
|
|
|
75 |
</li>
|
|
|
76 |
)}
|
|
|
77 |
</ul>
|
|
|
78 |
</div>
|
|
|
79 |
)
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
export default GroupsInfo
|