Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useEffect, useState } from 'react';
2
import { useDispatch } from 'react-redux';
3
import { Box, Button, Chip, Grid, Typography } from '@mui/material';
4
import Email from '@mui/icons-material/Email';
5
import Visibility from '@mui/icons-material/Visibility';
6
 
7
import { axios, parse } from '@utils';
8
import { addNotification } from '@store/notification/notification.actions';
9
 
10
import Widget from '@components/UI/Widget';
11
 
12
export default function JobCard({
13
  job: {
14
    company_uuid: companyUuid,
15
    company_image: companyImage,
16
    job_uuid: jobUuid,
17
    job_title: jobTitle,
18
    job_description: jobDescription,
19
    total_applications: totalApplications,
20
    location,
21
    employment_type: employmentType,
22
    last_date_of_application: lastDateOfApplication,
23
    job_category: jobCategory,
24
    timeElapsed,
25
    job_skills: jobSkills,
26
    job_visits: jobVisits,
27
    job_save_operation: jobSaveOperation,
28
    company_name: companyName
29
  }
30
}) {
31
  const [isJobSaved, setIsJobSaved] = useState(false);
32
  const dispatch = useDispatch();
33
 
34
  const handleClickFollow = () => {
35
    setIsJobSaved(!isJobSaved);
36
    likeHandler();
37
  };
38
 
39
  const likeHandler = () => {
40
    axios.post(`/job/${isJobSaved ? 'remove-' : ''}save-job/${jobUuid}`).then((response) => {
41
      const { success } = response.data;
42
 
43
      if (!success) {
44
        setIsJobSaved((currentState) => !currentState);
45
        dispatch(
46
          addNotification({
47
            style: 'danger',
48
            msg: 'Ha ocurrido un error, por favor intente más tarde'
49
          })
50
        );
51
      }
52
    });
53
  };
54
 
55
  useEffect(() => {
56
    setIsJobSaved(jobSaveOperation !== 'job-save');
57
  }, [jobSaveOperation]);
58
 
59
  return (
60
    <Widget>
61
      <Widget.Header
62
        avatar={`/storage/type/company/code/${companyUuid}/${
63
          companyImage ? `filename/${companyImage}` : ''
64
        }`}
65
        title={companyName}
66
        subheader={timeElapsed}
67
        renderAction={() => (
68
          <Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
69
            <Typography variant='overline'>
70
              <Email />
71
              Solicitantes {totalApplications}
72
            </Typography>
73
 
74
            <Typography variant='overline'>
75
              <Visibility /> Visto {jobVisits}
76
            </Typography>
77
          </Box>
78
        )}
79
      />
80
      <Widget.Body>
81
        <Grid container>
82
          <Grid>
83
            <Typography variant='h2'>{jobTitle}</Typography>
84
 
85
            <Typography variant='overline'>Ubicación: {location}</Typography>
86
 
87
            <Typography variant='overline'>Última aplicación: {lastDateOfApplication}</Typography>
88
 
89
            <Typography variant='overline'>Tipo de empleo: {employmentType}</Typography>
90
 
91
            <Typography variant='overline'>Categoría: {jobCategory}</Typography>
92
 
93
            <Typography>Descripción: {parse(jobDescription)}</Typography>
94
          </Grid>
95
 
96
          <Grid>
97
            <Typography variant='overline'>Habilidades:</Typography>
98
            {jobSkills && !!jobSkills.length && (
99
              <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
100
                {jobSkills.map((skill) => (
101
                  <Chip key={skill} label={skill} />
102
                ))}
103
              </Box>
104
            )}
105
          </Grid>
106
        </Grid>
107
      </Widget.Body>
108
 
109
      <Widget.Actions>
110
        <Button variant={isJobSaved ? 'secondary' : 'primary'} onClick={handleClickFollow}>
111
          {isJobSaved ? 'Dejar de seguir' : 'Guardar empleo'}
112
        </Button>
113
      </Widget.Actions>
114
    </Widget>
115
  );
116
}