Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2322 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5179 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { connect } from 'react-redux'
3
import { debounce } from '../../../utils'
4
import { searchEntities } from '../../../services/search'
5
import { addNotification } from '../../../redux/notification/notification.actions'
6
import Spinner from '../../../shared/loading-spinner/Spinner'
7
import Profile from '../../../components/Profile'
8
import SearchList from '../../../components/SearchList'
9
import TitleSection from '../../../components/TitleSection'
10
import EmptySection from '../../../shared/empty-section/EmptySection'
1 www 11
 
1601 steven 12
const RequestsSent = () => {
5179 stevensc 13
  const [sendRequests, setSendRequests] = useState([])
14
  const [loading, setLoading] = useState(true)
1 www 15
 
16
  useEffect(() => {
5179 stevensc 17
    getSendRequests()
18
  }, [])
1 www 19
 
5179 stevensc 20
  const getSendRequests = async (searchValue = '') => {
21
    setLoading(true)
22
    const response = await searchEntities('group/requests-sent', searchValue)
1 www 23
 
5179 stevensc 24
    if (!response.success) {
25
      addNotification({ style: 'danger', msg: response.data })
26
      setLoading(false)
27
      return
28
    }
29
 
30
    setSendRequests(response.data)
31
    setLoading(false)
32
  }
33
 
34
  const handleSearch = debounce((value) => getSendRequests(value), 500)
35
 
1 www 36
  return (
5179 stevensc 37
    <section className="companies-info container">
38
      <TitleSection title={LABELS.REQUESTS_SENT} />
39
      <SearchList onChange={handleSearch} />
40
      <div className="companies-list">
41
        {loading && <Spinner />}
42
        {(!loading && Boolean(!sendRequests.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
43
        {(!loading && Boolean(sendRequests.length)) &&
44
          sendRequests.map((request, index) =>
45
            <Profile
46
              {...request}
47
              key={index}
48
              fetchCallback={getSendRequests}
49
              btnAcceptTitle={LABELS.GROUP_VIEW}
50
            />
51
          )}
1 www 52
      </div>
53
    </section>
5179 stevensc 54
  )
55
}
1 www 56
 
57
const mapDispatchToProps = {
5179 stevensc 58
  addNotification: (notification) => addNotification(notification)
59
}
1 www 60
 
5179 stevensc 61
export default connect(null, mapDispatchToProps)(RequestsSent)