Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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