Proyectos de Subversion LeadersLinked - SPA

Rev

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

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