4522 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
4645 |
stevensc |
2 |
import React, { useState } from 'react'
|
4522 |
stevensc |
3 |
import { axios } from '../../../../../utils'
|
|
|
4 |
import { addNotification } from '../../../../../redux/notification/notification.actions'
|
|
|
5 |
import Avatar from '../../../../../shared/Avatar/Avatar'
|
|
|
6 |
import { useDispatch } from 'react-redux'
|
4645 |
stevensc |
7 |
import CoverModal from '../../../../../shared/profile/edit/cover-section/CoverModal'
|
4653 |
stevensc |
8 |
import ImageModal from '../../../../../shared/profile/edit/profile-info/profile-img/ImageModal'
|
4645 |
stevensc |
9 |
import { profileTypes } from '../../../../../shared/profile/Profile.types'
|
|
|
10 |
import EditIcon from '@mui/icons-material/EditOutlined'
|
4522 |
stevensc |
11 |
|
4653 |
stevensc |
12 |
const GroupActions = ({ cover, groupId, name, image, groupType, linkInmail, actionLinks, accessibility, imageProfileCover, imageSizeCover }) => {
|
4645 |
stevensc |
13 |
const [modalToShow, setModalToShow] = useState(null)
|
|
|
14 |
const [coverImg, setCoverImg] = useState({ path: `/storage/type/group-cover/code/${groupId}/${cover ? `filename/${cover}` : ""}` })
|
4653 |
stevensc |
15 |
const [profileImg, setProfileImg] = useState({ path: `/storage/type/group/code/${groupId}/${image ? `filename/${image}` : ""}` })
|
4522 |
stevensc |
16 |
const dispatch = useDispatch();
|
4645 |
stevensc |
17 |
const PATH = window.location.pathname
|
4522 |
stevensc |
18 |
|
4645 |
stevensc |
19 |
const closeModal = () => setModalToShow(null)
|
|
|
20 |
|
4522 |
stevensc |
21 |
const handleActionLink = (url) => {
|
|
|
22 |
axios.post(url)
|
|
|
23 |
.then(({ data }) => {
|
|
|
24 |
if (!data.success) {
|
|
|
25 |
return dispatch(addNotification({ style: 'error', msg: data.data }))
|
|
|
26 |
}
|
|
|
27 |
addNotification({ style: 'success', msg: data.data })
|
|
|
28 |
window.location.reload()
|
|
|
29 |
})
|
|
|
30 |
.catch(err => console.log('>>: err > ', err))
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
return (
|
4645 |
stevensc |
34 |
<>
|
|
|
35 |
<div className="group__actions">
|
4652 |
stevensc |
36 |
<div className="group__actions-cover position-relative">
|
4645 |
stevensc |
37 |
<img src={coverImg.path} alt='Profile cover' className='sidebar__cover' />
|
|
|
38 |
{PATH.includes('edit') &&
|
|
|
39 |
<button className='button-icon cover__edit-btn' onClick={() => setModalToShow('cover')}>
|
|
|
40 |
<EditIcon />
|
4522 |
stevensc |
41 |
</button>
|
|
|
42 |
}
|
|
|
43 |
</div>
|
4645 |
stevensc |
44 |
<div className="group__actions-body">
|
4653 |
stevensc |
45 |
<div onClick={() => PATH.includes('edit') && setModalToShow('image')}>
|
|
|
46 |
<Avatar imageUrl={profileImg.path} size='xl' name={name} />
|
|
|
47 |
</div>
|
4645 |
stevensc |
48 |
<h1>{name}</h1>
|
|
|
49 |
<span>{groupType}</span>
|
|
|
50 |
<div className="row" style={{ gap: '.5rem' }}>
|
|
|
51 |
{linkInmail &&
|
|
|
52 |
<a href={linkInmail} className="button btn btn-primary">
|
|
|
53 |
Contactar con el Administrador
|
|
|
54 |
</a>
|
|
|
55 |
}
|
|
|
56 |
{actionLinks?.link_accept &&
|
|
|
57 |
<button
|
|
|
58 |
onClick={() => handleActionLink(actionLinks?.link_accept)}
|
|
|
59 |
className="button btn btn-primary"
|
|
|
60 |
>
|
|
|
61 |
Aceptar invitacion
|
|
|
62 |
</button>
|
|
|
63 |
}
|
|
|
64 |
{actionLinks?.link_cancel &&
|
|
|
65 |
<button
|
|
|
66 |
onClick={() => handleActionLink(actionLinks?.link_cancel)}
|
|
|
67 |
className="button btn btn-secondary"
|
|
|
68 |
>
|
|
|
69 |
Cancelar invitacion
|
|
|
70 |
</button>
|
|
|
71 |
}
|
|
|
72 |
{actionLinks?.link_leave &&
|
|
|
73 |
<button
|
|
|
74 |
onClick={() => handleActionLink(actionLinks?.link_leave)}
|
|
|
75 |
className="button btn btn-secondary"
|
|
|
76 |
>
|
|
|
77 |
Abandonar grupo
|
|
|
78 |
</button>
|
|
|
79 |
}
|
|
|
80 |
{actionLinks?.link_request &&
|
|
|
81 |
<button
|
|
|
82 |
onClick={() => handleActionLink(actionLinks?.link_request)}
|
|
|
83 |
className="button btn btn-primary"
|
|
|
84 |
>
|
|
|
85 |
{accessibility === 'Auto unirse' ? 'Unirse' : 'Solicitar membresia'}
|
|
|
86 |
</button>
|
|
|
87 |
}
|
|
|
88 |
</div>
|
|
|
89 |
</div>
|
4522 |
stevensc |
90 |
</div>
|
4645 |
stevensc |
91 |
<CoverModal
|
|
|
92 |
isModalOpen={modalToShow === 'cover'}
|
|
|
93 |
coverType={profileTypes.GROUP}
|
|
|
94 |
groupId={groupId}
|
|
|
95 |
handleCoverSectionModalOpen={() => closeModal()}
|
|
|
96 |
imageSizeCover={imageProfileCover}
|
|
|
97 |
setCoverImg={(newImage) => setCoverImg(newImage)}
|
|
|
98 |
/>
|
4653 |
stevensc |
99 |
<ImageModal
|
|
|
100 |
handleModalOpen={() => closeModal()}
|
|
|
101 |
isModalOpen={modalToShow === 'image'}
|
|
|
102 |
groupId={groupId}
|
|
|
103 |
imageProfileCover={imageSizeCover}
|
|
|
104 |
profileType={profileTypes.USER}
|
|
|
105 |
setProfileImg={(newImage) => setProfileImg(newImage)}
|
|
|
106 |
/>
|
4645 |
stevensc |
107 |
</>
|
4522 |
stevensc |
108 |
)
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
export default GroupActions
|