| 5407 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
|
|
2 |
import axios from 'axios'
|
|
|
3 |
import React, { useEffect, useState } from 'react'
|
|
|
4 |
import EmptySection from '../../empty-section/EmptySection'
|
|
|
5 |
import { useSelector } from 'react-redux'
|
|
|
6 |
|
|
|
7 |
const SuggestWidget = ({
|
|
|
8 |
title = 'Mis Grupos:',
|
|
|
9 |
url = '/helpers/my-groups'
|
|
|
10 |
}) => {
|
|
|
11 |
const [widgetData, setWidgetData] = useState([])
|
|
|
12 |
const [lookMore, setLookMore] = useState(false)
|
|
|
13 |
const labels = useSelector(state => state.labels)
|
|
|
14 |
|
|
|
15 |
const getData = () => {
|
|
|
16 |
axios.get(url)
|
|
|
17 |
.then(({ data: response }) => {
|
|
|
18 |
const { success, data } = response
|
|
|
19 |
if (success) {
|
|
|
20 |
setWidgetData(data.sort((a, b) => a.priority - b.priority).reverse())
|
|
|
21 |
}
|
|
|
22 |
})
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
useEffect(() => {
|
|
|
26 |
getData()
|
|
|
27 |
}, [])
|
|
|
28 |
|
|
|
29 |
const dataSlice = () => {
|
|
|
30 |
let infoFollows = [...widgetData]
|
|
|
31 |
if (!lookMore) {
|
|
|
32 |
infoFollows = infoFollows.slice(0, 1)
|
|
|
33 |
}
|
|
|
34 |
return infoFollows
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
return (
|
|
|
38 |
<div className='suggests_widget'>
|
|
|
39 |
<div className="suggests_widget-header">
|
|
|
40 |
<h3>{title}</h3>
|
|
|
41 |
{widgetData.length >= 3 &&
|
|
|
42 |
<span onClick={() => setLookMore(!lookMore)}>
|
|
|
43 |
{lookMore ? labels.VIEW_LESS : labels.VIEW_MORE}
|
|
|
44 |
</span>}
|
|
|
45 |
</div>
|
|
|
46 |
<div className="suggest-list">
|
|
|
47 |
{widgetData.length
|
|
|
48 |
? dataSlice().map(({ id, name, image, profile }) =>
|
|
|
49 |
<div className='user' key={id}>
|
|
|
50 |
<div className="d-inline-flex align-items-center" style={{ gap: '.5rem' }}>
|
|
|
51 |
<a href={profile} target="_blank" rel="noreferrer">
|
|
|
52 |
<img src={image} alt={`${name} profile image`} />
|
|
|
53 |
</a>
|
|
|
54 |
<h4 className='break-ellipsis'>{name}</h4>
|
|
|
55 |
</div>
|
|
|
56 |
<a className="btn btn-primary ml-auto" href={profile}>
|
|
|
57 |
{labels.GROUP_VIEW}
|
|
|
58 |
</a>
|
|
|
59 |
</div>
|
|
|
60 |
)
|
|
|
61 |
: <EmptySection align='left' message={labels.DATATABLE_EMPTY} />
|
|
|
62 |
}
|
|
|
63 |
</div>
|
|
|
64 |
</div>
|
|
|
65 |
)
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
export default SuggestWidget
|