Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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