AutorÃa | Ultima modificación | Ver Log |
import React, { useEffect, useState } from 'react'
import { axios } from '../../../../utils'
import { useDispatch } from 'react-redux'
import { addNotification } from '../../../../redux/notification/notification.actions'
const GroupInfo = ({
groupId,
image,
name,
totalMembers,
linkInmail,
accessibility,
}) => {
const [actionLinks, setActionLinks] = useState({})
const dispatch = useDispatch()
const load = () => {
axios
.get('')
.then(({ data }) => {
if (!data.success) {
dispatch(addNotification({ style: 'error', msg: data.data }))
return
}
setActionLinks(data.data)
})
.catch((err) => console.log('>>: err > ', err))
}
const handleActionLink = (url) => {
axios
.post(url)
.then(({ data }) => {
if (!data.success) {
dispatch(addNotification({ style: 'error', msg: data.data }))
return
}
dispatch(addNotification({ style: 'success', msg: data.data }))
window.location.reload()
})
.catch((err) => console.log('>>: err > ', err))
}
useEffect(() => load(), [])
return (
<div className="group-info">
<img
src={`/storage/type/group/code/${groupId}/${
image ? `filename/${image}` : ''
}`}
alt="profile-image"
/>
<h2>{name}</h2>
<span>
<b>{totalMembers}</b>
<br />
Miembros
</span>
<div className="row ">
{linkInmail && (
<a href={linkInmail} className="btn btn-primary">
Contactar con el Administrador
</a>
)}
{actionLinks.link_accept && (
<button
onClick={() => handleActionLink(actionLinks.link_accept)}
className="btn btn-primary"
>
Aceptar invitacion
</button>
)}
{actionLinks.link_cancel && (
<button
onClick={() => handleActionLink(actionLinks.link_cancel)}
className="btn btn-primary"
>
Cancelar invitacion
</button>
)}
{actionLinks.link_leave && (
<button
onClick={() => handleActionLink(actionLinks.link_leave)}
className="btn btn-primary"
>
Abandonar grupo
</button>
)}
{actionLinks.link_request && (
<button
onClick={() => handleActionLink(actionLinks.link_request)}
className="btn btn-primary"
>
{accessibility === 'Auto unirse' ? 'Unirse' : 'Solicitar membresia'}
</button>
)}
</div>
</div>
)
}
export default GroupInfo