Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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