Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5416 stevensc 1
/* eslint-disable react/prop-types */
5418 stevensc 2
import React, { useEffect, useState } from 'react'
5416 stevensc 3
import FacebookIcon from '@mui/icons-material/Facebook'
4
import TwitterIcon from '@mui/icons-material/Twitter'
5
import InstagramIcon from '@mui/icons-material/Instagram'
6
import { axios } from '../../../utils'
7
import { addNotification } from '../../../redux/notification/notification.actions'
8
 
9
const CompanyInfo = ({
10
  companyId,
11
  image,
12
  companyName,
13
  facebook,
14
  twitter,
15
  instagram,
16
  totalFollowers,
17
  markFollower
18
}) => {
5425 stevensc 19
  const [authLinks, setAuthLinks] = useState([])
5416 stevensc 20
  const [followers, setFollowers] = useState(totalFollowers)
21
 
22
  const authClasses = {
23
    link_unfollow: 'secondary',
24
    link_follow: 'secondary',
25
    link_request: 'tertiary',
26
    link_accept: 'tertiary',
27
    link_cancel: 'tertiary',
28
    link_reject: 'tertiary',
29
    link_leave: 'tertiary',
30
    link_contact: 'primary'
31
  }
32
  const authLabels = {
33
    link_unfollow: 'Dejar de seguir',
34
    link_follow: 'Seguir',
35
    link_request: '¿Trabaja en esta empresa?',
36
    link_accept: 'Aceptar',
37
    link_cancel: 'Cancelar',
38
    link_reject: 'Rechazar',
39
    link_leave: 'Abandonar esta empresa',
40
    link_contact: 'Mensaje'
41
  }
42
 
43
  const fetchAuthLinks = async () => {
44
    const response = await axios.get(`/company/view/${companyId}`)
45
    const { success, data } = response.data
5417 stevensc 46
 
5416 stevensc 47
    if (success) {
5422 stevensc 48
      const filterResponse = Object.entries(data).filter((key) => key[0].includes('link'))
5426 stevensc 49
      const responseAuthLinks = filterResponse.map((key) => Object.fromEntries(key))
5422 stevensc 50
 
5426 stevensc 51
      console.log(filterResponse)
52
      console.log(responseAuthLinks)
53
 
5422 stevensc 54
      setAuthLinks(responseAuthLinks)
5416 stevensc 55
      setFollowers(data.total_followers)
5417 stevensc 56
 
5416 stevensc 57
      if (data.link_unfollow) {
58
        markFollower(true)
59
      } else {
60
        markFollower(false)
61
      }
62
    }
63
  }
64
 
65
  const handleButtonAction = async (link) => {
66
    const response = await axios.post(link)
67
    const { success, data } = response.data
5417 stevensc 68
 
5416 stevensc 69
    if (success) {
70
      addNotification({ style: 'success', msg: data })
71
      fetchAuthLinks()
72
    } else {
73
      addNotification({ style: 'danger', msg: 'ha ocurrido un error' })
74
    }
75
  }
76
 
77
  const openRrss = (rrss) => {
78
    window.open(rrss, '_blank')
79
  }
80
 
5418 stevensc 81
  useEffect(() => fetchAuthLinks(), [])
82
 
5416 stevensc 83
  return (
84
        <div className="user_profile">
85
            <div className="user-pro-img">
86
                <img
87
                    src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ''}`}
88
                    alt="profile-image"
89
                />
90
            </div>
91
            <div className="user_pro_status horizontal-list">
92
                <h1>{companyName}</h1>
93
                <div className="row px-5" style={{ marginTop: '10px' }}>
94
                    {facebook && <FacebookIcon onClick={() => openRrss(facebook)} className="cursor-pointer" />}
95
                    {twitter && <TwitterIcon onClick={() => openRrss(twitter)} className="cursor-pointer" />}
96
                    {instagram && <InstagramIcon onClick={() => openRrss(instagram)} className="cursor-pointer" />}
97
                </div>
5423 stevensc 98
                <div className="members_count">
99
                    <b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b>
100
                    <p style={{ fontSize: '1rem' }} className="ellipsis">Seguidores</p>
101
                </div>
102
                <div className="row ">
5424 stevensc 103
                    {authLinks.map(([key, value]) => (
104
                        <button
105
                            key={key}
106
                            className={`btn btn-${authClasses[key]}`}
107
                            onClick={() => handleButtonAction(value)}
108
                        >
109
                            {authLabels[key]}
110
                        </button>
111
                    ))}
5416 stevensc 112
                </div>
113
            </div>
114
        </div>
115
  )
116
}
117
 
118
export default CompanyInfo