Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3585 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useEffect, useState } from 'react';
2
import { useDispatch, useSelector } from 'react-redux';
3
import { useParams } from 'react-router-dom';
4
 
5
import { fetchFeeds, setCurrentPage, setTimelineUrl } from '../../redux/feed/feed.actions';
6
import { getBackendVars } from '../../services/backendVars';
7
 
8
import AppGrid from '@app/components/UI/layout/AppGrid';
9
import AboutCompany from '@app/components/company/AboutCompany';
10
import CompanyActions from '@app/components/company/CompanyActions';
11
import CompanyFollowers from '@app/components/company/CompanyFollowers';
12
import FeedList from '@app/components/dashboard/linkedin/feed-list/FeedList';
13
import GroupInfo from '@app/components/widgets/linkedin/group-widget';
14
import Pagination from '@components/common/Pagination';
15
 
16
const LinkedInCompany = () => {
17
  const [backendVars, setBackendVars] = useState(null);
18
  const [actionsUrls, setActionsUrls] = useState({});
19
  const [isFollower, setIsFollower] = useState(false);
20
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(({ feed }) => feed);
21
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
22
  const { uuid } = useParams();
23
  const dispatch = useDispatch();
24
 
25
  const getCompanyVars = () => {
26
    getBackendVars(`/company/view/${uuid}`).then((vars) => {
27
      const actions = {};
28
 
29
      Object.entries(vars).forEach(([key, value]) => {
30
        if (!key.includes('link')) return;
31
        actions[key] = value;
32
      });
33
 
34
      setActionsUrls(actions);
35
      dispatch(setTimelineUrl(vars.link_timeline));
36
      setIsFollower(!!vars.link_unfollow);
37
      setBackendVars(vars);
38
    });
39
  };
40
 
41
  const onChangePageHandler = (currentPage) => {
42
    dispatch(setCurrentPage(currentPage));
43
    window.scrollTo(0, 0);
44
  };
45
 
46
  useEffect(() => {
47
    dispatch(fetchFeeds(timelineUrl, currentPage));
48
  }, [timelineUrl, currentPage]);
49
 
50
  useEffect(() => {
51
    getCompanyVars();
52
  }, [uuid]);
53
 
54
  return (
55
    <AppGrid
56
      renderSidebar={() => (
57
        <GroupInfo
58
          cover={backendVars?.cover}
59
          image={backendVars?.image}
60
          name={backendVars?.company_name}
61
          overview={backendVars?.overview}
62
          id={backendVars?.company_uuid}
63
          totalMembers={backendVars?.total_followers}
64
          groupType={backendVars?.company_size}
65
          accessibility={backendVars?.industry}
66
        />
67
      )}
68
      renderMain={() => (
69
        <>
70
          <CompanyActions
71
            name={backendVars?.company_name}
72
            image={backendVars?.image}
73
            companyId={backendVars?.company_uuid}
74
            cover={backendVars?.cover}
75
            overview={backendVars?.overview}
76
            refetch={getCompanyVars}
77
            actionLinks={actionsUrls}
78
          />
79
          {!isFollower ? <AboutCompany {...backendVars} /> : null}
80
          {isFollower && !loading ? <FeedList feeds={allFeeds} /> : null}
81
          <Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
82
        </>
83
      )}
84
      renderAside={() => (
85
        <>
86
          <CompanyFollowers companyId={uuid} />
87
          <AboutCompany {...backendVars} />
88
        </>
89
      )}
90
    />
91
  );
92
};
93
 
94
export default LinkedInCompany;