Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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