Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
7268 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { axios } from '../../utils'
3
import { useParams } from 'react-router-dom'
4
import { useDispatch } from 'react-redux'
5
import { getBackendVars } from '../../services/backendVars'
6
import { addNotification } from '../../redux/notification/notification.actions'
7
import { Container, Grid, Tab, Tabs } from '@mui/material'
8
import parse from 'html-react-parser'
9
 
10
import Description from '../../components/job/Description'
11
import JobAttr from '../../components/job/JobAttr'
12
import ClientInfo from '../../components/job/ClientInfo'
13
import ApplyModal from '../../components/job/ApplyModal'
14
 
15
const JobViewPage = () => {
16
  const [job, setJob] = useState({})
17
  const [isJobApplied, setIsJobApplied] = useState(false)
18
  const [showApplyModal, setShowApplyModal] = useState(false)
19
  const [loading, setLoading] = useState(false)
20
  const { uuid } = useParams()
21
  const dispatch = useDispatch()
22
 
23
  const {
7269 stevensc 24
    jobId = '',
25
    companyId = '',
26
    companyImage = '',
27
    jobTitle = '',
28
    companyName = '',
29
    timeElapsed = '',
30
    location = '',
31
    jobSaved = '',
32
    lastDateOfApplication = '',
33
    employmentType = '',
34
    jobCategory = '',
35
    jobDescription = '',
36
    jobSkills = '',
37
    totalApplications = '',
38
    jobVisits = '',
39
    experience = '',
40
    salary = '',
41
    jobLanguages = '',
42
    jobDegrees = '',
43
    companyIndustry = '',
44
    companySize = '',
45
    companyAddress = '',
46
    companyWebsite = '',
47
    companyFoundationYear = '',
48
    jobApplyOperation = '',
49
    userProfiles = '',
7268 stevensc 50
  } = job
51
 
52
  const handleShowApplyModal = () => {
53
    setShowApplyModal(!showApplyModal)
54
  }
55
 
56
  const handleApply = () => {
57
    setIsJobApplied(!isJobApplied)
58
  }
59
 
60
  const getJob = () => {
7270 stevensc 61
    getBackendVars(`/job/view/${uuid}}`)
7268 stevensc 62
      .then((response) => {
63
        console.log(response)
64
        setJob(response)
65
      })
66
      .catch((error) => {
67
        throw new Error(error)
68
      })
69
  }
70
 
71
  const removeApply = async () => {
72
    setLoading(true)
73
    axios
74
      .post(`/job/remove-apply-job/${job}`)
75
      .then(({ data: response }) => {
76
        const { data, success } = response
77
 
78
        if (!success) {
79
          const errorMessage =
80
            typeof data === 'string'
81
              ? data
82
              : 'Ha ocurrido un error, por favor intente más tarde'
83
 
84
          dispatch(addNotification({ styled: 'danger', msg: errorMessage }))
85
        }
86
 
87
        handleApply()
88
      })
89
      .finally(() => setLoading(false))
90
  }
91
 
92
  useEffect(() => {
93
    getJob()
94
  }, [])
95
 
96
  useEffect(() => {
97
    setIsJobApplied(jobApplyOperation === 'apply')
98
  }, [jobApplyOperation])
99
 
100
  return (
101
    <>
102
      <Container as="main" className="px-0">
103
        <Tabs>
104
          <Tab label="Avance" value="user" disableRipple />
105
          <Tab label="Información" value="group" disableRipple />
106
        </Tabs>
107
        <Grid container spacing={2}>
7276 stevensc 108
          <Grid item xs={12} md={8} spacing={3}>
7268 stevensc 109
            <Description
110
              jobId={jobId}
111
              companyId={companyId}
112
              companyImage={companyImage}
113
              jobTitle={jobTitle}
114
              companyName={companyName}
115
              timeElapsed={timeElapsed}
116
              location={location}
117
              jobSaved={jobSaved}
118
              lastDateOfApplication={lastDateOfApplication}
119
              employmentType={employmentType}
120
              jobCategory={jobCategory}
121
              jobDescription={jobDescription}
122
              jobSkills={jobSkills}
123
              totalApplications={totalApplications}
124
              jobVisits={jobVisits}
125
            />
126
            <JobAttr title="Visión general" info={parse(jobDescription)} />
127
            <JobAttr
128
              title="Último día de aplicación"
129
              info={lastDateOfApplication}
130
            />
131
            <JobAttr title="Tipo de empleo" info={employmentType} />
132
            <JobAttr title="Ubicación" info={location} />
133
            <JobAttr title="Experiencia" info={experience} />
134
            <JobAttr title="Salario" info={salary} />
135
            <JobAttr title="Categoría" info={jobCategory} />
136
            <JobAttr title="Habilidades" info={jobSkills} />
137
            <JobAttr title="Idiomas" info={jobLanguages} />
138
            <JobAttr title="Grados" info={jobDegrees} />
139
          </Grid>
140
 
7276 stevensc 141
          <Grid item xs={12} md={4} spacing={3}>
7268 stevensc 142
            <button
143
              type="button"
144
              className={`btn ${
145
                isJobApplied ? 'btn-secondary' : 'btn-primary'
146
              }`}
147
              onClick={isJobApplied ? removeApply : handleShowApplyModal}
148
              disabled={loading}
149
            >
150
              {isJobApplied ? 'Quitar aplicación' : 'Aplicar'}
151
            </button>
152
            <ClientInfo
153
              companySize={companySize}
154
              companyAddress={companyAddress}
155
              companyWebsite={companyWebsite}
156
              companyIndustry={companyIndustry}
157
              companyFoundationYear={companyFoundationYear}
158
            />
159
          </Grid>
160
        </Grid>
161
      </Container>
162
      <ApplyModal
163
        jobId={jobId}
164
        show={showApplyModal}
165
        onApplied={handleApply}
166
        userProfiles={userProfiles}
167
        onHide={() => setShowApplyModal(false)}
168
      />
169
    </>
170
  )
171
}
172
 
173
export default JobViewPage