Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5070 stevensc 1
/* eslint-disable camelcase */
3517 stevensc 2
/* eslint-disable react/prop-types */
5070 stevensc 3
import React, { useState } from 'react'
4
import { addNotification } from '../redux/notification/notification.actions'
5
import ConfirmationBox from '../shared/confirmation-box/ConfirmationBox'
6
import Spinner from '../shared/loading-spinner/Spinner'
7
import { axios } from '../utils'
1587 steven 8
import styled from 'styled-components'
5996 stevensc 9
import { useSelector } from 'react-redux'
1587 steven 10
 
11
const StyledSpinnerContainer = styled.div`
12
  position: absolute;
13
  left: 0;
14
  top: 0;
15
  width: 100%;
16
  height: 100%;
17
  background: rgba(255, 255, 255, 0.4);
18
  display: flex;
19
  justify-content: center;
20
  align-items: center;
21
  z-index: 300;
5070 stevensc 22
`
23
const Profile = ({
24
  image,
25
  name,
26
  email,
27
  network,
28
  status,
29
  link_view,
30
  link_edit,
31
  link_delete,
32
  link_cancel,
33
  link_block,
34
  link_reject,
35
  link_accept,
36
  link_inmail,
37
  link_request,
38
  link_unblock,
39
  link_unfollow,
40
  link_approve,
41
  link_leave,
42
  link_admin,
43
  link_impersonate,
44
  fetchCallback,
45
  isTopData = false,
46
  btnAcceptTitle = 'Ver perfil',
47
  btnCancelTitle = 'Borrar perfil',
5996 stevensc 48
  btnEditTitle = 'Editar perfil',
5070 stevensc 49
}) => {
50
  const [showConfirmationBox, setShowConfirmationBox] = useState(false)
5996 stevensc 51
  const [showCancelConfirmationBox, setShowCancelConfirmationBox] =
52
    useState(false)
53
  const [showBlockConfirmationBox, setShowBlockConfirmationBox] =
54
    useState(false)
55
  const [showRejectConfirmationBox, setShowRejectConfirmationBox] =
56
    useState(false)
57
  const [showApproveConfirmationBox, setShowApproveConfirmationBox] =
58
    useState(false)
59
  const [showRequestConfirmationBox, setShowRequestConfirmationBox] =
60
    useState(false)
61
  const [showUnblockConfirmationBox, setShowUnblockConfirmationBox] =
62
    useState(false)
63
  const [showLeaveConfirmationBox, setShowLeaveConfirmationBox] =
64
    useState(false)
5070 stevensc 65
  const [loading, setLoading] = useState(false)
5996 stevensc 66
  const labels = useSelector((state) => state.labels)
1587 steven 67
 
5070 stevensc 68
  const handleShowConfirmationBox = (show = !showConfirmationBox) => {
69
    setShowConfirmationBox(show)
3639 efrain 70
  }
3816 stevensc 71
  const handleCancelConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 72
    setShowCancelConfirmationBox(show)
73
  }
3816 stevensc 74
  const handleBlockConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 75
    setShowBlockConfirmationBox(show)
76
  }
3816 stevensc 77
  const handleRejectConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 78
    setShowRejectConfirmationBox(show)
79
  }
3816 stevensc 80
  const handleApproveConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 81
    setShowApproveConfirmationBox(show)
82
  }
3816 stevensc 83
  const handleRequestConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 84
    setShowRequestConfirmationBox(show)
85
  }
3816 stevensc 86
  const handleUnblockConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 87
    setShowUnblockConfirmationBox(show)
88
  }
3816 stevensc 89
  const handleLeaveConfirmationBox = (show = !showConfirmationBox) => {
5070 stevensc 90
    setShowLeaveConfirmationBox(show)
91
  }
1587 steven 92
 
