Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5426 | Rev 5428 | 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'))
5427 stevensc 49
      console.log(filterResponse)
5422 stevensc 50
 
5427 stevensc 51
      const responseAuthLinks = filterResponse.map((key) => Object.fromEntries([key]))
52
 
5426 stevensc 53
      console.log(responseAuthLinks)
54
 
5422 stevensc 55
      setAuthLinks(responseAuthLinks)
5416 stevensc 56
      setFollowers(data.total_followers)
5417 stevensc 57
 
5416 stevensc 58
      if (data.link_unfollow) {
59
        markFollower(true)
60
      } else {
61
        markFollower(false)
62
      }
63
    }
64
  }
65
 
66
  const handleButtonAction = async (link) => {
67
    const response = await axios.post(link)
68
    const { success, data } = response.data
5417 stevensc 69
 
5416 stevensc 70
    if (success) {
71
      addNotification({ style: 'success', msg: data })
72
      fetchAuthLinks()
73
    } else {
74
      addNotification({ style: 'danger', msg: 'ha ocurrido un error' })
75
    }
76
  }
77
 
78
  const openRrss = (rrss) => {
79
    window.open(rrss, '_blank')
80
  }
81
 
5418 stevensc 82
  useEffect(() => fetchAuthLinks(), [])
83
 
5416 stevensc 84
  return (
85
        <div className="user_profile">
86
            <div className="user-pro-img">
87
                <img
88
                    src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ''}`}
89
                    alt="profile-image"
90
                />
91
            </div>
92
            <div className="user_pro_status horizontal-list">
93
                <h1>{companyName}</h1>
94
                <div className="row px-5" style={{ marginTop: '10px' }}>
95
                    {facebook && <FacebookIcon onClick={() => openRrss(facebook)} className="cursor-pointer" />}
96
                    {twitter && <TwitterIcon onClick={() => openRrss(twitter)} className="cursor-pointer" />}
97
                    {instagram && <InstagramIcon onClick={() => openRrss(instagram)} className="cursor-pointer" />}
98
                </div>
5423 stevensc 99
                <div className="members_count">
100
                    <b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b>
101
                    <p style={{ fontSize: '1rem' }} className="ellipsis">Seguidores</p>
102
                </div>
103
                <div className="row ">
5424 stevensc 104
                    {authLinks.map(([key, value]) => (
105
                        <button
106
                            key={key}
107
                            className={`btn btn-${authClasses[key]}`}
108
                            onClick={() => handleButtonAction(value)}
109
                        >
110
                            {authLabels[key]}
111
                        </button>
112
                    ))}
5416 stevensc 113
                </div>
114
            </div>
115
        </div>
116
  )
117
}
118
 
119
export default CompanyInfo