Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3892 | Rev 3930 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3552 stevensc 1
/* eslint-disable react/prop-types */
1 www 2
import React, { useEffect, useRef } from "react";
3
import { useState } from "react";
4
import { connect } from "react-redux";
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([])
1705 steven 49
  const [lookMore, setLookMore] = useState(false);
1 www 50
  const shouldSetInitialTab = useRef(true);
51
 
1110 stevensc 52
  useEffect(() => {
1 www 53
    setTimelineUrl(timeline);
1110 stevensc 54
    fetchAuthorizedLinks();
1 www 55
    shouldSetInitialTab.current = false;
56
    setInitialLoading(false);
57
    getSuggestionCompanies()
58
  }, []);
1108 stevensc 59
 
1 www 60
  const getSuggestionCompanies = async () => {
61
    try {
62
      setLoading(true);
63
      const response = await axios.get(`/helpers/company-suggestion/${companyId}`);
1105 stevensc 64
      if (response.data.success)
1 www 65
        setSuggestionCompanies(response.data.data)
66
    } catch (error) {
67
      console.log('>>: error > ', error)
1105 stevensc 68
    } finally {
1 www 69
      setLoading(false)
70
    }
71
  }
72
 
1107 stevensc 73
  useEffect(() => {
74
    isFollower
1108 stevensc 75
      ? setCurrentTab(TABS.FEEDS)
76
      : setCurrentTab(TABS.INFO)
1114 stevensc 77
  }, [isFollower]);
1107 stevensc 78
 
1 www 79
  const fetchAuthorizedLinks = async () => {
80
    setLoading(true);
81
    const response = await axios.get(`/company/view/${companyId}`);
82
    const resData = response.data;
1105 stevensc 83
    (resData);
1 www 84
    if (resData.success) {
85
      setAuthorizedLinks(resData.data);
86
      setFollowers(resData.data.total_followers);
87
      if (resData.data.link_unfollow) {
88
        setIsFollower(true);
89
        if (shouldSetInitialTab.current) setCurrentTab(TABS.FEEDS);
90
      } else {
91
        setIsFollower(false);
92
      }
93
    }
94
    return setLoading(false);
95
  };
96
 
97
  const handleButtonAction = async (link) => {
98
    setLoading(true);
99
    const response = await axios.post(link);
100
    const resData = response.data;
101
    if (resData.success) {
102
      addNotification({
103
        style: "success",
104
        msg: resData.data,
105
      });
106
      fetchAuthorizedLinks();
107
    } else {
108
      setLoading(false);
109
      addNotification({
110
        style: "danger",
111
        msg: "ha ocurrido un error",
112
      });
113
    }
114
  };
115
  const changeCurrentTab = (tab) => {
116
    setCurrentTab(tab)
117
  }
1705 steven 118
 
119
  const getData = () => {
1706 steven 120
    let infoFollows = [...suggestionCompanies]
2258 stevensc 121
    if (!lookMore) {
2943 stevensc 122
      infoFollows = infoFollows.slice(0, 3);
1705 steven 123
    }
124
    return infoFollows
125
  }