5070 stevensc 93
  const getImpersonateUrl = async (url = '') => {
94
    try {
95
      const { data } = await axios.get(url)
96
      if (data.success) window.location.href = data.data
97
    } catch (error) {
98
      console.log('>>: error > ', error)
99
    }
100
  }
101
 
1587 steven 102
  const handleCancelApply = (url = link_delete) => {
5070 stevensc 103
    setLoading(true)
5996 stevensc 104
    axios
105
      .post(url)
3522 stevensc 106
      .then(({ data }) => {
107
        if (!data.success) {
1587 steven 108
          const errorMsg =
5070 stevensc 109
            typeof data.data === 'string'
3522 stevensc 110
              ? data.data
5070 stevensc 111
              : 'Ha ocurrido un error, Por favor intente más tarde'
1587 steven 112
          addNotification({
5070 stevensc 113
            style: 'danger',
5996 stevensc 114
            msg: errorMsg,
5070 stevensc 115
          })
1587 steven 116
        }
5070 stevensc 117
        const msg = data.data
3522 stevensc 118
        addNotification({
5070 stevensc 119
          style: 'success',
5996 stevensc 120
          msg,
5070 stevensc 121
        })
122
        if (fetchCallback) fetchCallback()
1587 steven 123
      })
3522 stevensc 124
      .catch((error) => console.log('>>: error > ', error))
125
      .finally(() => setLoading(false))
5070 stevensc 126
  }
1587 steven 127
 
1588 steven 128
  const handleUnfollow = async (link_unfollow) => {
5070 stevensc 129
    setLoading(true)
5996 stevensc 130
    await axios.post(link_unfollow).then(({ data }) => {
131
      if (data.success) fetchCallback()
3517 stevensc 132
 
5996 stevensc 133
      typeof data.data === 'string' &&
134
        addNotification({
135
          style: 'danger',
136
          msg: data.data,
137
        })
138
    })
5070 stevensc 139
    setLoading(false)
140
  }
1588 steven 141
 
1587 steven 142
  const getManageUrl = async () => {
143
    try {
3517 stevensc 144
      const { data } = await axios.get(link_admin)
145
      if (data.success) window.open(data.data, '_backend')
1587 steven 146
    } catch (error) {
147
      console.log('>>: error > ', error)
148
    }
149
  }
150
 
