Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3931 | Rev 5406 | 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 (
3930 stevensc 127
    <>
1 www 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>
3930 stevensc 136
      <main className="main-section">
137
        <div className="main-section-data">
138
          <div className="main-left-sidebar">
139
            <div className="user_profile">
140
              <div className="user-pro-img">
141
                <img
142
                  src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""}`}
143
                  alt="profile-image"
144
                />
145
              </div>
146
              <div className="user_pro_status horizontal-list">
147
                <h1>{companyName}</h1>
148
                <div className="row px-5" style={{ marginTop: '10px' }}>
149
                  {facebook &&
150
                    <i
151
                      onClick={() => window.location.href = facebook}
152
                      className="cursor-pointer fa fa-facebook"
153
                      style={{ fontSize: '1.4rem' }}
154
                    />
155
                  }
156
                  {twitter &&
157
                    <i
158
                      onClick={() => window.location.href = twitter}
159
                      className="cursor-pointer fa fa-twitter"
160
                      style={{ fontSize: '1.4rem' }}
161
                    />
162
                  }
163
                  {instagram &&
164
                    <i
165
                      onClick={() => window.location.href = instagram}
166
                      className="fa fa-instagram cursor-pointer"
167
                      style={{ fontSize: '1.4rem' }}
168
                    />
169
                  }
3929 stevensc 170
                </div>
3930 stevensc 171
                <div className="container horizontal-list">
172
                  <div className="row ">
173
                    <div className="members_count">
174
                      <b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b>
175
                      <p style={{ fontSize: '1rem' }} className="ellipsis">Seguidores</p>
176
                    </div>
177
                    {authorizedLinks?.link_unfollow &&
178
                      <button
179
                        className="btn btn-secondary"
180
                        onClick={() => handleButtonAction(authorizedLinks?.link_unfollow)}
181
                      >
182
                        Dejar de seguir
183
                      </button>
3929 stevensc 184
                    }
3930 stevensc 185
                    {authorizedLinks?.link_follow &&
186
                      <button
187
                        className="btn btn-secondary"
188
                        onClick={() => handleButtonAction(authorizedLinks?.link_follow)}
189
                      >
190
                        Seguir
191
                      </button>
3929 stevensc 192
                    }
3930 stevensc 193
                    {
194
                      (authorizedLinks?.link_request && authorizedLinks?.link_unfollow)
195
                      &&
196
                      <button
197
                        className="btn btn-tertiary"
198
                        onClick={() => handleButtonAction(authorizedLinks?.link_request)}
199
                      >
200
                        ¿Trabaja en esta empresa?
201
                      </button>
3929 stevensc 202
                    }
3930 stevensc 203
                    {authorizedLinks?.link_accept &&
204
                      <button
205
                        className="btn btn-tertiary"
206
                        onClick={() => handleButtonAction(authorizedLinks?.link_accept)}
207
                      >
208
                        Aceptar
209
                      </button>
210
                    }
211
                    {authorizedLinks?.link_cancel &&
212
                      <button
213
                        title=""
214
                        className="btn btn-tertiary"
215
                        onClick={() => handleButtonAction(authorizedLinks?.link_cancel)}
216
                      >
217
                        Cancelar
218
                      </button>
219
                    }
220
                    {authorizedLinks?.link_reject &&
221
                      <button
222
                        title=""
223
                        className="btn btn-tertiary"
224
                        onClick={() => handleButtonAction(authorizedLinks?.link_reject)}
225
                      >
226
                        Rechazar
227
                      </button>
228
                    }
229
                    {authorizedLinks?.link_leave &&
230
                      <button
231
                        data-link="{{>link_leave}}"
232
                        title=""
233
                        className="btn btn-tertiary"
234
                        onClick={() => handleButtonAction(authorizedLinks?.link_leave)}
235
                      >
236
                        Abandonar esta empresa
237
                      </button>
238
                    }
239
                    {authorizedLinks?.link_contact &&
240
                      <a
241
                        href={authorizedLinks?.link_contact}
242
                        className="btn btn-primary"
243
                      >
244
                        Mensaje
245
                      </a>
246
                    }
2442 stevensc 247
                  </div>
1 www 248
                </div>
3929 stevensc 249
              </div>
250
            </div>
3930 stevensc 251
            <div className="d-none d-md-block">
252
              <CompanyFollowersHelper companyId={companyId} />
253
            </div>
254
          </div>
255
          <div className="main-ws-sec">
256
            <div className="user-tab-sec rewivew">
257
              {!initialLoading &&
258
                <div className="row">
259
                  {isFollower &&
260
                    <div className="col text-left pl-0">
3929 stevensc 261
                      <button
262
                        className="btn btn-link p-0 text-decoration-none"
3930 stevensc 263
                        onClick={() => changeCurrentTab(TABS.FEEDS)}
3929 stevensc 264
                        style={{ padding: '0 !important' }}
265
                      >
3930 stevensc 266
                        <span className="p-0 default-link font-weight-bold text-dark">Ver Publicaciones</span>
3929 stevensc 267
                      </button>
1 www 268
                    </div>
3930 stevensc 269
                  }
3931 stevensc 270
                  <div className="col text-right pr-0">
3930 stevensc 271
                    <button
272
                      className="btn btn-link p-0 text-decoration-none"
273
                      onClick={() => changeCurrentTab(TABS.INFO)}
274
                      style={{ padding: '0 !important' }}
275
                    >
276
                      <span className="p-0 default-link font-weight-bold text-dark">Ver Información</span>
277
                    </button>
2442 stevensc 278
                  </div>
3929 stevensc 279
                </div>
280
              }
281
            </div>
3930 stevensc 282
            {
283
              currentTab === TABS.FEEDS
284
              &&
285
              <div
286
                className="product-feed-tab animated fadeIn"
287
                id="feed-dd feed"
288
                style={{ display: 'block' }}
289
              >
290
                <div className="posts-section">
291
                  <FeedSection
292
                    routeTimeline={timeline}
293
                    image={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""}`}
