Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3688 | Ir a la última revisión | | 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 { Link, useParams } from 'react-router-dom';
3
import { useDispatch } from 'react-redux';
4
import { Button, Typography } from '@mui/material';
5
 
6
import { axios } from '@utils';
7
import { addNotification } from '@store/notification/notification.actions';
8
 
9
import Widget from '@components/UI/Widget';
10
import Cover from '@components/UI/cover/Cover';
11
import Avatar from '@components/common/avatar';
12
import Row from '@components/common/Row';
13
 
14
const GroupActions = ({
15
  cover,
16
  name,
17
  image,
18
  group_type,
19
  accessibility,
20
  image_size_cover,
21
  image_size_profile,
22
  link_inmail,
23
  link_accept,
24
  link_cancel,
25
  link_leave,
26
  link_request,
27
  refetch,
28
  edit = false
29
}) => {
30
  const { uuid } = useParams();
31
  const dispatch = useDispatch();
32
 
33
  const handleActionLink = async (url) => {
34
    try {
35
      const response = await axios.post(url);
36
      const { data, success } = response.data;
37
 
38
      if (!success) {
39
        const errMsg =
40
          typeof data === 'string' ? data : 'Lo sentimos, ocurrio un error. Intentalo mas tarde.';
41
        throw new Error(errMsg);
42
      }
43
 
44
      refetch();
45
      dispatch(addNotification({ style: 'success', msg: data }));
46
    } catch (error) {
47
      dispatch(addNotification({ style: 'danger', msg: error.message }));
48
    }
49
  };
50
 
51
  return (
52
    <>
53
      <Widget>
54
        <Cover
55
          cover={cover}
56
          sizes={image_size_cover}
57
          uploadUrl={`group/my-groups/cover/${uuid}/operation/upload`}
58
          edit={edit}
59
        />
60
        <Widget.Body>
61
          <Avatar
62
            src={image}
63
            alt={name}
64
            badgeStyles={{ mt: '-75px' }}
65
            styles={{ width: 150, height: 150 }}
66
            edit={edit}
67
            size={image_size_profile}
68
            uploadUrl={`group/my-groups/image/${uuid}/operation/upload`}
69
          />
70
          <Typography variant='h2'>{name}</Typography>
71
          <Typography variant='overline'>{group_type}</Typography>
72
 
73
          <Row>
74
            {link_inmail && (
75
              <Button color='primary' LinkComponent={Link} to={link_inmail}>
76
                Contactar con el Administrador
77
              </Button>
78
            )}
79
            {link_accept && (
80
              <Button color='primary' onClick={() => handleActionLink(link_accept)}>
81
                Aceptar invitacion
82
              </Button>
83
            )}
84
            {link_cancel && (
85
              <Button color='secondary' onClick={() => handleActionLink(link_cancel)}>
86
                Cancelar invitacion
87
              </Button>
88
            )}
89
            {link_leave && (
90
              <Button color='secondary' onClick={() => handleActionLink(link_leave)}>
91
                Abandonar grupo
92
              </Button>
93
            )}
94
            {link_request && (
95
              <Button color='primary' onClick={() => handleActionLink(link_request)}>
96
                {accessibility === 'Auto unirse' ? 'Unirse' : 'Solicitar membresia'}
97
              </Button>
98
            )}
99
          </Row>
100
        </Widget.Body>
101
      </Widget>
102
    </>
103
  );
104
};
105
 
106
export default GroupActions;