Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useState } from 'react';
2
import { useParams } from 'react-router-dom';
3
import { useDispatch } from 'react-redux';
4
import { Button, Grid } from '@mui/material';
5
 
6
import { axios, parse } from '@utils';
7
import { useFetch } from '@hooks';
8
import { addNotification } from '@store/notification/notification.actions';
9
 
10
import Spinner from '@components/UI/Spinner';
11
import JobCard from '@components/job/job-card';
12
import JobAttr from '@components/job/job-attr';
13
import CompanyInfo from '@components/job/company-info';
14
import ApplyModal from '@components/job/apply-modal';
15
 
16
const JobViewPage = () => {
17
  const [showApplyModal, setShowApplyModal] = useState(false);
18
  const [loading, setLoading] = useState(false);
19
  const { uuid } = useParams();
20
  const dispatch = useDispatch();
21
 
22
  const { data: job, isLoading, mutate } = useFetch(`/job/view/${uuid}`);
23
  const isJobApplied = job?.job_apply_operation === 'remove-apply';
24
 
25
  const toggleApplyModal = () => setShowApplyModal(!showApplyModal);
26
 
27
  const toggleApplication = () => {
28
    mutate({
29
      ...job,
30
      job_apply_operation: isJobApplied ? 'apply' : 'remove-apply'
31
    });
32
  };
33
 
34
  const removeApply = async () => {
35
    setLoading(true);
36
    try {
37
      const response = await axios.post(`/job/remove-apply-job/${job.job_uuid}`);
38
      const { data, success } = response.data;
39
      if (!success) throw new Error('Error al eliminar la aplicación');
40
      dispatch(addNotification({ style: 'success', msg: data }));
41
      toggleApplication();
42
    } catch (error) {
43
      dispatch(addNotification({ style: 'danger', msg: error.message }));
44
    } finally {
45
      setLoading(false);
46
    }
47
  };
48
 
49
  const apply = async (jobApply) => {
50
    setLoading(true);
51
 
52
    try {
53
      const url = `/job/apply-job/${job.job_uuid}`;
54
      const formData = new FormData();
55
      Object.entries(jobApply).map(([key, value]) => formData.append(key, value));
56
 
57
      const response = await axios.post(url, formData);
58
      const { data, success } = response.data;
59
 
60
      if (!success) throw new Error('Error al aplicar al trabajo');
61
 
62
      dispatch(addNotification({ style: 'success', msg: data }));
63
      toggleApplication();
64
      toggleApplyModal();
65
    } catch (error) {
66
      dispatch(addNotification({ styled: 'danger', msg: error.message }));
67
    } finally {
68
      setLoading(false);
69
    }
70
  };
71
 
72
  if (isLoading) {
73
    return <Spinner />;
74
  }
75
 
76
  return (
77
    <>
78
      <Grid container spacing={1}>
79
        <Grid size={{ xs: 12, md: 8 }} sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
80
          <JobCard job={job} />
81
 
82
          <JobAttr title='Visión general' info={parse(job?.job_description)} />
83
          <JobAttr title='Último día de aplicación' info={job?.last_date_of_application} />
84
          <JobAttr title='Tipo de empleo' info={job?.employment_type} />
85
          <JobAttr title='Ubicación' info={job?.location} />
86
          <JobAttr title='Experiencia' info={job?.experience} />
87
          <JobAttr title='Salario' info={job?.salary} />
88
          <JobAttr title='Categoría' info={job?.job_category} />
89
          <JobAttr title='Habilidades' info={job?.job_skills} />
90
          <JobAttr title='Idiomas' info={job?.job_languages} />
91
          <JobAttr title='Grados' info={job?.job_degrees} />
92
        </Grid>
93
 
94
        <Grid size={{ xs: 12, md: 4 }} sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
95
          <Button
96
            variant={isJobApplied ? 'secondary' : 'primary'}
97
            onClick={isJobApplied ? removeApply : toggleApplyModal}
98
            disabled={loading}
99
          >
100
            {isJobApplied ? 'Quitar aplicación' : 'Aplicar'}
101
          </Button>
102
 
103
          <CompanyInfo company={job} />
104
        </Grid>
105
      </Grid>
106
 
107
      <ApplyModal
108
        show={showApplyModal}
109
        profiles={job?.user_profiles}
110
        onConfirm={apply}
111
        onClose={toggleApplyModal}
112
      />
113
    </>
114
  );
115
};
116
 
117
export default JobViewPage;