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 from 'react';
2
import { useNavigate } from 'react-router-dom';
3
import { Avatar, Button, Typography } from '@mui/material';
4
import { useDispatch } from 'react-redux';
5
import parse from 'html-react-parser';
6
 
7
import { axios } from '@app/utils';
8
import { addNotification } from '@app/redux/notification/notification.actions';
9
 
10
import Widget from '@components/UI/Widget';
11
 
12
export default function CompanyWidget({
13
  company: {
14
    cover,
15
    name,
16
    image,
17
    overview,
18
    link_contact,
19
    link_unfollow,
20
    link_follow,
21
    link_request,
22
    link_accept,
23
    link_cancel,
24
    link_reject,
25
    link_leave
26
  },
27
  refetch = () => {}
28
}) {
29
  const dispatch = useDispatch();
30
  const navigate = useNavigate();
31
 
32
  const handleButtonAction = async (link) => {
33
    const response = await axios.post(link);
34
    const { success, data } = response.data;
35
    if (success) {
36
      dispatch(addNotification({ style: 'success', msg: data }));
37
      refetch();
38
    } else {
39
      dispatch(addNotification({ style: 'danger', msg: 'ha ocurrido un error' }));
40
    }
41
  };
42
 
43
  return (
44
    <Widget>
45
      <Widget.Media height={150} src={cover} />
46
 
47
      <Widget.Body>
48
        <Avatar src={image} alt={name} sx={{ mt: '-40px', width: '80px', height: '80px' }} />
49
        <Typography variant='h2'>{name}</Typography>
50
        <Typography variant='body1'>{parse(overview ?? '')}</Typography>
51
      </Widget.Body>
52
 
53
      <Widget.Actions>
54
        {link_contact && (
55
          <Button color='primary' onClick={() => navigate(link_contact)}>
56
            Mensaje
57
          </Button>
58
        )}
59
        {link_unfollow && (
60
          <Button color='secondary' onClick={() => handleButtonAction(link_unfollow)}>
61
            Dejar de seguir
62
          </Button>
63
        )}
64
        {link_follow && (
65
          <Button color='primary' onClick={() => handleButtonAction(link_follow)}>
66
            Seguir
67
          </Button>
68
        )}
69
        {link_request && link_unfollow && (
70
          <Button color='secondary' onClick={() => handleButtonAction(link_request)}>
71
            ¿Trabaja en esta empresa?
72
          </Button>
73
        )}
74
        {link_accept && (
75
          <Button color='primary' onClick={() => handleButtonAction(link_accept)}>
76
            Aceptar
77
          </Button>
78
        )}
79
        {link_cancel && (
80
          <Button color='info' onClick={() => handleButtonAction(link_cancel)}>
81
            Cancelar
82
          </Button>
83
        )}
84
        {link_reject && (
85
          <Button color='info' onClick={() => handleButtonAction(link_reject)}>
86
            Rechazar
87
          </Button>
88
        )}
89
        {link_leave && (
90
          <Button color='secondary' onClick={() => handleButtonAction(link_leave)}>
91
            Abandonar esta empresa
92
          </Button>
93
        )}
94
      </Widget.Actions>
95
    </Widget>
96
  );
97
}