Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1107 | Rev 1109 | 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>
1105 stevensc 231
                    {!initialLoading
232
                      &&
1 www 233
                      <React.Fragment>
234
                        {
1105 stevensc 235
                          currentTab === TABS.FEEDS
236
                          &&
237
                          <div
238
                            className="product-feed-tab animated fadeIn"
239
                            id="feed-dd"
240
                          >
241
                            {/* <!--posts-section star--> */}
242
                            <div className="posts-section">
243
                              <FeedSection routeTimeline={timeline} />
244
                            </div>
245
                            {/* <!--posts-section end--> */}
246
                          </div>
247
                        }
248
                        {
249
                          currentTab === TABS.INFO || !isFollower
250
                          &&
251
                          < div
252
                            className="product-feed-tab animated fadeIn"
253
                            id="feed-dd"
254
                          >
255
                            {!!overview && (
256
                              <div className="user-profile-extended-ov">
257
                                <h3>Visión general</h3>
258
                                <span>{parse(overview)}</span>
1 www 259
                              </div>
1105 stevensc 260
                            )}
261
                            {!!locations.length && (
262
                              <div className="user-profile-extended-ov st2">
263
                                <h3>Ubicación</h3>
264
                                <span>
265
                                  {locations.map(
266
                                    ({ formatted_address, is_main }, index) => (
267
                                      <React.Fragment key={index}>
268
                                        {index >= 0 ? <hr /> : ""}
269
                                        <p>
270
                                          {`${formatted_address} ${is_main === "y" ? "(Principal)" : ""
1 www 271
                                            }`}
1105 stevensc 272
                                        </p>
273
                                      </React.Fragment>
274
                                    )
275
                                  )}
276
                                </span>
277
                              </div>
278
                            )}
279
                            {!!industry && (
280
                              <div className="user-profile-ov">
281
                                <h3>Industria</h3>
282
                                <span>{industry}</span>
283
                              </div>
284
                            )}
285
                            {!!companySize && (
286
                              <div className="user-profile-ov">
287
                                <h3>Tamaño de la empresa</h3>
288
                                <span>{companySize}</span>
289
                              </div>
290
                            )}
291
                            {!!foundationYear && (
292
                              <div className="user-profile-ov">
293
                                <h3>Año de fundación</h3>
294
                                <span>{foundationYear}</span>
295
                              </div>
296
                            )}
297
                            {!!website && (
298
                              <div className="user-profile-ov">
299
                                <h3>Página web</h3>
300
                                <span>{website}</span>
301
                              </div>
302
                            )}
303
                          </div>
304
                        }
1 www 305
                      </React.Fragment>
1105 stevensc 306
                    }
1 www 307
                    {initialLoading && (
308
                      <div
309
                        style={{
310
                          display: "flex",
311
                          justifyContent: "center",
312
                          alignItems: "center",
313
                        }}
314
                      >
315
                        <Spinner />
316
                      </div>
317
                    )}
318
 
319
                    {/* <!--user-profile-ov end-->  */}
320
                  </div>
321
                  {/* <!--main-ws-sec end--> */}
322
                </div>
323
                <div className="col-lg-3">
324
                  <div className="right-sidebar">
325
                    {/* <?php echo $this->companySuggestionHelper($company_id)?> */}
326
                    <div
327
                      className="message-btn"
328
                      id="div-user-buttons"
329
                      style={{ position: "relative" }}
330
                    >
331
                      {authorizedLinks?.link_unfollow && (
332
                        <a
333
                          href="#"
334
                          className="btn-remove-follower"
335
                          onClick={(e) => {
336
                            e.preventDefault();
337
                            handleButtonAction(authorizedLinks?.link_unfollow);
338
                          }}
339
                        >
340
                          <i className="fa fa-user-times"></i> Dejar de seguir
341
                        </a>
342
                      )}
343
                      {authorizedLinks?.link_follow && (
344
                        <a
345
                          href="#"
346
                          className="btn-add-follower"
347
                          onClick={(e) => {
348
                            e.preventDefault();
349
                            handleButtonAction(authorizedLinks?.link_follow);
350
                          }}
351
                        >
352
                          <i className="fa fa-plus"></i> Seguir
353
                        </a>
354
                      )}
