Proyectos de Subversion LeadersLinked - SPA

Rev

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

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