Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2875 | Rev 2886 | 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'
-
 
13
import ProfileItem from '../../components/profile/ProfileItem'
-
 
Línea 14... Línea 6...
14
import PaginationComponent from '../../components/UI/PaginationComponent'
6
import { useFetch, useSearchQuery } from '@hooks'
15
 
7
 
16
const MyConnectionsPage = () => {
8
import Input from '@components/UI/inputs/Input'
17
  const [myConnections, setMyConnections] = useState([])
9
import TitleSection from '@components/UI/TitleSection'
18
  const [currentPage, setCurrentPage] = useState(1)
-
 
19
  const [totalPages, setTotalPages] = useState(1)
-
 
Línea -... Línea 10...
-
 
10
import MyConnectionsList from '@components/connections/MyConnectionsList'
20
  const [loading, setLoading] = useState(false)
11
import PaginationComponent from '@components/UI/PaginationComponent'
21
  const [search, setSearch] = useState('')
-
 
Línea 22... Línea 12...
22
 
12
 
23
  const labels = useSelector(({ intl }) => intl.labels)
-
 
24
  const dispatch = useDispatch()
-
 
25
 
13
const MyConnectionsPage = () => {
26
  const getMyConnections = async (search = '', page = 1) => {
14
  const labels = useSelector(({ intl }) => intl.labels)
27
    setLoading(true)
-
 
28
    try {
15
 
29
      const { success, data } = await searchEntities(
-
 
30
        'connection/my-connections',
-
 
31
        search,
-
 
32
        page
-
 
33
      )
-
 
34
 
-
 
35
      if (!success) {
-
 
36
        dispatch(addNotification({ style: 'danger', msg: data }))
-
 
37
        setLoading(false)
-
 
38
        return
-
 
39
      }
-
 
40
 
-
 
41
      setMyConnections(data.current.items)
-
 
42
      setCurrentPage(data.current.page)
-
 
43
      setTotalPages(data.total.pages)
-
 
44
    } catch (error) {
16
  const { getParam, setParam } = useSearchQuery()
45
      dispatch(addNotification({ style: 'danger', msg: error.message }))
17
  const { data, isLoading, refetch } = useFetch(
46
    } finally {
18
    `/connection/my-connections?search=${getParam('search')}?page=${getParam(
47
      setLoading(false)
19
      'page'
48
    }
-
 
49
  }
-
 
50
 
-
 
51
  const handleSearch = debounce((value) => setSearch(value), 500)
-
 
52
 
-
 
53
  const onChangePageHandler = (currentPage) => {
-
 
54
    setCurrentPage(currentPage)
-
 
55
  }
-
 
Línea 56... Línea 20...
56
 
20
    )}`
57
  useEffect(() => {
21
  )
58
    getMyConnections(search, currentPage)
22
 
59
  }, [search, currentPage])
23
  const handleSearch = debounce((e) => setParam('search', e.target.value), 500)
60
 
-
 
61
  return (
-
 
62
    <main className='companies-info container'>
-
 
63
      <TitleSection title={labels.first_level_persons} />
-
 
64
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
24
 
65
      {loading ? (
25
  return (
66
        <Spinner />
-
 
67
      ) : (
-
 
68
        <ul className='companies-list'>
26
    <>
69
          {myConnections.length ? (
-
 
70
            myConnections.map(({ id, ...rest }) => (
-
 
71
              <ProfileItem
-
 
72
                key={id}
-
 
73
                isTopData
-
 
74
                {...rest}
-
 
75
                fetchCallback={getMyConnections}
27
      <TitleSection title={labels.first_level_persons} />
76
              />
-
 
77
            ))
-
 
78
          ) : (
-
 
79
            <EmptySection
-
 
80
              align='left'
28
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
81
              message={labels.datatable_szerorecords}
29
      <MyConnectionsList
82
            />
30
        connections={data.current.items}
83
          )}
31
        loading={isLoading}
84
        </ul>
32
        onComplete={refetch}
85
      )}
33
      />
86
      <PaginationComponent
34
      <PaginationComponent
87
        isRow
35
        isRow
88
        pages={totalPages}
36
        pages={data.total.pages}
89
        currentActivePage={currentPage}
37
        currentActivePage={data.current.page}
Línea 90... Línea 38...
90
        onChangePage={onChangePageHandler}
38
        onChangePage={(page) => setParam('page', page)}