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