Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6863 | 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 } from 'react-redux'
import { getBackendVars } from '../../services/backendVars'
import { setTimelineUrl } from '../../redux/feed/feed.actions'
import { addNotification } from '../../redux/notification/notification.actions'

import Members from '../../components/group/Members'
import FeedList from '../../components/feed/linkedin/FeedList'
import FeedShare from '../../components/feed/linkedin/FeedShare'
import InfoWidget from '../../components/widgets/linkedin/InfoWidget'
import AboutGroup from '../../components/group/AboutGroup'
import GroupActions from '../../components/group/GroupActions'

const View = () => {
  const [backendVars, setBackendVars] = useState({})
  const [actionsUrls, setActionsUrls] = useState({})
  const { uuid } = useParams()
  const dispatch = useDispatch()

  useEffect(() => {
    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))
        setBackendVars(vars)
      })
      .catch((err) => {
        dispatch(addNotification({ style: 'danger', msg: err }))
        console.log(`Error: ${err}`)
        throw new Error(err)
      })
  }, [])

  return (
    <main className="w-100">
      <div className="container p-0 app__body layout__content">
        <div className="d-flex flex-column">
          <InfoWidget
            cover={backendVars.cover}
            image={backendVars.image}
            name={backendVars.name}
            overview={backendVars.overview}
            totalMembers={backendVars.total_members}
            id={backendVars.group_uuid}
            groupType={backendVars.group_type}
            accessibility={backendVars.accessibility}
          />
        </div>
        <div className="d-flex flex-column" style={{ gap: '.5rem' }}>
          <GroupActions {...backendVars} actionLinks={actionsUrls} />

          {backendVars.withoutFeeds ? (
            <AboutGroup {...backendVars} />
          ) : (
            <>
              <FeedShare image={backendVars.image} postUrl="/feed/add" />
              <FeedList feed={backendVars.feed} image={backendVars.image} />
            </>
          )}
        </div>
        <div className="d-flex flex-column" style={{ gap: '.5rem' }}>
          <Members groupId={backendVars.groupId} />
          {!backendVars.withoutFeeds && <AboutGroup {...backendVars} />}
        </div>
      </div>
    </main>
  )
}

export default View