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