3719 |
stevensc |
1 |
import React, { useEffect } from 'react';
|
|
|
2 |
import { useDispatch, useSelector } from 'react-redux';
|
|
|
3 |
import { useParams } from 'react-router-dom';
|
|
|
4 |
|
|
|
5 |
import { useFetch } from '@hooks';
|
|
|
6 |
import { fetchFeeds, setCurrentPage, setTimelineUrl } from '@store/feed/feed.actions';
|
|
|
7 |
|
|
|
8 |
import AppGrid from '@components/UI/layout/AppGrid';
|
|
|
9 |
import Spinner from '@components/UI/Spinner';
|
|
|
10 |
import Pagination from '@components/common/Pagination';
|
|
|
11 |
import FeedList from '@components/dashboard/linkedin/feed-list/FeedList';
|
|
|
12 |
import CompanyFollowers from '@components/company/company-followers';
|
|
|
13 |
import CompanyWidget from '@components/company/company-widget';
|
|
|
14 |
import AboutCompany from '@components/company/about-company';
|
|
|
15 |
import CompanyInfo from '@components/company/company-info';
|
|
|
16 |
|
|
|
17 |
export default function LinkedInCompany() {
|
|
|
18 |
const { uuid } = useParams();
|
|
|
19 |
const dispatch = useDispatch();
|
|
|
20 |
const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(({ feed }) => feed);
|
|
|
21 |
|
|
|
22 |
const { data, isLoading, refetch } = useFetch(`/company/view/${uuid}`);
|
|
|
23 |
|
|
|
24 |
const isFollower = !!data.link_unfollow;
|
|
|
25 |
const allFeeds = feeds.allIds.map((id) => feeds.byId[id]);
|
|
|
26 |
|
|
|
27 |
const onChangePageHandler = (currentPage) => {
|
|
|
28 |
dispatch(setCurrentPage(currentPage));
|
|
|
29 |
window.scrollTo(0, 0);
|
|
|
30 |
};
|
|
|
31 |
|
|
|
32 |
useEffect(() => {
|
|
|
33 |
dispatch(fetchFeeds(timelineUrl, currentPage));
|
|
|
34 |
}, [timelineUrl, currentPage]);
|
|
|
35 |
|
|
|
36 |
useEffect(() => {
|
|
|
37 |
dispatch(setTimelineUrl(data.link_timeline));
|
|
|
38 |
}, [data]);
|
|
|
39 |
|
|
|
40 |
if (isLoading) {
|
|
|
41 |
return <Spinner />;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
return (
|
|
|
45 |
<AppGrid
|
|
|
46 |
renderSidebar={() => <CompanyInfo company={data} />}
|
|
|
47 |
renderMain={() => (
|
|
|
48 |
<>
|
|
|
49 |
<CompanyWidget company={data} refetch={refetch} />
|
|
|
50 |
{loading && <Spinner />}
|
|
|
51 |
{!isFollower && <AboutCompany company={data} />}
|
|
|
52 |
{isFollower && !loading && (
|
|
|
53 |
<>
|
|
|
54 |
<FeedList feeds={allFeeds} />
|
|
|
55 |
<Pagination pages={pages} page={currentPage} onChange={onChangePageHandler} />
|
|
|
56 |
</>
|
|
|
57 |
)}
|
|
|
58 |
</>
|
|
|
59 |
)}
|
|
|
60 |
renderAside={() => (
|
|
|
61 |
<>
|
|
|
62 |
<CompanyFollowers companyId={uuid} />
|
|
|
63 |
<AboutCompany company={data} />
|
|
|
64 |
</>
|
|
|
65 |
)}
|
|
|
66 |
/>
|
|
|
67 |
);
|
|
|
68 |
}
|