Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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