Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6830 stevensc 1
import React, { useEffect, useState } from 'react'
6832 stevensc 2
import { axios } from '../../../utils'
3
import Avatar from '../../UI/AvatarImage'
4
import EmptySection from '../../UI/EmptySection'
5
import { useSelector } from 'react-redux'
6830 stevensc 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)
6832 stevensc 17
  const labels = useSelector(({ intl }) => intl.labels)
6830 stevensc 18
 
19
  const getData = () => {
20
    axios.get(url).then(({ data: response }) => {
21
      const { success, data } = response
22
      if (success) {
23
        setWidgetData(data.sort((a, b) => a.priority - b.priority).reverse())
24
      }
25
    })
26
  }
27
 
28
  useEffect(() => {
29
    getData()
30
  }, [])
31
 
32
  const dataSlice = () => {
33
    let infoFollows = [...widgetData]
34
    if (!lookMore) {
35
      infoFollows = infoFollows.slice(0, 3)
36
    }
37
    return infoFollows
38
  }
39
 
40
  return (
41
    <div className="sidebar__recent-item__container">
42
      <section className="sidebar__recent-item">
43
        <p>{title}</p>
44
        <button
45
          className="sidebar__recent-icon"
46
          onClick={() => setDisplayMenu(!displayMenu)}
47
        >
48
          {displayMenu ? <ExpandLessIcon /> : <ExpandMoreIcon />}
49
        </button>
50
      </section>
51
 
52
      <ul className={`helper__list ${displayMenu ? 'show' : 'hide'}`}>
53
        {widgetData.length ? (
54
          dataSlice().map(({ id, name, profile, image }) => (
55
            <li key={id}>
56
              <a
57
                href={profile}
58
                className="helper__list-item"
59
                target="secondary"
60
              >
61
                <Avatar imageUrl={image} size="md" name={name} />
62
                <span>{name}</span>
63
              </a>
64
            </li>
65
          ))
66
        ) : (
6832 stevensc 67
          <EmptySection message={labels.empty} />
6830 stevensc 68
        )}
69
 
70
        {widgetData.length >= 3 && (
71
          <li
72
            className="helper__list-item justify-content-center cursor-pointer py-2"
73
            onClick={() => setLookMore(!lookMore)}
74
          >
6832 stevensc 75
            <span>{lookMore ? labels.view_less : labels.view_more}</span>
6830 stevensc 76
          </li>
77
        )}
78
      </ul>
79
    </div>
80
  )
81
}
82
 
83
export default GroupsInfo