Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1 www 1
import React, { useEffect, useRef } from "react";
2
import { useState } from "react";
3
import { connect } from "react-redux";
4
import styled from "styled-components";
1105 stevensc 5
import { axios } from "../../../utils";
1 www 6
import CompanyFollowersHelper from "../../../shared/helpers/company-followers-helper/CompanyFollowers";
7
import parse from "html-react-parser";
8
import { addNotification } from "../../../redux/notification/notification.actions";
9
import Spinner from "../../../shared/loading-spinner/Spinner";
10
import { setTimelineUrl } from "../../../redux/feed/feed.actions";
11
import FeedSection from "../../../dashboard/components/feed-section/FeedSection";
12
 
13
const TABS = {
14
  FEEDS: "FEEDS",
15
  INFO: "INFO",
16
};
17
 
18
const View = (props) => {
19
  // backendVars destructuring
20
  const {
21
    companyId,
22
    cover,
23
    image,
24
    totalFollowers,
25
    facebook,
26
    twitter,
27
    instagram,
28
    companyName,
29
    overview,
30
    locations,
31
    industry,
32
    companySize,
33
    foundationYear,
34
    website,
35
    timeline,
36
  } = props.backendVars;
37
 
38
  // redux destructuring
39
  const { addNotification, setTimelineUrl } = props;
40
 
41
  // const [isFollower, setIsFollower] = useState(!!+follower);
42
  const [authorizedLinks, setAuthorizedLinks] = useState(null);
43
  const [loading, setLoading] = useState(false);
44
  const [followers, setFollowers] = useState(totalFollowers);
45
  const [initialLoading, setInitialLoading] = useState(true);
1108 stevensc 46
  const [isFollower, setIsFollower] = useState(false);
1107 stevensc 47
  const [currentTab, setCurrentTab] = useState(TABS.INFO);
1 www 48
  const [suggestionCompanies, setSuggestionCompanies] = useState([])
1705 steven 49
  const [lookMore, setLookMore] = useState(false);
1 www 50
  const shouldSetInitialTab = useRef(true);
51
 
1110 stevensc 52
  useEffect(() => {
1 www 53
    setTimelineUrl(timeline);
1110 stevensc 54
    fetchAuthorizedLinks();
1 www 55
    shouldSetInitialTab.current = false;
56
    setInitialLoading(false);
57
    getSuggestionCompanies()
58
  }, []);
1108 stevensc 59
 
1 www 60
  const getSuggestionCompanies = async () => {
61
    try {
62
      setLoading(true);
63
      const response = await axios.get(`/helpers/company-suggestion/${companyId}`);
1105 stevensc 64
      if (response.data.success)
1 www 65
        setSuggestionCompanies(response.data.data)
66
    } catch (error) {
67
      console.log('>>: error > ', error)
1105 stevensc 68
    } finally {
1 www 69
      setLoading(false)
70
    }
71
  }
72
 
1107 stevensc 73
  useEffect(() => {
74
    isFollower
1108 stevensc 75
      ? setCurrentTab(TABS.FEEDS)
76
      : setCurrentTab(TABS.INFO)
1114 stevensc 77
  }, [isFollower]);
1107 stevensc 78
 
1 www 79
  const fetchAuthorizedLinks = async () => {
80
    setLoading(true);
81
    const response = await axios.get(`/company/view/${companyId}`);
82
    const resData = response.data;
1105 stevensc 83
    (resData);
1 www 84
    if (resData.success) {
85
      setAuthorizedLinks(resData.data);
86
      setFollowers(resData.data.total_followers);
87
      if (resData.data.link_unfollow) {
88
        setIsFollower(true);
89
        if (shouldSetInitialTab.current) setCurrentTab(TABS.FEEDS);
90
      } else {
91
        setIsFollower(false);
92
      }
93
    }
94
    return setLoading(false);
95
  };
96
 
97
  const handleButtonAction = async (link) => {
98
    setLoading(true);
99
    const response = await axios.post(link);
100
    const resData = response.data;
101
    if (resData.success) {
102
      addNotification({
103
        style: "success",
104
        msg: resData.data,
105
      });
106
      fetchAuthorizedLinks();
107
    } else {
108
      setLoading(false);
109
      addNotification({
110
        style: "danger",
111
        msg: "ha ocurrido un error",
112
      });
113
    }
114
  };
115
  const changeCurrentTab = (tab) => {
116
    setCurrentTab(tab)
117
  }
1705 steven 118
 
119
  const getData = () => {
1706 steven 120
    let infoFollows = [...suggestionCompanies]
1705 steven 121
    if(!lookMore){
122
      infoFollows = infoFollows.slice(0, 5);
123
    }
124
    return infoFollows
125
  }
1 www 126
  return (
127
    <React.Fragment>
128
      <section className="cover-sec">
129
        <img
130
          id="user-cover-img"
1105 stevensc 131
          src={`/storage/type/company-cover/code/${companyId}/${cover ? `filename/${cover}` : ""
132
            }`}
1 www 133
          alt="cover-image"
134
        />
135
      </section>
136
      <main>
137
        <div className="main-section">
138
          <div className="container">
139
            <div className="main-section-data">
140
              <div className="row">
141
                <div className="col-lg-3">
142
                  <div className="main-left-sidebar">
1689 steven 143
                    <div className="user_profile border-gray border-radius pb-5">
1 www 144
                      <div className="user-pro-img">
145
                        <img
146
                          id="company-img"
1105 stevensc 147
                          src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""
148
                            }`}
1 www 149
                          alt="profile-image"
150
                        />
151
                      </div>
152
                      {/* <!--user-pro-img end--> */}
153
                      <div className="user_pro_status">
154
                        <h1>{companyName}</h1>
1701 steven 155
                        <div
156
                          className="row"
157
                          style={{
158
                            margin: '-1px'
159
                          }}
160
                        >
161
                          {
162
                            facebook && (
163
                              <div
164
                                className="col col-md col-sm"
165
                              >
166
                                <i onClick={() => window.location.href = facebook} className="cursor-pointer fa fa-facebook" style={{ fontSize: '1.4rem' }} />
167
                              </div>
168
                            )
169
                          }
170
                          {
171
                            twitter && (
172
                              <div
173
                                className="col col-md col-sm"
174
                              >
175
                                <i onClick={() => window.location.href = twitter} className="cursor-pointer fa fa-twitter" style={{ fontSize: '1.4rem' }} />
176
                              </div>
177
                            )
178
                          }
179
                          {
180
                            instagram && (
181
                              <div
182
                                className="col col-md col-sm"
183
                              >
184
                                <i onClick={() => window.location.href = instagram} className="fa fa-instagram cursor-pointer" style={{ fontSize: '1.4rem' }} />
185
                              </div>
186
                            )
187
                          }
188
                        </div>
1 www 189
                        <ul className="flw-status">
1702 steven 190
                          <div
1712 steven 191
                            className="container"
1702 steven 192
                          >
193
                            <div
1712 steven 194
                              className="row overflow-auto"
1702 steven 195
                            >
196
                              <div
1703 steven 197
                                className="col ellipsis"
1701 steven 198
                              >
1702 steven 199
                                <li>
1712 steven 200
                                  <span style={{ fontSize: '1rem' }} >Seguidores</span>
201
                                  <b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b>
1702 steven 202
                                </li>
203
                              </div>
1712 steven 204
                              {authorizedLinks?.link_unfollow && (
205
                                <div
206
                                  className="col ellipsis"
207
                                >
208
                                  <li>
209
                                    <a
210
                                      href="#"
211
                                      className="btn-remove-follower"
212
                                      onClick={(e) => {
213
                                        e.preventDefault();
214
                                        handleButtonAction(authorizedLinks?.link_unfollow);
215
                                      }}
216
                                    >
217
                                      <i className="fa fa-user-times"></i> Dejar de seguir
218
                                    </a>
219
                                  </li>
220
                                </div>
221
                              )}
222
                              {authorizedLinks?.link_follow && (
223
                                <div
224
                                  className="col ellipsis"
225
                                >
226
                                  <li>
227
                                    <a
228
                                      href="#"
229
                                      className="btn-add-follower"
230
                                      onClick={(e) => {
231
                                        e.preventDefault();
232
                                        handleButtonAction(authorizedLinks?.link_follow);
233
                                      }}
234
                                    >
235
                                      <i className="fa fa-plus"></i> Seguir
236
                                    </a>
237
                                  </li>
238
                                </div>
239
                              )}
240
                              {authorizedLinks?.link_request && (
241
                                <div
242
                                  className="col ellipsis"
243
                                >
244
                                  <li>
245
                                    <a
246
                                      href="#"
247
                                      className="btn-request"
248
                                      onClick={(e) => {
249
                                        e.preventDefault();
250
                                        handleButtonAction(authorizedLinks?.link_request);
251
                                      }}
252
                                    >
253
                                      <i className="fa  fa-user-plus"></i>
254
                                      Trabaja en esta empresa?
255
                                    </a>
256
                                  </li>
257
                                </div>
258
                              )}
259
                              {authorizedLinks?.link_accept && (
260
                                <div
261
                                  className="col ellipsis"
262
                                >
263
                                  <li>
264
                                    <a
265
                                      href="#"
266
                                      className="btn-accept"
267
                                      onClick={(e) => {
268
                                        e.preventDefault();
269
                                        handleButtonAction(authorizedLinks?.link_accept);
270
                                      }}
271
                                    >
272
                                      <i className="fa fa-check"></i> Aceptar
273
                                    </a>
274
                                  </li>
275
                                </div>
276
                              )}
277
 
278
                              {authorizedLinks?.link_cancel && (
279
                                <div
280
                                  className="col ellipsis"
281
                                >
282
                                  <li>
283
                                    <a
284
                                      href="#"
285
                                      title=""
286
                                      className="btn-cancel"
287
                                      onClick={(e) => {
288
                                        e.preventDefault();
289
                                        handleButtonAction(authorizedLinks?.link_cancel);
290
                                      }}
291
                                    >
292
                                      <i className="fa fa-user-times "></i> Cancelar
293
                                    </a>
294
                                  </li>
295
                                </div>
296
                              )}
297
                              {authorizedLinks?.link_reject && (
298
                                <div
299
                                  className="col ellipsis"
300
                                >
301
                                  <li>
302
                                    <a
303
                                      href="#"
304
                                      title=""
305
                                      className="btn-reject"
306
                                      onClick={(e) => {
307
                                        e.preventDefault();
308
                                        handleButtonAction(authorizedLinks?.link_reject);
309
                                      }}
310
                                    >
311
                                      <i className="fa fa-user-times "></i> Rechazar
312
                                    </a>
313
                                  </li>
314
                                </div>
315
                              )}
316
 
317
                              {authorizedLinks?.link_leave && (
318
                                <div
319
                                  className="col ellipsis"
320
                                >
321
                                  <li>
322
                                    <a
323
                                      href="#"
324
                                      data-link="{{>link_leave}}"
325
                                      title=""
326
                                      className="btn-leave"
327
                                      onClick={(e) => {
328
                                        e.preventDefault();
329
                                        handleButtonAction(authorizedLinks?.link_leave);
330
                                      }}
331
                                    >
332
                                      <i className="fa fa-user-times "></i>
333
                                      Abandonar esta empresa
334
                                    </a>
335
                                  </li>
336
                                </div>
337
                              )}
338
                              {authorizedLinks?.link_contact && (
339
                                <div
340
                                  className="col ellipsis"
341
                                >
1704 steven 342
 
1712 steven 343
                                  <li>
344
                                    <a
345
                                      href={authorizedLinks?.link_contact}
346
                                      title=""
347
                                      className="btn-send-message"
348
                                    >
349
                                      <i className="fa fa-envelope "></i> Mensaje
350
                                    </a>
351
                                  </li>
352
                                </div>
353
                              )}
354
                            </div>
1702 steven 355
                          </div>
1 www 356
                        </ul>
357
                      </div>
358
                      {/* <!--user_pro_status end--> */}
359
                    </div>
360
                    {/* <!--user_profile end--> */}
361
 
362
                    <CompanyFollowersHelper companyId={companyId} />
363
                  </div>
364
                  {/* <!--main-left-sidebar end--> */}
365
                </div>
366
                <div className="col-lg-6">
367
                  <div className="main-ws-sec">
368
                    <div className="user-tab-sec rewivew">
1108 stevensc 369
                      {
370
                        !initialLoading
371
                        &&
1 www 372
                        <div
373
                          className="row"
374
                        >
1113 stevensc 375
                          {
376
                            isFollower
377
                            &&
378
                            <div
1708 steven 379
                              className="col text-left pl-0"
1105 stevensc 380
                            >
1113 stevensc 381
                              <button
1709 steven 382
                                className="btn btn-link p-0 text-decoration-none"
1113 stevensc 383
                                onClick={() => changeCurrentTab(TABS.FEEDS)}
384
                              >
1710 steven 385
                                <span className="p-2 default-link font-weight-bold text-dark">Ver Publicaciones</span>
1113 stevensc 386
                              </button>
387
                            </div>
388
                          }
1 www 389
                          <div
1708 steven 390
                            className="col text-right pl-0"
1 www 391
                          >
1105 stevensc 392
                            <button
1709 steven 393
                              className="btn btn-link p-0 text-decoration-none"
1105 stevensc 394
                              onClick={() => changeCurrentTab(TABS.INFO)}
395
                            >
1710 steven 396
                              <span className="p-2 default-link font-weight-bold text-dark">Ver Info</span>
1105 stevensc 397
                            </button>
1 www 398
                          </div>
399
                        </div>
1108 stevensc 400
                      }
1 www 401
                      {/* <!-- tab-feed end--> */}
402
                    </div>
1109 stevensc 403
                    {
1112 stevensc 404
                      currentTab === TABS.FEEDS
1105 stevensc 405
                      &&
1109 stevensc 406
                      <div
407
                        className="product-feed-tab animated fadeIn"
408
                        id="feed-dd feed"
1111 stevensc 409
                        style={{ display: 'block' }}
1109 stevensc 410
                      >
411
                        <div className="posts-section">
412
                          <FeedSection routeTimeline={timeline} />
413
                        </div>
414
                      </div>
415
                    }
416
                    {
1113 stevensc 417
                      currentTab === TABS.INFO
1109 stevensc 418
                      &&
419
                      < div
420
                        className="product-feed-tab animated fadeIn"
421
                        id="feed-dd info"
1111 stevensc 422
                        style={{ display: 'block' }}
1109 stevensc 423
                      >
1 www 424
                        {
1109 stevensc 425
                          overview
1105 stevensc 426
                          &&
1109 stevensc 427
                          <div className="user-profile-extended-ov">
428
                            <h3>Visión general</h3>
429
                            <span>{parse(overview)}</span>
1105 stevensc 430
                          </div>
431
                        }
432
                        {
1109 stevensc 433
                          locations
1105 stevensc 434
                          &&
1109 stevensc 435
                          <div className="user-profile-extended-ov st2">
436
                            <h3>Ubicación</h3>
437
                            <span>
438
                              {locations.map(
439
                                ({ formatted_address, is_main }, index) => (
440
                                  <React.Fragment key={index}>
441
                                    {index >= 0 ? <hr /> : ""}
442
                                    <p>
443
                                      {`${formatted_address} ${is_main === "y" ? "(Principal)" : ""
444
                                        }`}
445
                                    </p>
446
                                  </React.Fragment>
447
                                )
448
                              )}
449
                            </span>
1105 stevensc 450
                          </div>
451
                        }
1109 stevensc 452
                        {
453
                          industry
454
                          &&
455
                          <div className="user-profile-ov">
456
                            <h3>Industria</h3>
457
                            <span>{industry}</span>
458
                          </div>
459
                        }
460
                        {
461
                          companySize
462
                          &&
463
                          <div className="user-profile-ov">
464
                            <h3>Tamaño de la empresa</h3>
465
                            <span>{companySize}</span>
466
                          </div>
467
                        }
468
                        {
469
                          foundationYear
470
                          &&
471
                          <div className="user-profile-ov">
472
                            <h3>Año de fundación</h3>
473
                            <span>{foundationYear}</span>
474
                          </div>
475
                        }
476
                        {
477
                          website
478
                          &&
479
                          <div className="user-profile-ov">
480
                            <h3>Página web</h3>
481
                            <span>{website}</span>
482
                          </div>
483
                        }
484
                      </div>
1105 stevensc 485
                    }
1110 stevensc 486
                    {
487
                      initialLoading
488
                      &&
1 www 489
                      <div
490
                        style={{
491
                          display: "flex",
492
                          justifyContent: "center",
493
                          alignItems: "center",
494
                        }}
495
                      >
496
                        <Spinner />
497
                      </div>
1110 stevensc 498
                    }
1 www 499
                  </div>
500
                </div>
501
                <div className="col-lg-3">
502
                  <div className="right-sidebar">
1701 steven 503
                    {loading && (
504
                      <div className="spinner-container">
505
                        <Spinner />
506
                      </div>
507
                    )}
1 www 508
                    <div
1105 stevensc 509
                      className="widget suggestions full-width d-none d-md-block d-lg-block"
510
                      style={{
1707 steven 511
                        height: "auto",
1105 stevensc 512
                        overflowY: "auto",
513
                      }}
514
                    >
515
                      <div className="sd-title">
516
                        <h3>Empresas similares</h3>
517
                      </div>
518
                      {/* <!--sd-title end--> */}
519
                      {suggestionCompanies.length ? (
1705 steven 520
                        getData().map(element => {
1105 stevensc 521
                          return (
1691 steven 522
                            <div className="suggestion-usd d-flex justify-content-start align-items-center " key={element.id}>
1105 stevensc 523
                              <img
1692 steven 524
                                style={{ width: "10%", height: "auto" }}
1105 stevensc 525
                                src={element.image}
526
                                alt=""
527
                              />
528
                              <div
529
                                className="sgt-text"
530
                              >
531
                                <a href={element.profile} target="_blank">
532
                                  <h4 className="text-dark">{element.name}</h4>
533
                                </a>
1 www 534
                              </div>
1105 stevensc 535
                            </div>
536
                          )
537
                        })
538
                      ) : (
539
                        <div className="view-more">Sin empresas similares</div>
540
                      )}
1705 steven 541
                      <div
542
                        className="w-100 text-center"
543
                      >
544
                        <button className="btn btn-primary" onClick={() => setLookMore(!lookMore)}>
545
                          Ver mas
546
                        </button>
547
                      </div>
1 www 548
                    </div>
549
                  </div>
550
                  {/* <!--right-sidebar end--> */}
551
                </div>
552
              </div>
553
            </div>
554
            {/* <!-- main-section-data end--> */}
555
          </div>
556
        </div>
557
      </main>
1105 stevensc 558
    </React.Fragment >
1 www 559
  );
560
};
561
 
562
// const mapStateToProps = (state) => ({
563
 
564
// })
565
 
566
const mapDispatchToProps = {
567
  addNotification: (notification) => addNotification(notification),
568
  setTimelineUrl: (url) => setTimelineUrl(url),
569
};
570
 
571
export default connect(null, mapDispatchToProps)(View);