294
                  />
3929 stevensc 295
                </div>
3930 stevensc 296
              </div>
297
            }
298
            {
299
              currentTab === TABS.INFO
300
              &&
301
              < div
302
                className="product-feed-tab animated fadeIn"
303
                id="feed-dd info"
304
                style={{ display: 'block' }}
305
              >
306
                {
307
                  overview
308
                  &&
309
                  <div className="user-profile-extended-ov">
310
                    <h3>Visión general</h3>
311
                    <span>{parse(overview)}</span>
312
                  </div>
313
                }
314
                {
315
                  locations
316
                  &&
317
                  <div className="user-profile-extended-ov st2">
318
                    <h3>Ubicación</h3>
319
                    <span>
320
                      {locations.map(
321
                        ({ formatted_address, is_main }, index) => (
322
                          <React.Fragment key={index}>
323
                            {index >= 0 ? <hr /> : ""}
324
                            <p>
325
                              {`${formatted_address} ${is_main === "y" ? "(Principal)" : ""
326
                                }`}
327
                            </p>
328
                          </React.Fragment>
329
                        )
330
                      )}
331
                    </span>
332
                  </div>
333
                }
334
                {
335
                  industry
336
                  &&
337
                  <div className="user-profile-ov">
338
                    <h3>Industria</h3>
339
                    <span>{industry}</span>
340
                  </div>
341
                }
342
                {
343
                  companySize
344
                  &&
345
                  <div className="user-profile-ov">
346
                    <h3>Tamaño de la empresa</h3>
347
                    <span>{companySize}</span>
348
                  </div>
349
                }
350
                {
351
                  foundationYear
352
                  &&
353
                  <div className="user-profile-ov">
354
                    <h3>Año de fundación</h3>
355
                    <span>{foundationYear}</span>
356
                  </div>
357
                }
358
                {
359
                  website
360
                  &&
361
                  <div className="user-profile-ov">
362
                    <h3>Página web</h3>
363
                    <span>{website}</span>
364
                  </div>
365
                }
366
              </div>
367
            }
368
            {
369
              initialLoading
370
              &&
371
              <div
372
                style={{
373
                  display: "flex",
374
                  justifyContent: "center",
375
                  alignItems: "center",
376
                }}
377
              >
378
                <Spinner />
379
              </div>
380
            }
381
          </div>
382
          <div className="right-sidebar">
383
            {loading &&
384
              <div className="spinner-container">
385
                <Spinner />
386
              </div>
387
            }
388
            <div className="peopleYouMayKnow">
389
              <div className="sd-title d-flex align-items-center justify-content-between">
390
                <h3>Empresas similares:</h3>
391
                {suggestionCompanies.length >= 5 &&
392
                  <a href="#" onClick={(e) => {
393
                    e.preventDefault()
394
                    setLookMore(!lookMore)
395
                  }}>
396
                    {lookMore ? 'Ver menos' : 'Ver mas'}
397
                  </a>
398
                }
399
              </div>
400
              <div className="suggest-list">
401
                {suggestionCompanies.length
402
                  ? getData().map(element => {
403
                    return (
404
                      <div className='user' key={element.id}>
405
                        <div className="w-100 d-flex align-items-center" style={{ gap: '.5rem' }}>
406
                          <a href={element.profile} target="_blank" rel="noreferrer">
407
                            <img src={element.image} alt={`${element.name} profile image`} />
408
                          </a>
409
                          <h4>{element.name}</h4>
3929 stevensc 410
                        </div>
4234 stevensc 411
                        <a
412
                          className="btn btn-primary"
413
                          href={element.profile}
414
                          target='_blank'
415
                          rel="noreferrer"
416
                          style={{ fontSize: '.9rem', borderRadius: '4px' }}
417
                        >
418
                          MÁS INF
419
                        </a>
3930 stevensc 420
                      </div>
421
                    )
422
                  })
423
                  : <div className="view-more">Sin empresas similares</div>
424
                }
1 www 425
              </div>
426
            </div>
427
          </div>
428
        </div>
2442 stevensc 429
      </main >
3930 stevensc 430
    </>
1 www 431
  );
432
};
433
 
434
const mapDispatchToProps = {
435
  addNotification: (notification) => addNotification(notification),
436
  setTimelineUrl: (url) => setTimelineUrl(url),
437
};
438
 
439
export default connect(null, mapDispatchToProps)(View);