Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2806 | Rev 3083 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useState } from 'react'
import { useParams } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import { Grid, Tab, Tabs } from '@mui/material'

import { useFetch } from '@hooks'
import ApplyModal from '@components/job/ApplyModal'
import JobAttr from '@components/job/JobAttr'
import { axios, parse } from '@utils'
import Description from '@components/job/Description'
import { addNotification } from '@store/notification/notification.actions'
import ClientInfo from '@components/job/ClientInfo'
import Spinner from '@components/UI/Spinner'

const JobViewPage = () => {
  const [showApplyModal, setShowApplyModal] = useState(false)
  const [loading, setLoading] = useState(false)
  const { uuid } = useParams()
  const dispatch = useDispatch()

  const { data: job, isLoading } = useFetch(`/job/view/${uuid}`)

  const isJobApplied = job?.job_apply_operation === 'remove-apply'

  const handleShowApplyModal = () => {
    setShowApplyModal(!showApplyModal)
  }

  const handleApply = () => {
    // setIsJobApplied(!isJobApplied)
  }

  const removeApply = async () => {
    setLoading(true)
    try {
      const response = await axios.post(`/job/remove-apply-job/${job}`)
      const { data, success } = response.data
      if (!success) throw new Error('Error al eliminar la aplicación')
      dispatch(addNotification({ styled: 'success', msg: data }))
      handleApply()
    } catch (error) {
      dispatch(addNotification({ styled: 'danger', msg: error.message }))
    } finally {
      setLoading(false)
    }
  }

  if (isLoading) {
    return <Spinner />
  }

  return (
    <>
      <Tabs>
        <Tab label='Avance' value='user' disableRipple />
        <Tab label='Información' value='group' disableRipple />
      </Tabs>

      <Grid container spacing={2}>
        <Grid item xs md={8} spacing={3}>
          <Description
            jobId={job?.job_uuid}
            companyId={job?.company_uuid}
            companyImage={job?.company_image}
            jobTitle={job?.job_title}
            companyName={job?.company_name}
            timeElapsed={job?.timeElapsed}
            location={job?.location}
            jobSaved={job?.job_save_operation}
            lastDateOfApplication={job?.last_date_of_application}
            employmentType={job?.employment_type}
            jobCategory={job?.job_category}
            jobDescription={job?.job_description}
            jobSkills={job?.job_skills}
            totalApplications={job?.total_applications}
            jobVisits={job?.job_visits}
          />
          <JobAttr title='Visión general' info={parse(job?.job_description)} />
          <JobAttr
            title='Último día de aplicación'
            info={job?.last_date_of_application}
          />
          <JobAttr title='Tipo de empleo' info={job?.employment_type} />
          <JobAttr title='Ubicación' info={job?.location} />
          <JobAttr title='Experiencia' info={job?.experience} />
          <JobAttr title='Salario' info={job?.salary} />
          <JobAttr title='Categoría' info={job?.job_category} />
          <JobAttr title='Habilidades' info={job?.job_skills} />
          <JobAttr title='Idiomas' info={job?.job_languages} />
          <JobAttr title='Grados' info={job?.job_degrees} />
        </Grid>

        <Grid item xs md={4}>
          <button
            type='button'
            className={`btn ${isJobApplied ? 'btn-secondary' : 'btn-primary'}`}
            onClick={isJobApplied ? removeApply : handleShowApplyModal}
            disabled={loading}
          >
            {job?.job_apply_operation === 'remove-apply'
              ? 'Quitar aplicación'
              : 'Aplicar'}
          </button>
          <ClientInfo
            companySize={job?.company_size}
            companyAddress={job?.company_address}
            companyWebsite={job?.company_website}
            companyIndustry={job?.company_industry}
            companyFoundationYear={job?.company_foundation_year}
          />
        </Grid>
      </Grid>

      <ApplyModal
        jobId={job?.job_uuid}
        show={showApplyModal}
        onApplied={handleApply}
        userProfiles={job?.user_profiles}
        onHide={() => setShowApplyModal(false)}
      />
    </>
  )
}

export default JobViewPage