Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3736 stevensc 1
import React from 'react';
2
import { Link } from 'react-router-dom';
3
import { Typography } from '@mui/material';
4
 
5
import { useAlert, useApi, useModal } from '@shared/hooks';
6
import { handleActionLink } from '@groups/services';
7
 
8
import Cover from '@components/UI/cover/Cover';
9
import { Card, CardContent, CardActions, Button, Avatar } from '@shared/components';
10
import { GroupImageForm } from '../group-image-form';
11
 
12
export function GroupCard({ uuid, group, updateGroup = () => {}, edit = false }) {
13
  const { showSuccess, showError } = useAlert();
14
  const { showModal, closeModal } = useModal();
15
 
16
  const {
17
    cover,
18
    name,
19
    image,
20
    group_type,
21
    accessibility,
22
    image_size_cover,
23
    image_size_profile,
24
    link_inmail,
25
    link_accept,
26
    link_cancel,
27
    link_leave,
28
    link_request
29
  } = group;
30
 
31
  const editImage = () => {
32
    showModal(
33
      'Cambiar imagen de grupo',
34
      <GroupImageForm
35
        sizes={image_size_profile}
36
        uuid={uuid}
37
        onSubmit={(image) => {
38
          updateGroup({ ...group, image });
39
          closeModal();
40
        }}
41
      />
42
    );
43
  };
44
 
45
  const { execute } = useApi(handleActionLink, {
46
    onSuccess: (message) => {
47
      showSuccess(message);
48
      updateGroup();
49
    },
50
    onError: (error) => {
51
      showError(error.message);
52
    }
53
  });
54
 
55
  return (
56
    <Card>
57
      <Cover
58
        cover={cover}
59
        sizes={image_size_cover}
60
        uploadUrl={`group/my-groups/cover/${uuid}/operation/upload`}
61
        edit={edit}
62
      />
63
 
64
      <CardContent>
65
        <Avatar
66
          src={image}
67
          alt={name}
68
          size={150}
69
          sizes={image_size_profile}
70
          edit={edit}
71
          badgeStyle={{ mt: '-75px' }}
72
          onEdit={editImage}
73
        />
74
        <Typography variant='h2'>{name}</Typography>
75
        <Typography variant='overline'>{group_type}</Typography>
76
      </CardContent>
77
 
78
      {link_inmail ||
79
        link_accept ||
80
        link_cancel ||
81
        link_leave ||
82
        (link_request && (
83
          <CardActions>
84
            {link_inmail && (
85
              <Button color='primary' LinkComponent={Link} to={link_inmail}>
86
                Contactar con el Administrador
87
              </Button>
88
            )}
89
            {link_accept && (
90
              <Button color='primary' onClick={() => execute(link_accept)}>
91
                Aceptar invitacion
92
              </Button>
93
            )}
94
            {link_cancel && (
95
              <Button color='secondary' onClick={() => execute(link_cancel)}>
96
                Cancelar invitacion
97
              </Button>
98
            )}
99
            {link_leave && (
100
              <Button color='secondary' onClick={() => execute(link_leave)}>
101
                Abandonar grupo
102
              </Button>
103
            )}
104
            {link_request && (
105
              <Button color='primary' onClick={() => execute(link_request)}>
106
                {accessibility === 'Auto unirse' ? 'Unirse' : 'Solicitar membresia'}
107
              </Button>
108
            )}
109
          </CardActions>
110
        ))}
111
    </Card>
112
  );
113
}