Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1108 | Rev 1110 | 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([])
49
  const shouldSetInitialTab = useRef(true);
50
 
51
  useEffect(async () => {
52
    setTimelineUrl(timeline);
53
    await fetchAuthorizedLinks();
54
    shouldSetInitialTab.current = false;
55
    setInitialLoading(false);
56
    getSuggestionCompanies()
57
  }, []);
1108 stevensc 58
 
1 www 59
  const getSuggestionCompanies = async () => {
60
    try {
61
      setLoading(true);
62
      const response = await axios.get(`/helpers/company-suggestion/${companyId}`);
1105 stevensc 63
      if (response.data.success)
1 www 64
        setSuggestionCompanies(response.data.data)
65
    } catch (error) {
66
      console.log('>>: error > ', error)
1105 stevensc 67
    } finally {
1 www 68
      setLoading(false)
69
    }
70
  }
71
 
1107 stevensc 72
  useEffect(() => {
73
    isFollower
1108 stevensc 74
      ? setCurrentTab(TABS.FEEDS)
75
      : setCurrentTab(TABS.INFO)
1107 stevensc 76
  }, []);
77
 
1 www 78
  const fetchAuthorizedLinks = async () => {
79
    setLoading(true);
80
    const response = await axios.get(`/company/view/${companyId}`);
81
    const resData = response.data;
1105 stevensc 82
    (resData);
1 www 83
    if (resData.success) {
84
      setAuthorizedLinks(resData.data);
85
      setFollowers(resData.data.total_followers);
86
      if (resData.data.link_unfollow) {
87
        setIsFollower(true);
88
        if (shouldSetInitialTab.current) setCurrentTab(TABS.FEEDS);
89
      } else {
90
        setIsFollower(false);
91
      }
92
    }
93
    return setLoading(false);
94
  };
95
 
96
  const handleButtonAction = async (link) => {
97
    setLoading(true);
98
    const response = await axios.post(link);
99
    const resData = response.data;
100
    if (resData.success) {
101
      addNotification({
102
        style: "success",
103
        msg: resData.data,
104
      });
105
      fetchAuthorizedLinks();
106
    } else {
107
      setLoading(false);
108
      addNotification({
109
        style: "danger",
110
        msg: "ha ocurrido un error",
111
      });
112
    }
113
  };
114
  const changeCurrentTab = (tab) => {
1105 stevensc 115
    ('>>: tab> ', tab)
1 www 116
    setCurrentTab(tab)
117
  }
