Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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