Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 856 | Rev 1800 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { useDispatch, useSelector } from 'react-redux'

import {
  fetchFeeds,
  setCurrentPage,
  setTimelineUrl
} from '../../redux/feed/feed.actions'
import { getBackendVars } from '../../services/backendVars'

import PaginationComponent from '@app/components/UI/PaginationComponent'
import AboutCompany from '../../components/company/AboutCompany'
import CompanyActions from '../../components/company/CompanyActions'
import CompanyFollowers from '../../components/company/CompanyFollowers'
import FeedList from '../../components/dashboard/linkedin/feed-list/FeedList'
import GroupInfo from '../../components/widgets/linkedin/InfoWidget'

import './styles/linkedin.scss'

const LinkedInCompany = () => {
  const [backendVars, setBackendVars] = useState(null)
  const [actionsUrls, setActionsUrls] = useState(null)
  const [isFollower, setIsFollower] = useState(false)
  const { feeds, timelineUrl, currentPage, loading, pages } = useSelector(
    ({ feed }) => feed
  )
  const allFeeds = feeds.allIds.map((id) => feeds.byId[id])
  const { uuid } = useParams()
  const dispatch = useDispatch()

  const getCompanyVars = () => {
    getBackendVars(`/company/view/${uuid}`).then((vars) => {
      const actions = {}

      Object.entries(vars).forEach(([key, value]) => {
        if (!key.includes('link')) return
        actions[key] = value
      })

      setActionsUrls(actions)
      dispatch(setTimelineUrl(vars.link_timeline))
      setIsFollower(!!vars.link_unfollow)
      setBackendVars(vars)
    })
  }

  const onChangePageHandler = (currentPage) => {
    dispatch(setCurrentPage(currentPage))
    window.scrollTo(0, 0)
  }

  useEffect(() => {
    dispatch(fetchFeeds(timelineUrl, currentPage))
  }, [timelineUrl, currentPage])

  useEffect(() => {
    getCompanyVars()
  }, [])

  return (
    <main className='w-100'>
      <div className='container p-0 app__body layout__content'>
        <div className='d-flex flex-column'>
          <GroupInfo
            cover={backendVars?.cover}
            image={backendVars?.image}
            name={backendVars?.company_name}
            overview={backendVars?.overview}
            id={backendVars?.company_uuid}
            totalMembers={backendVars?.total_followers}
            groupType={backendVars?.company_size}
            accessibility={backendVars?.industry}
          />
        </div>

        <div className='d-flex flex-column' style={{ gap: '.5rem' }}>
          <CompanyActions
            name={backendVars?.company_name}
            image={backendVars?.image}
            companyId={backendVars?.company_uuid}
            cover={backendVars?.cover}
            overview={backendVars?.overview}
            refetch={getCompanyVars}
            actionLinks={actionsUrls}
          />
          {!isFollower ? (
            <AboutCompany {...backendVars} />
          ) : (
            <>
              <FeedList
                feeds={allFeeds}
                loading={loading}
                image={`/storage/type/company/code/${backendVars?.companyId}/${
                  backendVars?.image ? `filename/${backendVars?.image}` : ''
                }`}
              />
              <PaginationComponent
                pages={pages}
                currentActivePage={currentPage}
                onChangePage={onChangePageHandler}
                isRow
              />
            </>
          )}
        </div>

        <div className='d-flex flex-column' style={{ gap: '.5rem' }}>
          <CompanyFollowers companyId={uuid} />
          <AboutCompany {...backendVars} />
        </div>
      </div>
    </main>
  )
}

export default LinkedInCompany