Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5407 | Rev 5431 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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:',
5415 stevensc 9
  url = '/helpers/my-groups',
10
  btnLabelAccept = 'Ver'
5407 stevensc 11
}) => {
12
  const [widgetData, setWidgetData] = useState([])
13
  const [lookMore, setLookMore] = useState(false)
14
  const labels = useSelector(state => state.labels)
15
 
16
  const getData = () => {
17
    axios.get(url)
18
      .then(({ data: response }) => {
19
        const { success, data } = response
20
        if (success) {
21
          setWidgetData(data.sort((a, b) => a.priority - b.priority).reverse())
22
        }
23
      })
24
  }
25
 
26
  useEffect(() => {
27
    getData()
28
  }, [])
29
 
30
  const dataSlice = () => {
31
    let infoFollows = [...widgetData]
5415 stevensc 32
 
33
    if (!lookMore) infoFollows = infoFollows.slice(0, 1)
34
 
5407 stevensc 35
    return infoFollows
36
  }
37
 
38
  return (
39
    <div className='suggests_widget'>
40
      <div className="suggests_widget-header">
41
        <h3>{title}</h3>
42
        {widgetData.length >= 3 &&
43
          <span onClick={() => setLookMore(!lookMore)}>
44
            {lookMore ? labels.VIEW_LESS : labels.VIEW_MORE}
45
          </span>}
46
      </div>
47
      <div className="suggest-list">
48
        {widgetData.length
5415 stevensc 49
          ? dataSlice().map((suggest) => <SuggestWidget.Item key={suggest.id} suggest={suggest} btnLabelAccept={btnLabelAccept}/>)
5407 stevensc 50
          : <EmptySection align='left' message={labels.DATATABLE_EMPTY} />
51
        }
52
      </div>
53
    </div>
54
  )
55
}
56
 
5415 stevensc 57
const Item = ({ suggest, btnLabelAccept }) => {
58
  return (
59
    <div className='user'>
60
      <div className="d-inline-flex align-items-center">
61
        <a href={suggest.profile} target="_blank" rel="noreferrer">
62
          <img src={suggest.image} alt={`${suggest.name} profile image`} />
63
        </a>
64
        <h4 className='break-ellipsis'>{suggest.name}</h4>
65
      </div>
66
      <a className="btn btn-primary ml-auto" href={suggest.profile}>
67
        {btnLabelAccept}
68
      </a>
69
    </div>
70
  )
71
}
72
 
73
SuggestWidget.Item = Item
74
 
5407 stevensc 75
export default SuggestWidget