Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2875 | Rev 3416 | 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, { useState } 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'
6
import { useFetch, useSearchQuery } from '@hooks'
8
 
-
 
9
import Spinner from '../../components/UI/Spinner'
7
 
10
import Input from '../../components/UI/inputs/Input'
-
 
11
import ProfileItem from '../../components/profile/ProfileItem'
8
import Input from '@components/UI/inputs/Input'
12
import TitleSection from '../../components/UI/TitleSection'
9
import TitleSection from '@components/UI/TitleSection'
13
import EmptySection from '../../components/UI/EmptySection'
10
import AddProfileModal from '@components/modals/AddProfileModal'
Línea 14... Línea 11...
14
import AddProfileModal from '../../components/modals/AddProfileModal'
11
import MyProfilesList from '@components/profile/MyProfilesList'
15
 
12
 
16
const MyProfilesPage = () => {
-
 
-
 
13
const MyProfilesPage = () => {
17
  const [isShowAddModal, setIsShowAddModal] = useState(false)
14
  const [isShowAddModal, setIsShowAddModal] = useState(false)
18
  const [myProfiles, setMyProfiles] = useState([])
-
 
Línea 19... Línea 15...
19
  const [loading, setLoading] = useState(false)
15
 
20
  const [search, setSearch] = useState('')
-
 
Línea 21... Línea 16...
21
 
16
  const toggleModal = () => setIsShowAddModal(!isShowAddModal)
22
  const labels = useSelector(({ intl }) => intl.labels)
-
 
23
  const dispatch = useDispatch()
-
 
24
 
17
 
25
  const getMyProfiles = async (search = '') => {
18
  const labels = useSelector(({ intl }) => intl.labels)
26
    setLoading(true)
-
 
27
    try {
-
 
28
      const { success, data } = await searchEntities(
-
 
29
        'profile/my-profiles',
-
 
30
        search
-
 
31
      )
-
 
32
 
-
 
33
      if (!success) {
-
 
34
        dispatch(addNotification({ style: 'danger', msg: data }))
-
 
35
        setLoading(false)
-
 
36
        return
-
 
37
      }
-
 
38
 
-
 
39
      setMyProfiles(data)
-
 
40
    } catch (error) {
-
 
41
      dispatch(addNotification({ style: 'danger', msg: error.message }))
19
 
42
    } finally {
20
  const { getStringParams, setParam } = useSearchQuery()
43
      setLoading(false)
21
  const { data, isLoading, refetch } = useFetch(
44
    }
-
 
45
  }
-
 
46
 
-
 
47
  const handleSearch = debounce((value) => setSearch(value), 500)
-
 
48
 
-
 
49
  const toggleModal = () => {
-
 
50
    setIsShowAddModal(!isShowAddModal)
-
 
51
  }
-
 
Línea 52... Línea 22...
52
 
22
    '/profile/my-profiles' + getStringParams()
53
  useEffect(() => {
23
  )
54
    getMyProfiles(search)
24
 
55
  }, [search])
25
  const handleSearch = debounce((e) => setParam('search', e.target.value))
56
 
26
 
57
  return (
27
  return (
58
    <main className='companies-info container'>
28
    <>
59
      <TitleSection
29
      <TitleSection
60
        title={labels.my_profiles}
-
 
61
        onAdd={toggleModal}
30
        title={labels.my_profiles}
62
        addLabel={labels.add}
-
 
63
      />
-
 
64
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
31
        onAdd={toggleModal}
65
      {loading ? (
-
 
66
        <Spinner />
-
 
67
      ) : (
-
 
68
        <ul className='companies-list'>
-
 
69
          {myProfiles.length ? (
32
        addLabel={labels.add}
70
            myProfiles.map(({ id, ...rest }) => (
33
      />
71
              <ProfileItem key={id} {...rest} fetchCallback={getMyProfiles} />
-
 
72
            ))
-
 
73
          ) : (
-
 
74
            <EmptySection
-
 
75
              align='left'
34
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
76
              message={labels.datatable_szerorecords}
35
      <MyProfilesList
77
            />
36
        profiles={data}
78
          )}
37
        loading={isLoading}
79
        </ul>
38
        onComplete={refetch}
80
      )}
39
      />
81
      <AddProfileModal
40
      <AddProfileModal
82
        show={isShowAddModal}
41
        show={isShowAddModal}
83
        getProfiles={() => getMyProfiles()}
42
        getProfiles={() => refetch()}
Línea 84... Línea 43...
84
        onHide={toggleModal}
43
        onHide={toggleModal}