Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5473 stevensc 1
/* eslint-disable camelcase */
2
/* eslint-disable indent */
3
/* eslint-disable react/prop-types */
4
import React, { useState } from 'react'
5
import parse from 'html-react-parser'
6
import EditIcon from '@mui/icons-material/EditOutlined'
7
import { axios } from '../../../../../utils'
8
import { useDispatch } from 'react-redux'
9
import { addNotification } from '../../../../../redux/notification/notification.actions'
10
import { Modal } from 'react-bootstrap'
11
import ImageModal from '../../../../../shared/profile/edit/profile-info/profile-img/ImageModal'
12
import { profileTypes } from '../../../../../shared/profile/Profile.types'
13
import CoverModal from '../../../../../shared/profile/edit/cover-section/CoverModal'
14
import OverviewModal from '../../../../my-profiles/edit/overview/OverviewModal'
15
import ConfirmModal from '../../../../../shared/confirm-modal/ConfirmModal'
16
 
17
const ProfileCard = ({
18
    fullName = '',
19
    overview = '',
20
    formatted_address: formattedAddress = '',
21
    total_connections: totalConnections,
22
    showContact = false,
23
    userExperiences = [],
24
    linkInmail = '',
25
    CancelConnectionUrl = '',
26
    RequestConnectionUrl = '',
27
    image = '',
28
    cover = '',
29
    userIdEncrypted,
30
    userProfileIdEncrypted,
31
    follower,
32
    following,
33
    facebook,
34
    twitter,
35
    instagram,
36
    imageProfileCover,
37
    imageSizeCover,
38
    view_following,
39
    view_total_connections
40
}) => {
41
    const [isAdded, setIsAdded] = useState(!RequestConnectionUrl)
42
    const [connectionUrl, setConnectionUrl] = useState(RequestConnectionUrl || CancelConnectionUrl)
43
    const [isModalShow, setIsModalShow] = useState(false)
44
    const dispatch = useDispatch()
45
    const PATH = window.location.pathname
46
 
47
    // modals state
48
    const [modalToShow, setModalToShow] = useState(null)
49
    const [settedOverview, setSettedOverview] = useState(overview)
50
    const [profileImg, setProfileImg] = useState({
51
        path: `/storage/type/user-profile/code/${userIdEncrypted}/${image ? `filename/${image}` : ''}`
52
    })
53
    const [coverImg, setCoverImg] = useState({
54
        path: `/storage/type/user-cover/code/${userIdEncrypted}/${cover ? `filename/${cover}` : ''}`
55
    })
56
 
57
    const displayModal = () => setIsModalShow(!isModalShow)
58
 
59
    const getProfileData = async () => {
60
        try {
61
            const { data: response } = await axios.get(window.location.href)
62
 
63
            if (response.link_request) {
64
                return setConnectionUrl(response.link_request)
65
            }
66
 
67
            return setConnectionUrl(response.link_cancel)
68
        } catch (error) {
69
            console.log(error)
70
            return dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
71
        }
72
    }
73
 
74
    const connect = async () => {
75
        try {
76
            const { data: response } = await axios.post(connectionUrl)
77
 
78
            if (!response.success) {
79
                return dispatch(addNotification({ style: 'danger', msg: response.data }))
80
            }
81
 
82
            if (response.success && isModalShow) {
83
                displayModal()
84
            }
85
 
86
            await getProfileData()
87
            dispatch(addNotification({ style: 'success', msg: response.data }))
88
            setIsAdded(!isAdded)
89
        } catch (error) {
90
            dispatch(addNotification({ style: 'danger', msg: `Error: ${error.message}` }))
91
        }
92
    }
93
 
94
    const closeModal = () => setModalToShow(null)
95
 
96
    return (
97
        <>
98
            <section className='profile__user-card'>
99
                <div className='cover__image-container'>
100
                    <img alt='Background Image' src={coverImg.path} />
101
                    {PATH.includes('edit') &&
102
                        <button className='button-icon cover__edit-btn' onClick={() => setModalToShow('cover')}>
103
                            <EditIcon />
104
                        </button>
105
                    }
106
                </div>
107
                <section className='px-4 pb-4'>
108
                    <div className='card__image-options'>
109
                        <img
110
                            alt='Profile Image'
111
                            className={`img ${PATH.includes('edit') && 'cursor-pointer'}`}
112
                            src={profileImg.path}
113
                            onClick={() => PATH.includes('edit') && setModalToShow('image')}
114
                        />
115
                        {PATH.includes('edit') &&
116
                            <button className='button-icon' onClick={() => setModalToShow('overview')}>
117
                                <EditIcon />
118
                            </button>
119
                        }
120
                    </div>
121
                    <div className='card-content'>
122
                        <div className='card-info'>
123
                            <h1>{fullName}</h1>
124
                            {parse(settedOverview.replaceAll('h1', 'p'))}
125
                            <div className='d-inline-flex align-items-center mt-2' style={{ gap: '1rem' }}>
126
                                <span>{formattedAddress}</span>
127
                                <a
128
                                    href=''
129
                                    onClick={(e) => {
130
                                        e.preventDefault()
131
                                        setModalToShow('info')
132
                                    }}>
133
                                    {LABELS.PERSONAL_INFO}
134
                                </a>
135
                            </div>
136
                            <div className='d-inline-flex align-items-center mt-2' style={{ gap: '1rem' }}>
137
                                {(Boolean(totalConnections) && view_total_connections) &&
138
                                    <a href='/connection/my-connections' target='_blank'>
139
                                        {`${totalConnections} ${LABELS.CONNECTIONS}`}
140
                                    </a>
141
                                }
142
                                {(Boolean(follower) && view_following) &&
143
                                    <a href='' className='cursor-auto' onClick={(e) => e.preventDefault()}>
144
                                        {`${follower} ${LABELS.FOLLOWERS}`}
145
                                    </a>
146
                                }
147
                                {(Boolean(following) && view_following) &&
148
                                    <a href='/company/following-companies' target='_blank'>
149
                                        {`${following} ${LABELS.FOLLOWING}`}
150
                                    </a>
151
                                }
152
                            </div>
153
                            <div className='button-actions mt-2'>
154
                                {(connectionUrl && isAdded) &&
155
                                    <button className='btn button btn-primary' onClick={() => displayModal()}>
156
                                        {LABELS.CANCEL}
157
                                    </button>
158
                                }
159
                                {(connectionUrl && !isAdded) &&
160
                                    <button className='btn button btn-primary' onClick={() => connect()}>
161
                                        {LABELS.CONNECT}
162
                                    </button>
163
                                }
164
                                {showContact &&
165
                                    <a href={linkInmail} className='btn button btn-secondary'>
166
                                        {LABELS.MESSAGE}
167
                                    </a>
168
                                }
169
                            </div>
170
                        </div>
171
                        <div className='card-experiences'>
172
                            <ul>
173
                                {userExperiences.map(({ company, title, industry, size }, index) =>
174
                                    <li key={index}>
175
                                        <span>{`${company} - ${title}`}</span>
176
                                        <p>{`${industry} / ${size}`}</p>
177
                                    </li>
178
                                )}
179
                            </ul>
180
                        </div>
181
                    </div>
182
                </section>
183
            </section>
184
            <OverviewModal
185
                isOpen={modalToShow === 'overview'}
186
                overview={settedOverview}
187
                userIdEncrypted={userProfileIdEncrypted}
188
                closeModal={() => closeModal()}
189
                setOverview={(newOverview) => setSettedOverview(newOverview)}
190
            />
191
            <CoverModal
192
                isModalOpen={modalToShow === 'cover'}
193
                coverType={profileTypes.USER}
194
                entityId={userIdEncrypted}
195
                profileId={userProfileIdEncrypted}
196
                handleCoverSectionModalOpen={() => closeModal()}
197
                imageSizeCover={imageSizeCover}
198
                setCoverImg={(newImage) => setCoverImg(newImage)}
199
            />
200
            <ImageModal
201
                handleModalOpen={() => closeModal()}
202
                isModalOpen={modalToShow === 'image'}
203
                profileId={userProfileIdEncrypted}
204
                imageProfileCover={imageProfileCover}
205
                profileType={profileTypes.USER}
206
                setProfileImg={(newImage) => setProfileImg(newImage)}
207
            />
208
            <ProfileCard.Modal
209
                show={modalToShow === 'info'}
210
                closeModal={() => closeModal()}
211
                fullName={fullName}
212
                facebook={facebook}
213
                twitter={twitter}
214
                instagram={instagram}
215
                following={following}
216
                formatted_address={formattedAddress}
217
                overview={overview}
218
                total_connections={totalConnections}
219
                follower={follower}
220
            />
221
            <ConfirmModal
222
                show={isModalShow}
223
                onClose={() => setIsModalShow(false)}
224
                onAccept={() => connect()}
225
            />
226
        </>
227
    )
228
}
229
 