151
  return (
5996 stevensc 152
    <div className="profile_info">
3522 stevensc 153
      <div className={`${image ? 'd-flex' : 'd-block'} position-relative`}>
5996 stevensc 154
        {image && (
155
          <div className="profile_info_header_imgContainer">
156
            <img
157
              src={image}
158
              className="object-fit-contain"
159
              style={{ maxHeight: '100px' }}
160
              alt="group image"
161
            />
3520 stevensc 162
          </div>
5996 stevensc 163
        )}
164
        <div
165
          className={`${
166
            image ? 'col-8 d-flex flex-column align-items-start' : 'col-12'
167
          } ${isTopData ? 'justify-content-end' : 'justify-content-center'}`}
168
        >
169
          <h3
170
            className={`${status ? '' : 'w-100 text-left'} ${
171
              isTopData ? 'mb-2' : ''
172
            } w-100`}
173
          >
2296 stevensc 174
            {name}
175
          </h3>
5996 stevensc 176
          {isTopData && email && (
177
            <h4
178
              className={`${status ? '' : 'w-100 text-left'} ${
179
                isTopData ? 'mb-2' : ''
180
              } w-100`}
181
            >
3814 stevensc 182
              {email}
183
            </h4>
5996 stevensc 184
          )}
185
          {network && (
186
            <h4
187
              className={`${status ? '' : 'w-100 text-left'} ${
188
                isTopData ? 'mb-2' : ''
189
              } w-100`}
190
            >
3814 stevensc 191
              {network}
192
            </h4>
5996 stevensc 193
          )}
194
          {isTopData && (
2386 stevensc 195
            <ul>
5996 stevensc 196
              {link_view && (
2386 stevensc 197
                <li>
198
                  <a
199
                    href={link_view}
3816 stevensc 200
                    data-link={link_view}
201
                    className="btn btn-secondary ellipsis"
2386 stevensc 202
                  >
203
                    {btnAcceptTitle}
204
                  </a>
205
                </li>
5996 stevensc 206
              )}
207
              {link_inmail && (
2386 stevensc 208
                <li>
209
                  <a
210
                    href={link_inmail}
3816 stevensc 211
                    data-link={link_inmail}
212
                    className="btn btn-primary"
2386 stevensc 213
                  >
5996 stevensc 214
                    {labels.MESSAGE}
2386 stevensc 215
                  </a>
216
                </li>
5996 stevensc 217
              )}
2386 stevensc 218
            </ul>
5996 stevensc 219
          )}
3064 stevensc 220
        </div>
5996 stevensc 221
        {status && (
222
          <h4
223
            className={`col-sm-12 d-flex justify-content-center align-items-center ${
224
              !image ? 'position-relative' : ''
225
            }`}
226
          >
3068 stevensc 227
            {status}
228
          </h4>
5996 stevensc 229
        )}
2385 stevensc 230
      </div>
231
      <hr />
232
      <ul>
5996 stevensc 233
        {link_view && !isTopData && (
2316 stevensc 234
          <li>
235
            <a
5996 stevensc 236
              href={link_view}
237
              data-link={link_view}
238
              title=""
239
              className="btn btn-primary"
240
            >
241
              {btnAcceptTitle}
242
            </a>
243
          </li>
244
        )}
245
        {link_edit && (
246
          <li>
247
            <a
248
              href={link_edit}
249
              data-link={link_edit}
250
              title=""
251
              className="btn btn-secondary"
252
            >
253
              {btnEditTitle}
254
            </a>
255
          </li>
256
        )}
257
        {link_approve && (
258
          <li>
259
            <a
3816 stevensc 260
              href="#"
2317 stevensc 261
              className="btn btn-tertiary"
3816 stevensc 262
              onClick={(e) => {
5070 stevensc 263
                e.preventDefault()
264
                handleApproveConfirmationBox()
3816 stevensc 265
              }}
2316 stevensc 266
            >
5996 stevensc 267
              {labels.APPROVE}
2316 stevensc 268
            </a>
269
          </li>
5996 stevensc 270
        )}
271
        {link_accept && (
3046 stevensc 272
          <li>
273
            <a
3816 stevensc 274
              href="#"
3046 stevensc 275
              className="btn btn-tertiary"
3816 stevensc 276
              onClick={(e) => {
5070 stevensc 277
                e.preventDefault()
278
                handleApproveConfirmationBox()
3816 stevensc 279
              }}
3046 stevensc 280
            >
5996 stevensc 281
              {labels.ACCEPT}
3046 stevensc 282
            </a>
283
          </li>
5996 stevensc 284
        )}
285
        {link_reject && (
2320 stevensc 286
          <li>
3816 stevensc 287
            <a
288
              href="#"
5090 stevensc 289
              className="btn btn-tertiary"
3816 stevensc 290
              onClick={(e) => {
5070 stevensc 291
                e.preventDefault()
292
                handleRejectConfirmationBox()
3816 stevensc 293
              }}
2320 stevensc 294
            >
5996 stevensc 295
              {labels.REJECT}
3816 stevensc 296
            </a>
2320 stevensc 297
          </li>
5996 stevensc 298
        )}
299
        {link_delete && (
2320 stevensc 300
          <li>
3816 stevensc 301
            <a
302
              href="#"
5090 stevensc 303
              className="btn btn-tertiary"
3816 stevensc 304
              onClick={(e) => {
5070 stevensc 305
                e.preventDefault()
306
                handleShowConfirmationBox()
3816 stevensc 307
              }}
2320 stevensc 308
            >
3816 stevensc 309
              {btnCancelTitle}
310
            </a>
2320 stevensc 311
          </li>
5996 stevensc 312
        )}
313
        {link_inmail && !isTopData && (
2518 stevensc 314
          <li>
315
            <a
316
              href={link_inmail}
3816 stevensc 317
              data-link={link_inmail}
318
              title=""
5090 stevensc 319
              className="btn btn-secondary"
2518 stevensc 320
            >
5996 stevensc 321
              {labels.MESSAGE}
2518 stevensc 322
            </a>
323
          </li>
5996 stevensc 324
        )}
325
        {link_admin && (
2320 stevensc 326
          <li>
327
            <a
328
              onClick={() => getManageUrl()}
329
              data-link={link_admin}
330
              title="Administrar empresa"
5090 stevensc 331
              className="btn btn-secondary"
2320 stevensc 332
            >
5996 stevensc 333
              {labels.ADMINISTRATE}
2320 stevensc 334
            </a>
335
          </li>
5996 stevensc 336
        )}
337
        {link_unfollow && (
2320 stevensc 338
          <li>
339
            <a
340
              onClick={() => handleUnfollow(link_unfollow)}
341
              data-link={link_unfollow}
342
              title="Administrar empresa"
5090 stevensc 343
              className="btn btn-tertiary"
2320 stevensc 344
            >
5996 stevensc 345
              {labels.UNFOLLOW}
2320 stevensc 346
            </a>
347
          </li>
5996 stevensc 348
        )}
2519 stevensc 349
 
5996 stevensc 350
        {link_block && (
2519 stevensc 351
          <li>
3816 stevensc 352
            <a
353
              href="#"
5090 stevensc 354
              className="btn btn-tertiary"
3816 stevensc 355
              onClick={(e) => {
5070 stevensc 356
                e.preventDefault()
357
                handleBlockConfirmationBox()
3816 stevensc 358
              }}
2519 stevensc 359
            >
5996 stevensc 360
              {labels.BLOCK}
3816 stevensc 361
            </a>
2519 stevensc 362
          </li>
5996 stevensc 363
        )}
364
        {link_unblock && (
2320 stevensc 365
          <li>
3816 stevensc 366
            <a
367
              href="#"
2410 stevensc 368
              className="btn btn-tertiary"
3816 stevensc 369
              onClick={(e) => {
5070 stevensc 370
                e.preventDefault()
5996 stevensc 371
                handleUnblockConfirmationBox()
372
              }}
373
            >
374
              {labels.UNBLOCK}
375
            </a>
376
          </li>
377
        )}
378
        {link_request && (
379
          <li>
380
            <a
381
              href="#"
382
              className="btn btn-tertiary"
383
              onClick={(e) => {
384
                e.preventDefault()
5070 stevensc 385
                handleRequestConfirmationBox()
3816 stevensc 386
              }}
2320 stevensc 387
            >
5996 stevensc 388
              {labels.CONNECT}
3816 stevensc 389
            </a>
390
          </li>
5996 stevensc 391
        )}
392
        {link_cancel && (
2320 stevensc 393
          <li>
3816 stevensc 394
            <a
395
              href="#"
5090 stevensc 396
              className="btn btn-tertiary"
3816 stevensc 397
              onClick={(e) => {
5070 stevensc 398
                e.preventDefault()
399
                handleCancelConfirmationBox()
3816 stevensc 400
              }}
2320 stevensc 401
            >
5996 stevensc 402
              {labels.CANCEL}
3816 stevensc 403
            </a>
404
          </li>
5996 stevensc 405
        )}
406
        {link_leave && (
2320 stevensc 407
          <li>
3816 stevensc 408
            <a
409
              href="#"
2320 stevensc 410
              className="btn btn-tertiary"
3816 stevensc 411
              onClick={(e) => {
5070 stevensc 412
                e.preventDefault()
413
                handleLeaveConfirmationBox()
3816 stevensc 414
              }}
2320 stevensc 415
            >
5996 stevensc 416
              {labels.LEAVE}
3816 stevensc 417
            </a>
418
          </li>
5996 stevensc 419
        )}
420
        {link_impersonate && (
421
          <li>
422
            <a
423
              href="#"
424
              className="btn btn-tertiary"
425
              onClick={() => getImpersonateUrl(link_impersonate)}
426
            >
427
              {' '}
428
              Personificar{' '}
429
            </a>
430
          </li>
431
        )}
3816 stevensc 432
      </ul>
5996 stevensc 433
      {link_delete && (
5070 stevensc 434
        <div style={{ position: 'relative' }}>
2320 stevensc 435
          <ConfirmationBox
436
            show={showConfirmationBox}
3816 stevensc 437
            onClose={() => handleShowConfirmationBox(false)}
438
            onAccept={() => handleCancelApply(link_delete)}
2320 stevensc 439
          />
440
        </div>
5996 stevensc 441
      )}
442
      {link_cancel && (
443
        <div style={{ position: 'relative' }}>
444
          <ConfirmationBox
445
            show={showCancelConfirmationBox}
446
            onClose={() => handleCancelConfirmationBox(false)}
447
            onAccept={() => handleCancelApply(link_cancel)}
448
          />
449
        </div>
450
      )}
451
      {link_block && (
452
        <div style={{ position: 'relative' }}>
453
          <ConfirmationBox
454
            show={showBlockConfirmationBox}
455
            onClose={() => handleBlockConfirmationBox(false)}
456
            onAccept={() => handleCancelApply(link_block)}
457
          />
458
        </div>
459
      )}
460
      {link_accept && (
461
        <div style={{ position: 'relative' }}>
462
          <ConfirmationBox
463
            show={showApproveConfirmationBox}
464
            onClose={() => handleApproveConfirmationBox(false)}
465
            onAccept={() => handleCancelApply(link_accept)}
466
          />
467
        </div>
468
      )}
469
      {link_approve && (
470
        <div style={{ position: 'relative' }}>
471
          <ConfirmationBox
472
            show={showApproveConfirmationBox}
473
            onClose={() => handleApproveConfirmationBox(false)}
474
            onAccept={() => handleCancelApply(link_approve)}
475
          />
476
        </div>
477
      )}
478
      {link_reject && (
479
        <div style={{ position: 'relative' }}>
480
          <ConfirmationBox
481
            show={showRejectConfirmationBox}
482
            onClose={() => handleRejectConfirmationBox(false)}
483
            onAccept={() => handleCancelApply(link_reject)}
484
          />
485
        </div>
486
      )}
487
      {link_request && (
488
        <div style={{ position: 'relative' }}>
489
          <ConfirmationBox
490
            show={showRequestConfirmationBox}
491
            onClose={() => handleRequestConfirmationBox(false)}
492
            onAccept={() => handleCancelApply(link_request)}
493
          />
494
        </div>
495
      )}
496
      {link_unblock && (
497
        <div style={{ position: 'relative' }}>
498
          <ConfirmationBox
499
            show={showUnblockConfirmationBox}
500
            onClose={() => handleUnblockConfirmationBox(false)}
501
            onAccept={() => handleCancelApply(link_unblock)}
502
          />
503
        </div>
504
      )}
505
      {link_leave && (
506
        <div style={{ position: 'relative' }}>
507
          <ConfirmationBox
508
            show={showLeaveConfirmationBox}
509
            onClose={() => handleLeaveConfirmationBox(false)}
510
            onAccept={() => handleCancelApply(link_leave)}
511
          />
512
        </div>
513
      )}
514
      {loading && (
3522 stevensc 515
        <StyledSpinnerContainer>
516
          <Spinner />
517
        </StyledSpinnerContainer>
5996 stevensc 518
      )}
5070 stevensc 519
    </div>
520
  )
521
}
1587 steven 522
 
5070 stevensc 523
export default Profile