Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
7378 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { axios, debounce, jsonToParams } from '../../utils'
3
import { Container } from '@mui/material'
4
import { useSelector } from 'react-redux'
5
 
6
import Spinner from '../../components/UI/Spinner'
7
import SearchBar from '../../components/UI/SearchBar'
8
import ProfileItem from '../../components/profile/ProfileItem'
9
import EmptySection from '../../components/UI/EmptySection'
10
import TitleSection from '../../components/UI/TitleSection'
11
import LoaderContainer from '../../components/UI/LoaderContainer'
12
import PaginationComponent from '../../components/UI/PaginationComponent'
13
 
14
const ImpersonatePage = () => {
15
  const [users, setUsers] = useState([])
16
  const [search, setSearch] = useState('')
17
  const [currentPage, setCurrentPage] = useState(1)
18
  const [pages, setPages] = useState(1)
19
  const [loading, setLoading] = useState(false)
20
  const labels = useSelector(({ intl }) => intl.labels)
21
 
22
  const handleSearch = debounce((value) => setSearch(value), 500)
23
 
24
  const fetchUsers = async (page = 1, keyword = '') => {
25
    setLoading(true)
26
 
27
    setCurrentPage(page)
28
    const urlParams = {
29
      page,
30
      keyword,
31
    }
32
 
33
    await axios
34
      .get(`/impersonate?${jsonToParams(urlParams)}`)
35
      .then((response) => {
36
        const { success, data } = response.data
37
        if (success) {
38
          setUsers(data.current.items)
39
          setPages(data.total.pages)
40
        }
41
      })
42
    setLoading(false)
43
  }
44
 
45
  useEffect(() => {
46
    fetchUsers(currentPage, search)
47
  }, [currentPage, search])
48
 
49
  return (
50
    <>
7379 stevensc 51
      <Container component="main" className="companies-info ">
7378 stevensc 52
        <TitleSection title="Usuarios disponibles a personalizar" />
53
        <SearchBar onChange={handleSearch} />
54
        {loading ? (
55
          <LoaderContainer>
56
            <Spinner />
57
          </LoaderContainer>
58
        ) : (
7379 stevensc 59
          <ul className="companies-list mt-3">
7378 stevensc 60
            {users.length > 0 ? (
61
              users.map(
62
                ({ image, name, email, network, link_impersonate }, id) => (
63
                  <ProfileItem
64
                    isTopData
65
                    key={id}
66
                    image={image}
67
                    name={name}
68
                    email={email}
69
                    network={network}
70
                    link_impersonate={link_impersonate}
71
                  />
72
                )
73
              )
74
            ) : (
75
              <EmptySection
76
                align="left"
77
                message={labels.datatable_szerorecords}
78
              />
79
            )}
80
          </ul>
81
        )}
82
        <PaginationComponent
83
          pages={pages}
84
          currentActivePage={currentPage}
85
          onChangePage={fetchUsers}
7379 stevensc 86
          isRow
7378 stevensc 87
        />
88
      </Container>
89
    </>
90
  )
91
}
92
 
93
export default ImpersonatePage