Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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