Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4313 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { useEffect } from 'react'
3
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
4
import GroupIcon from '@mui/icons-material/Group'
5
import { useState } from 'react'
6
import axios from '../../../../utils/axios'
4314 stevensc 7
import EmptySection from '../../../../shared/empty-section/EmptySection'
4313 stevensc 8
 
9
const HelpersContainer = (props) => {
10
  const [recentItem1, setrecentItem1] = useState(false)
11
  const [recentItem2, setrecentItem2] = useState(false)
12
 
13
  return (
14
    <div className='sidebar__bottom'>
15
      <HelpersContainer.Item />
16
    </div>
17
  )
18
}
19
 
20
const Item = ({ url = '/helpers/my-groups', title = 'Mis grupos' }) => {
21
 
22
  const [widgetData, setWidgetData] = useState([]);
23
  const [lookMore, setLookMore] = useState(false);
24
 
25
  const getData = () => {
26
    axios.get(url)
27
      .then(({ data: response }) => {
28
        const { success, data } = response
29
        if (success) {
30
          setWidgetData(data.sort((a, b) => a.priority - b.priority).reverse());
31
        }
32
      });
33
  }
34
 
35
  useEffect(() => {
36
    getData()
37
  }, []);
38
 
39
  const dataSlice = () => {
40
    let infoFollows = [...widgetData]
41
    if (!lookMore) {
4315 stevensc 42
      infoFollows = infoFollows.slice(0, 3)
4313 stevensc 43
    }
44
    return infoFollows
45
  }
46
 
47
  return (
48
    <div className='sidebar__recent-item__container'>
49
 
50
      <section className='sidebar__recent-item'>
51
        <p>{title}</p>
52
        <div className='sidebar__recent-actions'>
4314 stevensc 53
          <button className='sidebar__recent-icon' onClick={() => setLookMore(!lookMore)}>
4313 stevensc 54
            <ExpandMoreIcon />
55
          </button>
56
        </div>
4314 stevensc 57
      </section>
4313 stevensc 58
 
4314 stevensc 59
      <ul className={`helper__list ${lookMore ? 'show' : 'hide'}`}>
60
        {widgetData.length
61
          ? dataSlice().map(({ id, name, profile }) =>
62
            <li key={id}>
4315 stevensc 63
              <a href={profile} className='helper__list-itemf'>
4313 stevensc 64
                <GroupIcon />
4314 stevensc 65
                <span>{name}</span>
66
              </a>
67
            </li>
68
          )
69
          : <EmptySection message='Sin resultados' />
70
        }
4313 stevensc 71
 
4314 stevensc 72
      </ul>
73
 
4313 stevensc 74
    </div>
75
  )
76
}
77
 
78
HelpersContainer.Item = Item
79
 
80
export default HelpersContainer