Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5415 | Rev 5435 | 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
 
5431 stevensc 33
    if (!lookMore) {
34
      infoFollows = infoFollows.slice(0, 1)
35
    }
5415 stevensc 36
 
5407 stevensc 37
    return infoFollows
38
  }
39
 
40
  return (
41
    <div className='suggests_widget'>
42
      <div className="suggests_widget-header">
43
        <h3>{title}</h3>
44
        {widgetData.length >= 3 &&
45
          <span onClick={() => setLookMore(!lookMore)}>
46
            {lookMore ? labels.VIEW_LESS : labels.VIEW_MORE}
47
          </span>}
48
      </div>
49
      <div className="suggest-list">
50
        {widgetData.length
5415 stevensc 51
          ? dataSlice().map((suggest) => <SuggestWidget.Item key={suggest.id} suggest={suggest} btnLabelAccept={btnLabelAccept}/>)
5407 stevensc 52
          : <EmptySection align='left' message={labels.DATATABLE_EMPTY} />
53
        }
54
      </div>
55
    </div>
56
  )
57
}
58
 
5415 stevensc 59
const Item = ({ suggest, btnLabelAccept }) => {
60
  return (
61
    <div className='user'>
62
      <div className="d-inline-flex align-items-center">
63
        <a href={suggest.profile} target="_blank" rel="noreferrer">
64
          <img src={suggest.image} alt={`${suggest.name} profile image`} />
65
        </a>
66
        <h4 className='break-ellipsis'>{suggest.name}</h4>
67
      </div>
68
      <a className="btn btn-primary ml-auto" href={suggest.profile}>
69
        {btnLabelAccept}
70
      </a>
71
    </div>
72
  )
73
}
74
 
75
SuggestWidget.Item = Item
76
 
5407 stevensc 77
export default SuggestWidget