Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2513 | Rev 2516 | 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
        }
2513 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
            <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>
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();
226
                handleApproveConfirmationBox();
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
        {
2320 stevensc 264
          link_admin &&
265
          <li>
266
            <a
267
              onClick={() => getManageUrl()}
268
              data-link={link_admin}
269
              title="Administrar empresa"
270
              className="btn btn-primary"
271
            >
272
              Administrar
273
            </a>
274
          </li>
2296 stevensc 275
        }
276
        {
2320 stevensc 277
          link_unfollow
278
          &&
279
          <li>
280
            <a
281
              onClick={() => handleUnfollow(link_unfollow)}
282
              data-link={link_unfollow}
283
              title="Administrar empresa"
284
              className="btn btn-primary"
285
            >
286
              Dejar de seguir
287
            </a>
288
          </li>
2296 stevensc 289
        }
2286 stevensc 290
 
2296 stevensc 291
        {
2320 stevensc 292
          link_block &&
293
          <li>
294
            <a
295
              href="#"
2393 stevensc 296
              className="btn btn-primary"
2320 stevensc 297
              onClick={(e) => {
298
                e.preventDefault();
299
                handleBlockConfirmationBox();
300
              }}
301
            >
302
              Bloquear
303
            </a>
304
          </li>
2296 stevensc 305
        }
306
        {
307
          link_unblock && (
308
            <li>
309
              <a
310
                href="#"
311
                className="btn btn-tertiary"
312
                onClick={(e) => {
313
                  e.preventDefault();
314
                  handleUnblockConfirmationBox();
315
                }}
316
              >
317
                Desbloquear
318
              </a>
319
            </li>
320
          )
321
        }
322
        {
2320 stevensc 323
          link_request
324
          &&
325
          <li>
326
            <a
327
              href="#"
2410 stevensc 328
              className="btn btn-tertiary"
2320 stevensc 329
              onClick={(e) => {
330
                e.preventDefault();
331
                handleRequestConfirmationBox();
332
              }}
333
            >
334
              Conectar
335
            </a>
336
          </li>
2296 stevensc 337
        }
338
        {
2320 stevensc 339
          link_cancel
340
          &&
341
          <li>
342
            <a
343
              href="#"
2393 stevensc 344
              className="btn btn-primary"
2320 stevensc 345
              onClick={(e) => {
346
                e.preventDefault();
347
                handleCancelConfirmationBox();
348
              }}
349
            >
2507 stevensc 350
              Cancelar
2320 stevensc 351
            </a>
352
          </li>
2296 stevensc 353
        }
354
        {
2320 stevensc 355
          link_leave &&
356
          <li>
357
            <a
358
              href="#"
359
              className="btn btn-tertiary"
360
              onClick={(e) => {
361
                e.preventDefault();
362
                handleLeaveConfirmationBox();
363
              }}
364
            >
365
              Abandonar
366
            </a>
367
          </li>
2296 stevensc 368
        }
369
      </ul>
2285 stevensc 370
      {
2320 stevensc 371
        link_delete &&
372
        <div style={{ position: "relative" }}>
373
          <ConfirmationBox
374
            show={showConfirmationBox}
375
            onClose={() => handleShowConfirmationBox(false)}
376
            onAccept={() => handleCancelApply(link_delete)}
377
          />
378
        </div>
2285 stevensc 379
      }
380
      {
381
        link_cancel && (
382
          <div style={{ position: "relative" }}>
383
            <ConfirmationBox
384
              show={showCancelConfirmationBox}
385
              onClose={() => handleCancelConfirmationBox(false)}
386
              onAccept={() => handleCancelApply(link_cancel)}
387
            />
388
          </div>
389
        )
390
      }
391
      {
392
        link_block && (
393
          <div style={{ position: "relative" }}>
394
            <ConfirmationBox
395
              show={showBlockConfirmationBox}
396
              onClose={() => handleBlockConfirmationBox(false)}
397
              onAccept={() => handleCancelApply(link_block)}
398
            />
399
          </div>
400
        )
401
      }
402
      {
2314 stevensc 403
        link_accept && (
2285 stevensc 404
          <div style={{ position: "relative" }}>
405
            <ConfirmationBox
406
              show={showApproveConfirmationBox}
407
              onClose={() => handleApproveConfirmationBox(false)}
2314 stevensc 408
              onAccept={() => handleCancelApply(link_accept)}
2285 stevensc 409
            />
410
          </div>
411
        )
412
      }
413
      {
414
        link_reject && (
415
          <div style={{ position: "relative" }}>
416
            <ConfirmationBox
417
              show={showRejectConfirmationBox}
418
              onClose={() => handleRejectConfirmationBox(false)}
419
              onAccept={() => handleCancelApply(link_reject)}
420
            />
421
          </div>
422
        )
423
      }
424
      {
425
        link_request && (
426
          <div style={{ position: "relative" }}>
427
            <ConfirmationBox
428
              show={showRequestConfirmationBox}
429
              onClose={() => handleRequestConfirmationBox(false)}
430
              onAccept={() => handleCancelApply(link_request)}
431
            />
432
          </div>
433
        )
434
      }
435
      {
436
        link_unblock && (
437
          <div style={{ position: "relative" }}>
438
            <ConfirmationBox
439
              show={showUnblockConfirmationBox}
440
              onClose={() => handleUnblockConfirmationBox(false)}
441
              onAccept={() => handleCancelApply(link_unblock)}
442
            />
443
          </div>
444
        )
445
      }
446
      {
447
        link_leave && (
448
          <div style={{ position: "relative" }}>
449
            <ConfirmationBox
450
              show={showLeaveConfirmationBox}
451
              onClose={() => handleLeaveConfirmationBox(false)}
452
              onAccept={() => handleCancelApply(link_leave)}
453
            />
454
          </div>
455
        )
456
      }
457
      {
458
        loading && (
459
          <StyledSpinnerContainer>
460
            <Spinner />
461
          </StyledSpinnerContainer>
462
        )
463
      }
2296 stevensc 464
    </div>
1587 steven 465
  );
466
};
467
 
468
export default Profile;