Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2875 | Rev 2932 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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