118
  return (
119
    <React.Fragment>
120
      <section className="cover-sec">
121
        <img
122
          id="user-cover-img"
1105 stevensc 123
          src={`/storage/type/company-cover/code/${companyId}/${cover ? `filename/${cover}` : ""
124
            }`}
1 www 125
          alt="cover-image"
126
        />
127
      </section>
128
      <main>
129
        <div className="main-section">
130
          <div className="container">
131
            <div className="main-section-data">
132
              <div className="row">
133
                <div className="col-lg-3">
134
                  <div className="main-left-sidebar">
135
                    <div className="user_profile">
136
                      <div className="user-pro-img">
137
                        <img
138
                          id="company-img"
1105 stevensc 139
                          src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""
140
                            }`}
1 www 141
                          alt="profile-image"
142
                        />
143
                      </div>
144
                      {/* <!--user-pro-img end--> */}
145
                      <div className="user_pro_status">
146
                        <h1>{companyName}</h1>
147
                        <ul className="flw-status">
148
                          <li>
1105 stevensc 149
                            <span style={{ fontSize: '1rem' }} >Seguidores</span>
150
                            <b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b>
1 www 151
                          </li>
152
                        </ul>
153
                      </div>
154
                      {/* <!--user_pro_status end--> */}
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
                            >
1105 stevensc 166
                              <i onClick={() => window.location.href = facebook} className="cursor-pointer fa fa-facebook-square" style={{ fontSize: '1.4rem' }} />
1 www 167
                            </div>
168
                          )
169
                        }
170
                        {
171
                          twitter && (
172
                            <div
173
                              className="col col-md col-sm"
174
                            >
1105 stevensc 175
                              <i onClick={() => window.location.href = twitter} className="cursor-pointer fa fa-twitter" style={{ fontSize: '1.4rem' }} />
1 www 176
                            </div>
177
                          )
178
                        }
179
                        {
180
                          instagram && (
181
                            <div
182
                              className="col col-md col-sm"
183
                            >
1105 stevensc 184
                              <i onClick={() => window.location.href = instagram} className="fa fa-instagram cursor-pointer" style={{ fontSize: '1.4rem' }} />
1 www 185
                            </div>
186
                          )
187
                        }
188
                      </div>
189
                    </div>
190
                    {/* <!--user_profile end--> */}
191
 
192
                    <CompanyFollowersHelper companyId={companyId} />
193
                  </div>
194
                  {/* <!--main-left-sidebar end--> */}
195
                </div>
196
                <div className="col-lg-6">
197
                  <div className="main-ws-sec">
198
                    <div className="user-tab-sec rewivew">
1108 stevensc 199
                      {
200
                        !initialLoading
201
                        &&
1 www 202
                        <div
203
                          className="row"
204
                        >
205
                          <div
206
                            className="col text-right"
207
                          >
1105 stevensc 208
                            <button
209
                              className="btn btn-link"
210
                              onClick={() => changeCurrentTab(TABS.FEEDS)}
211
                            >
212
                              <img src="/images/ic1.png" alt="" />
213
                              <span className="p-2 default-link ">Ver Publicaciones</span>
214
                            </button>
1 www 215
                          </div>
216
                          <div
217
                            className="col text-left"
218
                          >
1105 stevensc 219
                            <button
220
                              className="btn btn-link"
221
                              onClick={() => changeCurrentTab(TABS.INFO)}
222
                            >
223
                              <img src="/images/ic2.png" alt="" />
224
                              <span className="p-2 default-link">Ver Info</span>
225
                            </button>
1 www 226
                          </div>
227
                        </div>
1108 stevensc 228
                      }
1 www 229
                      {/* <!-- tab-feed end--> */}
230
                    </div>
1109 stevensc 231
                    {
232
                      isFollower & currentTab === TABS.FEEDS
1105 stevensc 233
                      &&
1109 stevensc 234
                      <div
235
                        className="product-feed-tab animated fadeIn"
236
                        id="feed-dd feed"
237
                      >
238
                        {/* <!--posts-section star--> */}
239
                        <div className="posts-section">
240
                          <FeedSection routeTimeline={timeline} />
241
                        </div>
242
                        {/* <!--posts-section end--> */}
243
                      </div>
244
                    }
245
                    {
246
                      !isFollower || currentTab === TABS.INFO
247
                      &&
248
                      < div
249
                        className="product-feed-tab animated fadeIn"
250
                        id="feed-dd info"
251
                      >
1 www 252
                        {
1109 stevensc 253
                          overview
1105 stevensc 254
                          &&
1109 stevensc 255
                          <div className="user-profile-extended-ov">
256
                            <h3>Visión general</h3>
257
                            <span>{parse(overview)}</span>
1105 stevensc 258
                          </div>
259
                        }
260
                        {
1109 stevensc 261
                          locations
1105 stevensc 262
                          &&
1109 stevensc 263
                          <div className="user-profile-extended-ov st2">
264
                            <h3>Ubicación</h3>
265
                            <span>
266
                              {locations.map(
267
                                ({ formatted_address, is_main }, index) => (
268
                                  <React.Fragment key={index}>
269
                                    {index >= 0 ? <hr /> : ""}
270
                                    <p>
271
                                      {`${formatted_address} ${is_main === "y" ? "(Principal)" : ""
272
                                        }`}
273
                                    </p>
274
                                  </React.Fragment>
275
                                )
276
                              )}
277
                            </span>
1105 stevensc 278
                          </div>
279
                        }
1109 stevensc 280
                        {
281
                          industry
282
                          &&
283
                          <div className="user-profile-ov">
284
                            <h3>Industria</h3>
285
                            <span>{industry}</span>
286
                          </div>
287
                        }
288
                        {
289
                          companySize
290
                          &&
291
                          <div className="user-profile-ov">
292
                            <h3>Tamaño de la empresa</h3>
293
                            <span>{companySize}</span>
294
                          </div>
295
                        }
296
                        {
297
                          foundationYear
298
                          &&
299
                          <div className="user-profile-ov">
300
                            <h3>Año de fundación</h3>
301
                            <span>{foundationYear}</span>
302
                          </div>
303
                        }
304
                        {
305
                          website
306
                          &&
307
                          <div className="user-profile-ov">
308
                            <h3>Página web</h3>
309
                            <span>{website}</span>
310
                          </div>
311
                        }
312
                      </div>
1105 stevensc 313
                    }
1 www 314
                    {initialLoading && (
315
                      <div
316
                        style={{
317
                          display: "flex",
318
                          justifyContent: "center",
319
                          alignItems: "center",
320
                        }}
321
                      >
322
                        <Spinner />
323
                      </div>
324
                    )}
325
 
326
                    {/* <!--user-profile-ov end-->  */}
327
                  </div>
328
                  {/* <!--main-ws-sec end--> */}
329
                </div>
330
                <div className="col-lg-3">
331
                  <div className="right-sidebar">
332
                    {/* <?php echo $this->companySuggestionHelper($company_id)?> */}
333
                    <div
334
                      className="message-btn"
335
                      id="div-user-buttons"
336
                      style={{ position: "relative" }}
337
                    >
338
                      {authorizedLinks?.link_unfollow && (
339
                        <a
340
                          href="#"
341
                          className="btn-remove-follower"
342
                          onClick={(e) => {
343
                            e.preventDefault();
344
                            handleButtonAction(authorizedLinks?.link_unfollow);
345
                          }}
346
                        >
347
                          <i className="fa fa-user-times"></i> Dejar de seguir
348
                        </a>
349
                      )}
350
                      {authorizedLinks?.link_follow && (
351
                        <a
352
                          href="#"
353
                          className="btn-add-follower"
354
                          onClick={(e) => {
355
                            e.preventDefault();
356
                            handleButtonAction(authorizedLinks?.link_follow);
357
                          }}
358
                        >
359
                          <i className="fa fa-plus"></i> Seguir
360
                        </a>
361
                      )}
362
                      {authorizedLinks?.link_request && (
363
                        <a
364
                          href="#"
365
                          className="btn-request"
366
                          onClick={(e) => {
367
                            e.preventDefault();
368
                            handleButtonAction(authorizedLinks?.link_request);
369
                          }}
370
                        >
371
                          <i className="fa  fa-user-plus"></i>
372
                          Trabaja en esta empresa?
373
                        </a>
374
                      )}
375
                      {authorizedLinks?.link_accept && (
376
                        <a
377
                          href="#"
378
                          className="btn-accept"
379
                          onClick={(e) => {
380
                            e.preventDefault();
381
                            handleButtonAction(authorizedLinks?.link_accept);
382
                          }}
383
                        >
384
                          <i className="fa fa-check"></i> Aceptar
385
                        </a>
386
                      )}
387
                      {authorizedLinks?.link_cancel && (
388
                        <a
389
                          href="#"
390
                          title=""
391
                          className="btn-cancel"
392
                          onClick={(e) => {
393
                            e.preventDefault();
394
                            handleButtonAction(authorizedLinks?.link_cancel);
395
                          }}
396
                        >
397
                          <i className="fa fa-user-times "></i> Cancelar
398
                        </a>
399
                      )}
400
                      {authorizedLinks?.link_reject && (
401
                        <a
402
                          href="#"
403
                          title=""
404
                          className="btn-reject"
405
                          onClick={(e) => {
406
                            e.preventDefault();
407
                            handleButtonAction(authorizedLinks?.link_reject);
408
                          }}
409
                        >
410
                          <i className="fa fa-user-times "></i> Rechazar
411
                        </a>
412
                      )}
413
                      {authorizedLinks?.link_leave && (
414
                        <a
415
                          href="#"
416
                          data-link="{{>link_leave}}"
417
                          title=""
418
                          className="btn-leave"
419
                          onClick={(e) => {
420
                            e.preventDefault();
421
                            handleButtonAction(authorizedLinks?.link_leave);
422
                          }}
423
                        >
424
                          <i className="fa fa-user-times "></i>
425
                          Abandonar esta empresa
426
                        </a>
427
                      )}
428
                      {authorizedLinks?.link_contact && (
429
                        <a
430
                          href={authorizedLinks?.link_contact}
431
                          title=""
432
                          className="btn-send-message"
433
                        >
434
                          <i className="fa fa-envelope "></i> Mensaje
435
                        </a>
436
                      )}
437
                      {loading && (
438
                        <div className="spinner-container">
439
                          <Spinner />
440
                        </div>
441
                      )}
442
                    </div>
443
                    <div
1105 stevensc 444
                      className="widget suggestions full-width d-none d-md-block d-lg-block"
445
                      style={{
446
                        height: "450px",
447
                        overflowY: "auto",
448
                      }}
449
                    >
450
                      <div className="sd-title">
451
                        <h3>Empresas similares</h3>
452
                      </div>
453
                      {/* <!--sd-title end--> */}
454
                      {suggestionCompanies.length ? (
455
                        suggestionCompanies.map(element => {
456
                          return (
457
                            <div className="suggestion-usd" key={element.id}>
458
                              <img
459
                                style={{ width: "50px", height: "auto" }}
460
                                src={element.image}
461
                                alt=""
462
                              />
463
                              <div
464
                                className="sgt-text"
465
                              >
466
                                <a href={element.profile} target="_blank">
467
                                  <h4 className="text-dark">{element.name}</h4>
468
                                </a>
1 www 469
                              </div>
1105 stevensc 470
                            </div>
471
                          )
472
                        })
473
                      ) : (
474
                        <div className="view-more">Sin empresas similares</div>
475
                      )}
1 www 476
                    </div>
477
                  </div>
478
                  {/* <!--right-sidebar end--> */}
479
                </div>
480
              </div>
481
            </div>
482
            {/* <!-- main-section-data end--> */}
483
          </div>
484
        </div>
485
      </main>
1105 stevensc 486
    </React.Fragment >
1 www 487
  );
488
};
489
 
490
// const mapStateToProps = (state) => ({
491
 
492
// })
493
 
494
const mapDispatchToProps = {
495
  addNotification: (notification) => addNotification(notification),
496
  setTimelineUrl: (url) => setTimelineUrl(url),
497
};
498
 
499
export default connect(null, mapDispatchToProps)(View);