Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 5 | Rev 2864 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
3
import { debounce } from '../../utils'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import { searchEntities } from '../../services/items'
6
 
7
import Spinner from '../../components/UI/Spinner'
8
import SearchBar from '../../components/UI/SearchBar'
9
import EmptySection from '../../components/UI/EmptySection'
10
import TitleSection from '../../components/UI/TitleSection'
11
import ProfileItem from '../../components/profile/ProfileItem'
12
import LoaderContainer from '../../components/UI/LoaderContainer'
13
 
14
const SavedJobsPage = () => {
15
  const [appliedJobs, setMyProfiles] = useState([])
16
  const [loading, setLoading] = useState(false)
17
  const [search, setSearch] = useState('')
18
 
19
  const labels = useSelector(({ intl }) => intl.labels)
20
  const dispatch = useDispatch()
21
 
22
  const getSavedJobs = async (search = '') => {
23
    setLoading(true)
24
    try {
25
      const { success, data } = await searchEntities('job/saved-jobs', search)
26
 
27
      if (!success) {
28
        dispatch(addNotification({ style: 'danger', msg: data }))
29
        setLoading(false)
30
        return
31
      }
32
 
33
      setMyProfiles(data)
34
    } catch (error) {
2194 stevensc 35
      dispatch(addNotification({ style: 'danger', msg: error.message }))
5 stevensc 36
    } finally {
37
      setLoading(false)
38
    }
39
  }
40
 
41
  const handleSearch = debounce((value) => setSearch(value), 500)
42
 
43
  useEffect(() => {
44
    getSavedJobs(search)
45
  }, [search])
46
 
47
  return (
2194 stevensc 48
    <main className='companies-info container'>
5 stevensc 49
      <TitleSection title={labels.jobs_saved} />
50
      <SearchBar onChange={handleSearch} />
51
      {loading ? (
52
        <LoaderContainer>
53
          <Spinner />
54
        </LoaderContainer>
55
      ) : (
2194 stevensc 56
        <ul className='companies-list'>
5 stevensc 57
          {appliedJobs.length ? (
58
            appliedJobs.map(({ id, title, employment_type, ...rest }) => (
59
              <ProfileItem
60
                key={id}
61
                name={title}
62
                status={employment_type}
63
                fetchCallback={getSavedJobs}
64
                {...rest}
65
                btnAcceptTitle={labels.view_job}
66
                btnLeaveTitle={labels.delete}
67
              />
68
            ))
69
          ) : (
70
            <EmptySection
2194 stevensc 71
              align='left'
5 stevensc 72
              message={labels.datatable_szerorecords}
73
            />
74
          )}
75
        </ul>
76
      )}
77
    </main>
78
  )
79
}
80
 
81
export default SavedJobsPage