Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
3
import { debounce } from '../../utils'
4
import { searchEntities } from '../../services/items'
5
import { addNotification } from '../../redux/notification/notification.actions'
6
 
7
import Spinner from '../../components/UI/Spinner'
8
import SearchBar from '../../components/UI/SearchBar'
9
import TitleSection from '../../components/UI/TitleSection'
10
import EmptySection from '../../components/UI/EmptySection'
11
import ProfileItem from '../../components/profile/ProfileItem'
12
import LoaderContainer from '../../components/UI/LoaderContainer'
13
 
14
const InvitationsReceivedPage = () => {
15
  const [invitationsReceived, setMyProfiles] = useState([])
16
  const [loading, setLoading] = useState(false)
17
  const [search, setSearch] = useState('')
18
 
19
  const labels = useSelector(({ intl }) => intl.labels)
20
  const dispatch = useDispatch()
21
 
22
  const getInvitationsReceived = async (search = '') => {
23
    setLoading(true)
24
    try {
25
      const { success, data } = await searchEntities(
26
        'connection/invitations-received',
27
        search
28
      )
29
 
30
      if (!success) {
31
        dispatch(addNotification({ style: 'danger', msg: data }))
32
        setLoading(false)
33
        return
34
      }
35
 
36
      setMyProfiles(data)
37
    } catch (error) {
2194 stevensc 38
      dispatch(addNotification({ style: 'danger', msg: error.message }))
5 stevensc 39
    } finally {
40
      setLoading(false)
41
    }
42
  }
43
 
44
  const handleSearch = debounce((value) => setSearch(value), 500)
45
 
46
  useEffect(() => {
47
    getInvitationsReceived(search)
48
  }, [search])
49
 
50
  return (
2194 stevensc 51
    <main className='companies-info container'>
5 stevensc 52
      <TitleSection title={labels.invitations_received} />
53
      <SearchBar onChange={handleSearch} />
54
      {loading ? (
55
        <LoaderContainer>
56
          <Spinner />
57
        </LoaderContainer>
58
      ) : (
2194 stevensc 59
        <ul className='companies-list'>
5 stevensc 60
          {invitationsReceived.length ? (
61
            invitationsReceived.map(({ id, ...rest }) => (
62
              <ProfileItem
63
                key={id}
64
                {...rest}
65
                fetchCallback={getInvitationsReceived}
66
              />
67
            ))
68
          ) : (
69
            <EmptySection
2194 stevensc 70
              align='left'
5 stevensc 71
              message={labels.datatable_szerorecords}
72
            />
73
          )}
74
        </ul>
75
      )}
76
    </main>
77
  )
78
}
79
 
80
export default InvitationsReceivedPage