Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3092 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3092 Rev 3694
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useEffect, useState } from 'react';
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from 'react-redux';
3
import { Box, Button, Chip, Grid, Typography } from '@mui/material'
3
import { Box, Button, Chip, Grid, Typography } from '@mui/material';
-
 
4
import Email from '@mui/icons-material/Email';
4
import { Email, Visibility } from '@mui/icons-material'
5
import Visibility from '@mui/icons-material/Visibility';
Línea 5... Línea 6...
5
 
6
 
6
import { axios, parse } from '@utils'
7
import { axios, parse } from '@utils';
Línea 7... Línea 8...
7
import { addNotification } from '@store/notification/notification.actions'
8
import { addNotification } from '@store/notification/notification.actions';
Línea 8... Línea 9...
8
 
9
 
9
import Widget from '@components/UI/Widget'
10
import Widget from '@components/UI/Widget';
10
 
11
 
11
export default function JobCard({
12
export default function JobCard({
Línea 25... Línea 26...
25
    job_visits: jobVisits,
26
    job_visits: jobVisits,
26
    job_save_operation: jobSaveOperation,
27
    job_save_operation: jobSaveOperation,
27
    company_name: companyName
28
    company_name: companyName
28
  }
29
  }
29
}) {
30
}) {
30
  const [isJobSaved, setIsJobSaved] = useState(false)
31
  const [isJobSaved, setIsJobSaved] = useState(false);
31
  const dispatch = useDispatch()
32
  const dispatch = useDispatch();
Línea 32... Línea 33...
32
 
33
 
33
  const handleClickFollow = () => {
34
  const handleClickFollow = () => {
34
    setIsJobSaved(!isJobSaved)
35
    setIsJobSaved(!isJobSaved);
35
    likeHandler()
36
    likeHandler();
Línea 36... Línea 37...
36
  }
37
  };
37
 
-
 
38
  const likeHandler = () => {
38
 
39
    axios
-
 
40
      .post(`/job/${isJobSaved ? 'remove-' : ''}save-job/${jobUuid}`)
39
  const likeHandler = () => {
41
      .then((response) => {
40
    axios.post(`/job/${isJobSaved ? 'remove-' : ''}save-job/${jobUuid}`).then((response) => {
42
        const { success } = response.data
41
      const { success } = response.data;
43
 
42
 
44
        if (!success) {
43
      if (!success) {
45
          setIsJobSaved((currentState) => !currentState)
44
        setIsJobSaved((currentState) => !currentState);
46
          dispatch(
45
        dispatch(
47
            addNotification({
46
          addNotification({
48
              style: 'danger',
47
            style: 'danger',
49
              msg: 'Ha ocurrido un error, por favor intente más tarde'
48
            msg: 'Ha ocurrido un error, por favor intente más tarde'
50
            })
49
          })
51
          )
50
        );
52
        }
51
      }
Línea 53... Línea 52...
53
      })
52
    });
54
  }
53
  };
55
 
54
 
Línea 56... Línea 55...
56
  useEffect(() => {
55
  useEffect(() => {
57
    setIsJobSaved(jobSaveOperation !== 'job-save')
56
    setIsJobSaved(jobSaveOperation !== 'job-save');
58
  }, [jobSaveOperation])
57
  }, [jobSaveOperation]);
59
 
58
 
Línea 83... Línea 82...
83
          <Grid item xs>
82
          <Grid item xs>
84
            <Typography variant='h2'>{jobTitle}</Typography>
83
            <Typography variant='h2'>{jobTitle}</Typography>
Línea 85... Línea 84...
85
 
84
 
Línea 86... Línea -...
86
            <Typography variant='overline'>Ubicación: {location}</Typography>
-
 
87
 
85
            <Typography variant='overline'>Ubicación: {location}</Typography>
88
            <Typography variant='overline'>
-
 
Línea 89... Línea -...
89
              Última aplicación: {lastDateOfApplication}
-
 
90
            </Typography>
86
 
91
 
-
 
Línea 92... Línea 87...
92
            <Typography variant='overline'>
87
            <Typography variant='overline'>Última aplicación: {lastDateOfApplication}</Typography>
Línea 93... Línea 88...
93
              Tipo de empleo: {employmentType}
88
 
94
            </Typography>
89
            <Typography variant='overline'>Tipo de empleo: {employmentType}</Typography>
Línea 110... Línea 105...
110
          </Grid>
105
          </Grid>
111
        </Grid>
106
        </Grid>
112
      </Widget.Body>
107
      </Widget.Body>
Línea 113... Línea 108...
113
 
108
 
114
      <Widget.Actions>
-
 
115
        <Button
109
      <Widget.Actions>
116
          variant={isJobSaved ? 'secondary' : 'primary'}
-
 
117
          onClick={handleClickFollow}
-
 
118
        >
110
        <Button variant={isJobSaved ? 'secondary' : 'primary'} onClick={handleClickFollow}>
119
          {isJobSaved ? 'Dejar de seguir' : 'Guardar empleo'}
111
          {isJobSaved ? 'Dejar de seguir' : 'Guardar empleo'}
120
        </Button>
112
        </Button>
121
      </Widget.Actions>
113
      </Widget.Actions>
122
    </Widget>
114
    </Widget>
123
  )
115
  );