Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2781 | Rev 2784 | 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
        }
2782 stevensc 158
        <div className={image ? 'col-md-8 d-flex flex-column justify-content-end 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
          {
163
            <ul>
164
              {
165
                link_view
166
                &&
167
                <li>
168
                  <a
169
                    href={link_view}
170
                    data-link={link_view}
171
                    className="btn btn-secondary ellipsis"
172
                  >
173
                    {btnAcceptTitle}
174
                  </a>
175
                </li>
176
              }
177
              {
178
                link_inmail
179
                &&
180
                <li>
181
                  <a
182
                    href={link_inmail}
183
                    data-link={link_inmail}
184
                    className="btn btn-primary"
185
                  >
186
                    Mensaje
187
                  </a>
188
                </li>
189
              }
190
            </ul>
191
          }
2287 stevensc 192
        </div>
2297 stevensc 193
        {
194
          status
195
          &&
2517 stevensc 196
          <h4 className="col-sm-12 d-flex justify-content-center align-items-center">
2297 stevensc 197
            {status}
198
          </h4>
199
        }
2385 stevensc 200
      </div>
201
      <hr />
202
      <ul>
2316 stevensc 203
        {
2296 stevensc 204
          link_edit && (
205
            <li>
206
              <a
207
                href={link_edit}
208
                data-link={link_edit}
209
                title=""
210
                className="btn btn-tertiary"
211
              >
2320 stevensc 212
                {btnEditTitle}
2296 stevensc 213
              </a>
214
            </li>
215
          )
216
        }
217
        {
2511 stevensc 218
          link_approve
2316 stevensc 219
          &&
220
          <li>
221
            <a
222
              href="#"
2317 stevensc 223
              className="btn btn-tertiary"
2316 stevensc 224
              onClick={(e) => {
225
                e.preventDefault();
2780 stevensc 226
                handleCancelApply(link_approve);
2316 stevensc 227
              }}
228
            >
2510 stevensc 229
              Aprobar
2316 stevensc 230
            </a>
231
          </li>
2296 stevensc 232
        }
233
        {
2320 stevensc 234
          link_reject &&
235
          <li>
236
            <a
237
              href="#"
238
              className="btn btn-primary"
239
              onClick={(e) => {
240
                e.preventDefault();
241
                handleRejectConfirmationBox();
242
              }}
243
            >
244
              Rechazar
245
            </a>
246
          </li>
2296 stevensc 247
        }
248
        {
2320 stevensc 249
          link_delete &&
250
          <li>
251
            <a
252
              href="#"
253
              className="btn btn-primary"
254
              onClick={(e) => {
255
                e.preventDefault();
256
                handleShowConfirmationBox();
257
              }}
258
            >
259
              {btnCancelTitle}
260
            </a>
261
          </li>
2296 stevensc 262
        }
263
        {
2518 stevensc 264
          link_inmail && !isTopData
265
          &&
266
          <li>
267
            <a
268
              href={link_inmail}
269
              data-link={link_inmail}
270
              title=""
271
              className="btn btn-primary"
272
            >
273
              Mensaje
274
            </a>
275
          </li>
276
        }
277
        {
2320 stevensc 278
          link_admin &&
279
          <li>
280
            <a
281
              onClick={() => getManageUrl()}
282
              data-link={link_admin}
283
              title="Administrar empresa"
284
              className="btn btn-primary"
285
            >
286
              Administrar
287
            </a>
288
          </li>
2296 stevensc 289
        }
290
        {
2320 stevensc 291
          link_unfollow
292
          &&
293
          <li>
294
            <a
295
              onClick={() => handleUnfollow(link_unfollow)}
296
              data-link={link_unfollow}
297
              title="Administrar empresa"
298
              className="btn btn-primary"
299
            >
300
              Dejar de seguir
301
            </a>
302
          </li>
2296 stevensc 303
        }
2519 stevensc 304
 
2296 stevensc 305
        {
2519 stevensc 306
          link_block &&
307
          <li>
308
            <a
309
              href="#"
310
              className="btn btn-primary"
311
              onClick={(e) => {
312
                e.preventDefault();
313
                handleBlockConfirmationBox();
314
              }}
315
            >
316
              Bloquear
317
            </a>
318
          </li>
319
        }
320
        {
2296 stevensc 321
          link_unblock && (
322
            <li>
323
              <a
324
                href="#"
325
                className="btn btn-tertiary"
326
                onClick={(e) => {
327
                  e.preventDefault();
328
                  handleUnblockConfirmationBox();
329
                }}
330
              >
331
                Desbloquear
332
              </a>
333
            </li>
334
          )
335
        }
336
        {
2320 stevensc 337
          link_request
338
          &&
339
          <li>
340
            <a
341
              href="#"
2410 stevensc 342
              className="btn btn-tertiary"
2320 stevensc 343
              onClick={(e) => {
344
                e.preventDefault();
345
                handleRequestConfirmationBox();
346
              }}
347
            >
348
              Conectar
349
            </a>
350
          </li>
2296 stevensc 351
        }
352
        {
2320 stevensc 353
          link_cancel
354
          &&
355
          <li>
356
            <a
357
              href="#"
2393 stevensc 358
              className="btn btn-primary"
2320 stevensc 359
              onClick={(e) => {
360
                e.preventDefault();
361
                handleCancelConfirmationBox();
362
              }}
363
            >
2507 stevensc 364
              Cancelar
2320 stevensc 365
            </a>
366
          </li>
2296 stevensc 367
        }
368
        {
2320 stevensc 369
          link_leave &&
370
          <li>
371
            <a
372
              href="#"
373
              className="btn btn-tertiary"
374
              onClick={(e) => {
375
                e.preventDefault();
376
                handleLeaveConfirmationBox();
377
              }}
378
            >
379
              Abandonar
380
            </a>
381
          </li>
2296 stevensc 382
        }
383
      </ul>
2285 stevensc 384
      {
2320 stevensc 385
        link_delete &&
386
        <div style={{ position: "relative" }}>
387
          <ConfirmationBox
388
            show={showConfirmationBox}
389
            onClose={() => handleShowConfirmationBox(false)}
390
            onAccept={() => handleCancelApply(link_delete)}
391
          />
392
        </div>
2285 stevensc 393
      }
394
      {
395
        link_cancel && (
396
          <div style={{ position: "relative" }}>
397
            <ConfirmationBox
398
              show={showCancelConfirmationBox}
399
              onClose={() => handleCancelConfirmationBox(false)}
400
              onAccept={() => handleCancelApply(link_cancel)}
401
            />
402
          </div>
403
        )
404
      }
405
      {
406
        link_block && (
407
          <div style={{ position: "relative" }}>
408
            <ConfirmationBox
409
              show={showBlockConfirmationBox}
410
              onClose={() => handleBlockConfirmationBox(false)}
411
              onAccept={() => handleCancelApply(link_block)}
412
            />
413
          </div>
414
        )
415
      }
416
      {
2314 stevensc 417
        link_accept && (
2285 stevensc 418
          <div style={{ position: "relative" }}>
419
            <ConfirmationBox
420
              show={showApproveConfirmationBox}
421
              onClose={() => handleApproveConfirmationBox(false)}
2314 stevensc 422
              onAccept={() => handleCancelApply(link_accept)}
2285 stevensc 423
            />
424
          </div>
425
        )
426
      }
427
      {
2582 stevensc 428
        link_approve && (
429
          <div style={{ position: "relative" }}>
430
            <ConfirmationBox
431
              show={showApproveConfirmationBox}
432
              onClose={() => handleApproveConfirmationBox(false)}
433
              onAccept={() => handleCancelApply(link_approve)}
434
            />
435
          </div>
436
        )
437
      }
438
      {
2285 stevensc 439
        link_reject && (
440
          <div style={{ position: "relative" }}>
441
            <ConfirmationBox
442
              show={showRejectConfirmationBox}
443
              onClose={() => handleRejectConfirmationBox(false)}
444
              onAccept={() => handleCancelApply(link_reject)}
445
            />
446
          </div>
447
        )
448
      }
449
      {
450
        link_request && (
451
          <div style={{ position: "relative" }}>
452
            <ConfirmationBox
453
              show={showRequestConfirmationBox}
454
              onClose={() => handleRequestConfirmationBox(false)}
455
              onAccept={() => handleCancelApply(link_request)}
456
            />
457
          </div>
458
        )
459
      }
460
      {
461
        link_unblock && (
462
          <div style={{ position: "relative" }}>
463
            <ConfirmationBox
464
              show={showUnblockConfirmationBox}
465
              onClose={() => handleUnblockConfirmationBox(false)}
466
              onAccept={() => handleCancelApply(link_unblock)}
467
            />
468
          </div>
469
        )
470
      }
471
      {
472
        link_leave && (
473
          <div style={{ position: "relative" }}>
474
            <ConfirmationBox
475
              show={showLeaveConfirmationBox}
476
              onClose={() => handleLeaveConfirmationBox(false)}
477
              onAccept={() => handleCancelApply(link_leave)}
478
            />
479
          </div>
480
        )
481
      }
482
      {
483
        loading && (
484
          <StyledSpinnerContainer>
485
            <Spinner />
486
          </StyledSpinnerContainer>
487
        )
488
      }
2296 stevensc 489
    </div>
1587 steven 490
  );
491
};
492
 
493
export default Profile;