Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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