Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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