355
                      {authorizedLinks?.link_request && (
356
                        <a
357
                          href="#"
358
                          className="btn-request"
359
                          onClick={(e) => {
360
                            e.preventDefault();
361
                            handleButtonAction(authorizedLinks?.link_request);
362
                          }}
363
                        >
364
                          <i className="fa  fa-user-plus"></i>
365
                          Trabaja en esta empresa?
366
                        </a>
367
                      )}
368
                      {authorizedLinks?.link_accept && (
369
                        <a
370
                          href="#"
371
                          className="btn-accept"
372
                          onClick={(e) => {
373
                            e.preventDefault();
374
                            handleButtonAction(authorizedLinks?.link_accept);
375
                          }}
376
                        >
377
                          <i className="fa fa-check"></i> Aceptar
378
                        </a>
379
                      )}
380
                      {authorizedLinks?.link_cancel && (
381
                        <a
382
                          href="#"
383
                          title=""
384
                          className="btn-cancel"
385
                          onClick={(e) => {
386
                            e.preventDefault();
387
                            handleButtonAction(authorizedLinks?.link_cancel);
388
                          }}
389
                        >
390
                          <i className="fa fa-user-times "></i> Cancelar
391
                        </a>
392
                      )}
393
                      {authorizedLinks?.link_reject && (
394
                        <a
395
                          href="#"
396
                          title=""
397
                          className="btn-reject"
398
                          onClick={(e) => {
399
                            e.preventDefault();
400
                            handleButtonAction(authorizedLinks?.link_reject);
401
                          }}
402
                        >
403
                          <i className="fa fa-user-times "></i> Rechazar
404
                        </a>
405
                      )}
406
                      {authorizedLinks?.link_leave && (
407
                        <a
408
                          href="#"
409
                          data-link="{{>link_leave}}"
410
                          title=""
411
                          className="btn-leave"
412
                          onClick={(e) => {
413
                            e.preventDefault();
414
                            handleButtonAction(authorizedLinks?.link_leave);
415
                          }}
416
                        >
417
                          <i className="fa fa-user-times "></i>
418
                          Abandonar esta empresa
419
                        </a>
420
                      )}
421
                      {authorizedLinks?.link_contact && (
422
                        <a
423
                          href={authorizedLinks?.link_contact}
424
                          title=""
425
                          className="btn-send-message"
426
                        >
427
                          <i className="fa fa-envelope "></i> Mensaje
428
                        </a>
429
                      )}
430
                      {loading && (
431
                        <div className="spinner-container">
432
                          <Spinner />
433
                        </div>
434
                      )}
435
                    </div>
436
                    <div
1105 stevensc 437
                      className="widget suggestions full-width d-none d-md-block d-lg-block"
438
                      style={{
439
                        height: "450px",
440
                        overflowY: "auto",
441
                      }}
442
                    >
443
                      <div className="sd-title">
444
                        <h3>Empresas similares</h3>
445
                      </div>
446
                      {/* <!--sd-title end--> */}
447
                      {suggestionCompanies.length ? (
448
                        suggestionCompanies.map(element => {
449
                          return (
450
                            <div className="suggestion-usd" key={element.id}>
451
                              <img
452
                                style={{ width: "50px", height: "auto" }}
453
                                src={element.image}
454
                                alt=""
455
                              />
456
                              <div
457
                                className="sgt-text"
458
                              >
459
                                <a href={element.profile} target="_blank">
460
                                  <h4 className="text-dark">{element.name}</h4>
461
                                </a>
1 www 462
                              </div>
1105 stevensc 463
                            </div>
464
                          )
465
                        })
466
                      ) : (
467
                        <div className="view-more">Sin empresas similares</div>
468
                      )}
1 www 469
                    </div>
470
                  </div>
471
                  {/* <!--right-sidebar end--> */}
472
                </div>
473
              </div>
474
            </div>
475
            {/* <!-- main-section-data end--> */}
476
          </div>
477
        </div>
478
      </main>
1105 stevensc 479
    </React.Fragment >
1 www 480
  );
481
};
482
 
483
// const mapStateToProps = (state) => ({
484
 
485
// })
486
 
487
const mapDispatchToProps = {
488
  addNotification: (notification) => addNotification(notification),
489
  setTimelineUrl: (url) => setTimelineUrl(url),
490
};
491
 
492
export default connect(null, mapDispatchToProps)(View);