Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1111 | Rev 1113 | 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
 
1110 stevensc 51
  useEffect(() => {
1 www 52
    setTimelineUrl(timeline);
1110 stevensc 53
    fetchAuthorizedLinks();
1 www 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
                    {
1112 stevensc 232
                      currentTab === TABS.FEEDS
1105 stevensc 233
                      &&
1109 stevensc 234
                      <div
235
                        className="product-feed-tab animated fadeIn"
236
                        id="feed-dd feed"
1111 stevensc 237
                        style={{ display: 'block' }}
1109 stevensc 238
                      >
239
                        <div className="posts-section">
240
                          <FeedSection routeTimeline={timeline} />
241
                        </div>
242
                      </div>
243
                    }
244
                    {
1111 stevensc 245
                      !isFollower || currentTab === TABS.INFO
1109 stevensc 246
                      &&
247
                      < div
248
                        className="product-feed-tab animated fadeIn"
249
                        id="feed-dd info"
1111 stevensc 250
                        style={{ display: 'block' }}
1109 stevensc 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
                    }
1110 stevensc 314
                    {
315
                      initialLoading
316
                      &&
1 www 317
                      <div
318
                        style={{
319
                          display: "flex",
320
                          justifyContent: "center",
321
                          alignItems: "center",
322
                        }}
323
                      >
324
                        <Spinner />
325
                      </div>
1110 stevensc 326
                    }
1 www 327
                  </div>
328
                </div>
329
                <div className="col-lg-3">
330
                  <div className="right-sidebar">
331
                    {/* <?php echo $this->companySuggestionHelper($company_id)?> */}
332
                    <div
333
                      className="message-btn"
334
                      id="div-user-buttons"
335
                      style={{ position: "relative" }}
336
                    >
337
                      {authorizedLinks?.link_unfollow && (
338
                        <a
339
                          href="#"
340
                          className="btn-remove-follower"
341
                          onClick={(e) => {
342
                            e.preventDefault();
343
                            handleButtonAction(authorizedLinks?.link_unfollow);
344
                          }}
345
                        >
346
                          <i className="fa fa-user-times"></i> Dejar de seguir
347
                        </a>
348
                      )}
349
                      {authorizedLinks?.link_follow && (
350
                        <a
351
                          href="#"
352
                          className="btn-add-follower"
353
                          onClick={(e) => {
354
                            e.preventDefault();
355
                            handleButtonAction(authorizedLinks?.link_follow);
356
                          }}
357
                        >
358
                          <i className="fa fa-plus"></i> Seguir
359
                        </a>
360
                      )}
361
                      {authorizedLinks?.link_request && (
362
                        <a
363
                          href="#"
364
                          className="btn-request"
365
                          onClick={(e) => {
366
                            e.preventDefault();
367
                            handleButtonAction(authorizedLinks?.link_request);
368
                          }}
369
                        >
370
                          <i className="fa  fa-user-plus"></i>
371
                          Trabaja en esta empresa?
372
                        </a>
373
                      )}
374
                      {authorizedLinks?.link_accept && (
375
                        <a
376
                          href="#"
377
                          className="btn-accept"
378
                          onClick={(e) => {
379
                            e.preventDefault();
380
                            handleButtonAction(authorizedLinks?.link_accept);
381
                          }}
382
                        >
383
                          <i className="fa fa-check"></i> Aceptar
384
                        </a>
385
                      )}
386
                      {authorizedLinks?.link_cancel && (
387
                        <a
388
                          href="#"
389
                          title=""
390
                          className="btn-cancel"
391
                          onClick={(e) => {
392
                            e.preventDefault();
393
                            handleButtonAction(authorizedLinks?.link_cancel);
394
                          }}
395
                        >
396
                          <i className="fa fa-user-times "></i> Cancelar
397
                        </a>
398
                      )}
399
                      {authorizedLinks?.link_reject && (
400
                        <a
401
                          href="#"
402
                          title=""
403
                          className="btn-reject"
404
                          onClick={(e) => {
405
                            e.preventDefault();
406
                            handleButtonAction(authorizedLinks?.link_reject);
407
                          }}
408
                        >
409
                          <i className="fa fa-user-times "></i> Rechazar
410
                        </a>
411
                      )}
412
                      {authorizedLinks?.link_leave && (
413
                        <a
414
                          href="#"
415
                          data-link="{{>link_leave}}"
416
                          title=""
417
                          className="btn-leave"
418
                          onClick={(e) => {
419
                            e.preventDefault();
420
                            handleButtonAction(authorizedLinks?.link_leave);
421
                          }}
422
                        >
423
                          <i className="fa fa-user-times "></i>
424
                          Abandonar esta empresa
425
                        </a>
426
                      )}
427
                      {authorizedLinks?.link_contact && (
428
                        <a
429
                          href={authorizedLinks?.link_contact}
430
                          title=""
431
                          className="btn-send-message"
432
                        >
433
                          <i className="fa fa-envelope "></i> Mensaje
434
                        </a>
435
                      )}
436
                      {loading && (
437
                        <div className="spinner-container">
438
                          <Spinner />
439
                        </div>
440
                      )}
441
                    </div>
442
                    <div
1105 stevensc 443
                      className="widget suggestions full-width d-none d-md-block d-lg-block"
444
                      style={{
445
                        height: "450px",
446
                        overflowY: "auto",
447
                      }}
448
                    >
449
                      <div className="sd-title">
450
                        <h3>Empresas similares</h3>
451
                      </div>
452
                      {/* <!--sd-title end--> */}
453
                      {suggestionCompanies.length ? (
454
                        suggestionCompanies.map(element => {
455
                          return (
456
                            <div className="suggestion-usd" key={element.id}>
457
                              <img
458
                                style={{ width: "50px", height: "auto" }}
459
                                src={element.image}
460
                                alt=""
461
                              />
462
                              <div
463
                                className="sgt-text"
464
                              >
465
                                <a href={element.profile} target="_blank">
466
                                  <h4 className="text-dark">{element.name}</h4>
467
                                </a>
1 www 468
                              </div>
1105 stevensc 469
                            </div>
470
                          )
471
                        })
472
                      ) : (
473
                        <div className="view-more">Sin empresas similares</div>
474
                      )}
1 www 475
                    </div>
476
                  </div>
477
                  {/* <!--right-sidebar end--> */}
478
                </div>
479
              </div>
480
            </div>
481
            {/* <!-- main-section-data end--> */}
482
          </div>
483
        </div>
484
      </main>
1105 stevensc 485
    </React.Fragment >
1 www 486
  );
487
};
488
 
489
// const mapStateToProps = (state) => ({
490
 
491
// })
492
 
493
const mapDispatchToProps = {
494
  addNotification: (notification) => addNotification(notification),
495
  setTimelineUrl: (url) => setTimelineUrl(url),
496
};
497
 
498
export default connect(null, mapDispatchToProps)(View);