Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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