230
const InfoModal = ({
231
    show,
232
    closeModal,
233
    facebook,
234
    following,
235
    formatted_address,
236
    fullName,
237
    instagram,
238
    overview,
239
    total_connections,
240
    twitter,
241
    follower
242
}) => {
243
    return (
244
        <Modal
245
            show={show}
246
            onHide={closeModal}
247
        >
248
            <Modal.Header closeButton>
249
                <h2>{LABELS.ABOUT_GROUP}</h2>
250
            </Modal.Header>
251
            <Modal.Body>
252
                <div className="description__label">
253
                    <label htmlFor="name">{LABELS.FIRST_NAME}</label>
254
                    <p>{fullName}</p>
255
                </div>
256
                {overview &&
257
                    <div className="description__label">
258
                        <label htmlFor="name">{LABELS.DESCRIPTION}</label>
259
                        {parse(overview)}
260
                    </div>
261
                }
262
                {formatted_address &&
263
                    <div className="description__label">
264
                        <label htmlFor="name">{LABELS.LOCATION}</label>
265
                        <p>{formatted_address}</p>
266
                    </div>
267
                }
268
                {total_connections &&
269
                    <div className="description__label">
270
                        <label htmlFor="name">{LABELS.CONNECTIONS}</label>
271
                        <p>{total_connections}</p>
272
                    </div>
273
                }
274
                {follower &&
275
                    <div className="description__label">
276
                        <label htmlFor="name">{LABELS.FOLLOWERS}</label>
277
                        <p>{follower}</p>
278
                    </div>
279
                }
280
                {following &&
281
                    <div className="description__label">
282
                        <label htmlFor="name">{LABELS.FOLLOWING}</label>
283
                        <p>{following}</p>
284
                    </div>
285
                }
286
                <div className="description__label">
287
                    <label htmlFor="name">{LABELS.SOCIAL_NETWORKS}</label>
288
                    {facebook &&
289
                        <a href={facebook} target="_blank" rel="noreferrer">
290
                            <p className='mb-1'>{facebook}</p>
291
                        </a>}
292
                    {instagram &&
293
                        <a href={instagram} target="_blank" rel="noreferrer">
294
                            <p className='mb-1'>{instagram}</p>
295
                        </a>}
296
                    {twitter &&
297
                        <a href={twitter} target="_blank" rel="noreferrer">
298
                            <p className='mb-1'>{twitter}</p>
299
                        </a>}
300
                </div>
301
            </Modal.Body>
302
        </Modal>
303
    )
304
}
305
 
306
ProfileCard.Modal = InfoModal
307
 
308
export default ProfileCard