Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2864 | Rev 2936 | 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'
2864 stevensc 3
import { Search } from '@mui/icons-material'
4
 
5 stevensc 5
import { debounce } from '../../utils'
6
import { searchEntities } from '../../services/items'
7
import { addNotification } from '../../redux/notification/notification.actions'
8
 
9
import Spinner from '../../components/UI/Spinner'
2864 stevensc 10
import Input from '../../components/UI/inputs/Input'
5 stevensc 11
import TitleSection from '../../components/UI/TitleSection'
12
import EmptySection from '../../components/UI/EmptySection'
13
import ProfileItem from '../../components/profile/ProfileItem'
14
 
15
const AppliedJobsPage = () => {
16
  const [appliedJobs, setMyProfiles] = useState([])
17
  const [loading, setLoading] = useState(false)
18
  const [search, setSearch] = useState('')
19
  const labels = useSelector(({ intl }) => intl.labels)
20
 
21
  const dispatch = useDispatch()
22
 
23
  const getAppliedJobs = async (search = '') => {
24
    setLoading(true)
25
    try {
26
      const { success, data } = await searchEntities('job/applied-jobs', search)
27
 
28
      if (!success) {
29
        dispatch(addNotification({ style: 'danger', msg: data }))
30
        setLoading(false)
31
        return
32
      }
33
 
34
      setMyProfiles(data)
35
    } catch (error) {
2194 stevensc 36
      dispatch(addNotification({ style: 'danger', msg: error.message }))
5 stevensc 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
 
48
  return (
2194 stevensc 49
    <main className='companies-info container'>
5 stevensc 50
      <TitleSection title={labels.jobs_applied} />
2875 stevensc 51
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
5 stevensc 52
      {loading ? (
2864 stevensc 53
        <Spinner />
5 stevensc 54
      ) : (
2194 stevensc 55
        <ul className='companies-list'>
5 stevensc 56
          {appliedJobs.length ? (
57
            appliedJobs.map(({ id, title, employment_type, ...rest }) => (
58
              <ProfileItem
59
                key={id}
60
                name={title}
61
                status={employment_type}
62
                {...rest}
63
                fetchCallback={getAppliedJobs}
64
                btnAcceptTitle={labels.view_job}
65
                btnLeaveTitle={labels.job_request_cancel}
66
              />
67
            ))
68
          ) : (
69
            <EmptySection
2194 stevensc 70
              align='left'
5 stevensc 71
              message={labels.datatable_szerorecords}
72
            />
73
          )}
74
        </ul>
75
      )}
76
    </main>
77
  )
78
}
79
 
80
export default AppliedJobsPage