Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7315 | | 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'
7277 stevensc 9
import styled from 'styled-components'
7268 stevensc 10
 
11
import Description from '../../components/job/Description'
12
import JobAttr from '../../components/job/JobAttr'
13
import ClientInfo from '../../components/job/ClientInfo'
14
import ApplyModal from '../../components/job/ApplyModal'
15
 
7277 stevensc 16
const Col = styled(Grid)`
17
  display: flex;
7278 stevensc 18
  flex-direction: column !important;
7277 stevensc 19
  gap: 0.5rem;
20
`
21
 
7268 stevensc 22
const JobViewPage = () => {
23
  const [job, setJob] = useState({})
24
  const [isJobApplied, setIsJobApplied] = useState(false)
25
  const [showApplyModal, setShowApplyModal] = useState(false)
26
  const [loading, setLoading] = useState(false)
27
  const { uuid } = useParams()
28
  const dispatch = useDispatch()
29
 
30
  const handleShowApplyModal = () => {
31
    setShowApplyModal(!showApplyModal)
32
  }
33
 
34
  const handleApply = () => {
35
    setIsJobApplied(!isJobApplied)
36
  }
37
 
38
  const getJob = () => {
7301 stevensc 39
    getBackendVars(`/job/view/${uuid}`)
7268 stevensc 40
      .then((response) => {
41
        setJob(response)
42
      })
43
      .catch((error) => {
7310 stevensc 44
        dispatch(
45
          addNotification({
46
            style: 'danger',
47
            msg: 'Error interno. Por favor, intente más tarde.',
48
          })
49
        )
7268 stevensc 50
        throw new Error(error)
51
      })
52
  }
53
 
54
  const removeApply = async () => {
55
    setLoading(true)
56
    axios
57
      .post(`/job/remove-apply-job/${job}`)
58
      .then(({ data: response }) => {
59
        const { data, success } = response
60
 
61
        if (!success) {
62
          const errorMessage =
63
            typeof data === 'string'
64
              ? data
65
              : 'Ha ocurrido un error, por favor intente más tarde'
66
 
67
          dispatch(addNotification({ styled: 'danger', msg: errorMessage }))
68
        }
69
 
70
        handleApply()
71
      })
72
      .finally(() => setLoading(false))
73
  }
74
 
75
  useEffect(() => {
76
    getJob()
77
  }, [])
78
 
79
  useEffect(() => {
7315 stevensc 80
    setIsJobApplied(job?.job_apply_operation === 'remove-apply')
7312 stevensc 81
  }, [job])
7268 stevensc 82
 
83
  return (
84
    <>
85
      <Container as="main" className="px-0">
86
        <Tabs>
87
          <Tab label="Avance" value="user" disableRipple />
88
          <Tab label="Información" value="group" disableRipple />
89
        </Tabs>
90
        <Grid container spacing={2}>
7277 stevensc 91
          <Col item xs={12} md={8} spacing={3}>
7268 stevensc 92
            <Description
7312 stevensc 93
              jobId={job?.job_uuid}
94
              companyId={job?.company_uuid}
95
              companyImage={job?.company_image}
96
              jobTitle={job?.job_title}
97
              companyName={job?.company_name}
98
              timeElapsed={job?.timeElapsed}
99
              location={job?.location}
100
              jobSaved={job?.job_save_operation}
101
              lastDateOfApplication={job?.last_date_of_application}
102
              employmentType={job?.employment_type}
103
              jobCategory={job?.job_category}
104
              jobDescription={job?.job_description}
105
              jobSkills={job?.job_skills}
106
              totalApplications={job?.total_applications}
107
              jobVisits={job?.job_visits}
7268 stevensc 108
            />
109
            <JobAttr
7311 stevensc 110
              title="Visión general"
7313 stevensc 111
              info={job?.job_description && parse(job?.job_description)}
7311 stevensc 112
            />
113
            <JobAttr
7268 stevensc 114
              title="Último día de aplicación"
7312 stevensc 115
              info={job?.last_date_of_application}
7268 stevensc 116
            />
7312 stevensc 117
            <JobAttr title="Tipo de empleo" info={job?.employment_type} />
118
            <JobAttr title="Ubicación" info={job?.location} />
119
            <JobAttr title="Experiencia" info={job?.experience} />
120
            <JobAttr title="Salario" info={job?.salary} />
121
            <JobAttr title="Categoría" info={job?.job_category} />
122
            <JobAttr title="Habilidades" info={job?.job_skills} />
123
            <JobAttr title="Idiomas" info={job?.job_languages} />
124
            <JobAttr title="Grados" info={job?.job_degrees} />
7277 stevensc 125
          </Col>
7268 stevensc 126
 
7277 stevensc 127
          <Col item xs={12} md={4}>
7268 stevensc 128
            <button
129
              type="button"
130
              className={`btn ${
131
                isJobApplied ? 'btn-secondary' : 'btn-primary'
132
              }`}
133
              onClick={isJobApplied ? removeApply : handleShowApplyModal}
134
              disabled={loading}
135
            >
136
              {isJobApplied ? 'Quitar aplicación' : 'Aplicar'}
137
            </button>
138
            <ClientInfo
7312 stevensc 139
              companySize={job?.company_size}
140
              companyAddress={job?.company_address}
141
              companyWebsite={job?.company_website}
142
              companyIndustry={job?.company_industry}
143
              companyFoundationYear={job?.company_foundation_year}
7268 stevensc 144
            />
7277 stevensc 145
          </Col>
7268 stevensc 146
        </Grid>
147
      </Container>
148
      <ApplyModal
7312 stevensc 149
        jobId={job?.job_uuid}
7268 stevensc 150
        show={showApplyModal}
151
        onApplied={handleApply}
7312 stevensc 152
        userProfiles={job?.user_profiles}
7268 stevensc 153
        onHide={() => setShowApplyModal(false)}
154
      />
155
    </>
156
  )
157
}
158
 
159
export default JobViewPage