1 www 126
  return (
127
    <React.Fragment>
128
      <section className="cover-sec">
129
        <img
130
          id="user-cover-img"
1105 stevensc 131
          src={`/storage/type/company-cover/code/${companyId}/${cover ? `filename/${cover}` : ""
132
            }`}
1 www 133
          alt="cover-image"
134
        />
135
      </section>
136
      <main>
137
        <div className="main-section">
3929 stevensc 138
          <div className="main-section-data">
139
            <div className="main-left-sidebar">
140
              <div className="user_profile">
141
                <div className="user-pro-img">
142
                  <img
143
                    src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""}`}
144
                    alt="profile-image"
145
                  />
146
                </div>
147
                <div className="user_pro_status horizontal-list">
148
                  <h1>{companyName}</h1>
149
                  <div className="row px-5" style={{ marginTop: '10px' }}>
150
                    {facebook &&
151
                      <i
152
                        onClick={() => window.location.href = facebook}
153
                        className="cursor-pointer fa fa-facebook"
154
                        style={{ fontSize: '1.4rem' }}
155
                      />
156
                    }
157
                    {twitter &&
158
                      <i
159
                        onClick={() => window.location.href = twitter}
160
                        className="cursor-pointer fa fa-twitter"
161
                        style={{ fontSize: '1.4rem' }}
162
                      />
163
                    }
164
                    {instagram &&
165
                      <i
166
                        onClick={() => window.location.href = instagram}
167
                        className="fa fa-instagram cursor-pointer"
168
                        style={{ fontSize: '1.4rem' }}
169
                      />
170
                    }
2442 stevensc 171
                  </div>
3929 stevensc 172
                  <div className="container horizontal-list">
173
                    <div className="row ">
174
                      <div className="members_count">
175
                        <b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b>
176
                        <p style={{ fontSize: '1rem' }} className="ellipsis">Seguidores</p>
177
                      </div>
178
                      {authorizedLinks?.link_unfollow &&
179
                        <button
180
                          className="btn btn-secondary"
181
                          onClick={() => handleButtonAction(authorizedLinks?.link_unfollow)}
182
                        >
183
                          Dejar de seguir
184
                        </button>
2442 stevensc 185
                      }
3929 stevensc 186
                      {authorizedLinks?.link_follow &&
187
                        <button
188
                          className="btn btn-secondary"
189
                          onClick={() => handleButtonAction(authorizedLinks?.link_follow)}
190
                        >
191
                          Seguir
192
                        </button>
2442 stevensc 193
                      }
3929 stevensc 194
                      {
195
                        (authorizedLinks?.link_request && authorizedLinks?.link_unfollow)
196
                        &&
197
                        <button
198
                          className="btn btn-tertiary"
199
                          onClick={() => handleButtonAction(authorizedLinks?.link_request)}
200
                        >
201
                          ¿Trabaja en esta empresa?
202
                        </button>
2442 stevensc 203
                      }
3929 stevensc 204
                      {authorizedLinks?.link_accept &&
205
                        <button
206
                          className="btn btn-tertiary"
207
                          onClick={() => handleButtonAction(authorizedLinks?.link_accept)}
208
                        >
209
                          Aceptar
210
                        </button>
211
                      }
212
                      {authorizedLinks?.link_cancel &&
213
                        <button
214
                          title=""
215
                          className="btn btn-tertiary"
216
                          onClick={() => handleButtonAction(authorizedLinks?.link_cancel)}
217
                        >
218
                          Cancelar
219
                        </button>
220
                      }
221
                      {authorizedLinks?.link_reject &&
222
                        <button
223
                          title=""
224
                          className="btn btn-tertiary"
225
                          onClick={() => handleButtonAction(authorizedLinks?.link_reject)}
226
                        >
227
                          Rechazar
228
                        </button>
229
                      }
230
                      {authorizedLinks?.link_leave &&
231
                        <button
232
                          data-link="{{>link_leave}}"
233
                          title=""
234
                          className="btn btn-tertiary"
235
                          onClick={() => handleButtonAction(authorizedLinks?.link_leave)}
236
                        >
237
                          Abandonar esta empresa
238
                        </button>
239
                      }
240
                      {authorizedLinks?.link_contact &&
241
                        <a
242
                          href={authorizedLinks?.link_contact}
243
                          className="btn btn-primary"
244
                        >
245
                          Mensaje
246
                        </a>
247
                      }
2442 stevensc 248
                    </div>
1 www 249
                  </div>
250
                </div>
3929 stevensc 251
              </div>
252
              <div className="d-none d-md-block">
2442 stevensc 253
                <CompanyFollowersHelper companyId={companyId} />
254
              </div>
3929 stevensc 255
            </div>
256
            <div className="main-ws-sec">
257
              <div className="user-tab-sec rewivew">
258
                {!initialLoading &&
259
                  <div className="row">
260
                    {isFollower &&
261
                      <div className="col text-left pl-0">
2442 stevensc 262
                        <button
263
                          className="btn btn-link p-0 text-decoration-none"
3929 stevensc 264
                          onClick={() => changeCurrentTab(TABS.FEEDS)}
2574 stevensc 265
                          style={{ padding: '0 !important' }}
2442 stevensc 266
                        >
3929 stevensc 267
                          <span className="p-0 default-link font-weight-bold text-dark">Ver Publicaciones</span>
2442 stevensc 268
                        </button>
269
                      </div>
3929 stevensc 270
                    }
271
                    <div className="col text-right pl-0">
272
                      <button
273
                        className="btn btn-link p-0 text-decoration-none"
274
                        onClick={() => changeCurrentTab(TABS.INFO)}
275
                        style={{ padding: '0 !important' }}
276
                      >
277
                        <span className="p-0 default-link font-weight-bold text-dark">Ver Información</span>
278
                      </button>
1 www 279
                    </div>
2442 stevensc 280
                  </div>
281
                }
282
              </div>
3929 stevensc 283
              {
284
                currentTab === TABS.FEEDS
285
                &&
286
                <div
287
                  className="product-feed-tab animated fadeIn"
288
                  id="feed-dd feed"
289
                  style={{ display: 'block' }}
290
                >
291
                  <div className="posts-section">
292
                    <FeedSection
293
                      routeTimeline={timeline}
294
                      image={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""}`}
