Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6863 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6830 stevensc 1
import React, { useState } from 'react'
2
import { axios } from '../../utils'
3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import EditIcon from '@mui/icons-material/EditOutlined'
6
 
7
import Avatar from '../UI/AvatarImage'
8
import CoverModal from '../cover/CoverModal'
9
import ImageModal from '../modals/ImageModal'
10
 
11
const GroupActions = ({
12
  cover,
13
  groupId,
14
  name,
15
  image,
16
  groupType,
17
  linkInmail,
18
  actionLinks,
19
  accessibility,
20
  imageProfileCover,
21
  imageSizeCover,
22
}) => {
23
  const [modalToShow, setModalToShow] = useState(null)
24
  const [coverImg, setCoverImg] = useState({
25
    path: `/storage/type/group-cover/code/${groupId}/${
26
      cover ? `filename/${cover}` : ''
27
    }`,
28
  })
29
  const [profileImg, setProfileImg] = useState({
30
    path: `/storage/type/group/code/${groupId}/${
31
      image ? `filename/${image}` : ''
32
    }`,
33
  })
34
  const dispatch = useDispatch()
35
  const PATH = window.location.pathname
36
 
37
  const closeModal = () => setModalToShow(null)
38
 
39
  const handleActionLink = (url) => {
40
    axios
41
      .post(url)
42
      .then(({ data }) => {
43
        if (!data.success) {
44
          return dispatch(addNotification({ style: 'error', msg: data.data }))
45
        }
46
        addNotification({ style: 'success', msg: data.data })
47
        window.location.reload()
48
      })
49
      .catch((err) => console.log('>>: err > ', err))
50
  }
51
 
52
  return (
53
    <>
54
      <div className="group__actions">
55
        <div
56
          className="group__actions-cover position-relative"
57
          style={{ height: '300px' }}
58
        >
59
          <img
60
            src={coverImg.path}
61
            alt="Profile cover"
62
            className="sidebar__cover"
63
          />
64
          {PATH.includes('edit') && (
65
            <button
66
              className="button-icon cover__edit-btn"
67
              onClick={() => setModalToShow('cover')}
68
            >
69
              <EditIcon />
70
            </button>
71
          )}
72
        </div>
73
        <div className="group__actions-body">
74
          <div className="card__image-options">
75
            {PATH.includes('edit') ? (
76
              <img
77
                alt="Profile Image"
78
                className={`img ${PATH.includes('edit') && 'cursor-pointer'}`}
79
                src={profileImg.path}
80
                onClick={() => PATH.includes('edit') && setModalToShow('image')}
81
                style={{ zIndex: 10 }}
82
              />
83
            ) : (
84
              <Avatar imageUrl={profileImg.path} size="xl" name={name} />
85
            )}
86
          </div>
87
          <h1>{name}</h1>
88
          <span>{groupType}</span>
89
          <div className="row" style={{ gap: '.5rem' }}>
90
            {linkInmail && (
91
              <a href={linkInmail} className="button btn btn-primary">
92
                Contactar con el Administrador
93
              </a>
94
            )}
95
            {actionLinks?.link_accept && (
96
              <button
97
                onClick={() => handleActionLink(actionLinks?.link_accept)}
98
                className="button btn btn-primary"
99
              >
100
                Aceptar invitacion
101
              </button>
102
            )}
103
            {actionLinks?.link_cancel && (
104
              <button
105
                onClick={() => handleActionLink(actionLinks?.link_cancel)}
106
                className="button btn btn-secondary"
107
              >
108
                Cancelar invitacion
109
              </button>
110
            )}
111
            {actionLinks?.link_leave && (
112
              <button
113
                onClick={() => handleActionLink(actionLinks?.link_leave)}
114
                className="button btn btn-secondary"
115
              >
116
                Abandonar grupo
117
              </button>
118
            )}
119
            {actionLinks?.link_request && (
120
              <button
121
                onClick={() => handleActionLink(actionLinks?.link_request)}
122
                className="button btn btn-primary"
123
              >
124
                {accessibility === 'Auto unirse'
125
                  ? 'Unirse'
126
                  : 'Solicitar membresia'}
127
              </button>
128
            )}
129
          </div>
130
        </div>
131
      </div>
132
      <CoverModal
133
        isOpen={modalToShow === 'cover'}
134
        sizes={imageSizeCover}
135
        onClose={() => closeModal()}
136
        onComplete={(newImage) => setCoverImg(newImage)}
137
      />
138
      <ImageModal
139
        show={modalToShow === 'image'}
140
        onClose={() => closeModal()}
141
        sizes={imageProfileCover}
142
        id={groupId}
143
        onComplete={(newImage) => setProfileImg(newImage)}
144
      />
145
    </>
146
  )
147
}
148
 
149
export default GroupActions