Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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