Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6830 | Rev 6865 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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