Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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