295
                    />
2442 stevensc 296
                  </div>
3929 stevensc 297
                </div>
298
              }
299
              {
300
                currentTab === TABS.INFO
301
                &&
302
                < div
303
                  className="product-feed-tab animated fadeIn"
304
                  id="feed-dd info"
305
                  style={{ display: 'block' }}
306
                >
307
                  {
308
                    overview
309
                    &&
310
                    <div className="user-profile-extended-ov">
311
                      <h3>Visión general</h3>
312
                      <span>{parse(overview)}</span>
313
                    </div>
314
                  }
315
                  {
316
                    locations
317
                    &&
318
                    <div className="user-profile-extended-ov st2">
319
                      <h3>Ubicación</h3>
320
                      <span>
321
                        {locations.map(
322
                          ({ formatted_address, is_main }, index) => (
323
                            <React.Fragment key={index}>
324
                              {index >= 0 ? <hr /> : ""}
325
                              <p>
326
                                {`${formatted_address} ${is_main === "y" ? "(Principal)" : ""
327
                                  }`}
328
                              </p>
329
                            </React.Fragment>
330
                          )
331
                        )}
332
                      </span>
333
                    </div>
334
                  }
335
                  {
336
                    industry
337
                    &&
338
                    <div className="user-profile-ov">
339
                      <h3>Industria</h3>
340
                      <span>{industry}</span>
341
                    </div>
342
                  }
343
                  {
344
                    companySize
345
                    &&
346
                    <div className="user-profile-ov">
347
                      <h3>Tamaño de la empresa</h3>
348
                      <span>{companySize}</span>
349
                    </div>
350
                  }
351
                  {
352
                    foundationYear
353
                    &&
354
                    <div className="user-profile-ov">
355
                      <h3>Año de fundación</h3>
356
                      <span>{foundationYear}</span>
357
                    </div>
358
                  }
359
                  {
360
                    website
361
                    &&
362
                    <div className="user-profile-ov">
363
                      <h3>Página web</h3>
364
                      <span>{website}</span>
365
                    </div>
366
                  }
367
                </div>
368
              }
369
              {
370
                initialLoading
371
                &&
372
                <div
373
                  style={{
374
                    display: "flex",
375
                    justifyContent: "center",
376
                    alignItems: "center",
377
                  }}
378
                >
379
                  <Spinner />
380
                </div>
381
              }
382
            </div>
383
            <div className="right-sidebar">
384
              {loading &&
385
                <div className="spinner-container">
386
                  <Spinner />
387
                </div>
388
              }
389
              <div className="peopleYouMayKnow">
390
                <div className="sd-title d-flex align-items-center justify-content-between">
391
                  <h3>Empresas similares:</h3>
392
                  {suggestionCompanies.length >= 5 &&
393
                    <a href="#" onClick={(e) => {
394
                      e.preventDefault()
395
                      setLookMore(!lookMore)
396
                    }}>
397
                      {lookMore ? 'Ver menos' : 'Ver mas'}
398
                    </a>
399
                  }
400
                </div>
401
                <div className="suggest-list">
402
                  {suggestionCompanies.length
403
                    ? getData().map(element => {
404
                      return (
405
                        <div className='user' key={element.id}>
406
                          <div className="w-100 d-flex align-items-center" style={{ gap: '.5rem' }}>
407
                            <a href={element.profile} target="_blank" rel="noreferrer">
408
                              <img src={element.image} alt={`${element.name} profile image`} />
409
                            </a>
410
                            <h4>{element.name}</h4>
1771 steven 411
                          </div>
3929 stevensc 412
                          <div className="w-100 d-flex align-items-center justify-content-start" style={{ gap: '.5rem' }}>
413
                            <a
414
                              className="btn btn-primary"
415
                              href={element.profile}
416
                              target='_blank'
417
                              rel="noreferrer"
418
                              style={{ fontSize: '.9rem', borderRadius: '4px' }}
419
                            >
420
                              MÁS INF
421
                            </a>
422
                          </div>
423
                        </div>
424
                      )
425
                    })
426
                    : <div className="view-more">Sin empresas similares</div>
427
                  }
1 www 428
                </div>
429
              </div>
430
            </div>
431
          </div>
432
        </div>
2442 stevensc 433
      </main >
1105 stevensc 434
    </React.Fragment >
1 www 435
  );
436
};
437
 
438
const mapDispatchToProps = {
439
  addNotification: (notification) => addNotification(notification),
440
  setTimelineUrl: (url) => setTimelineUrl(url),
441
};
442
 
443
export default connect(null, mapDispatchToProps)(View);