Rev 1113 | Rev 1689 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useEffect, useRef } from "react";import { useState } from "react";import { connect } from "react-redux";import styled from "styled-components";import { axios } from "../../../utils";import CompanyFollowersHelper from "../../../shared/helpers/company-followers-helper/CompanyFollowers";import parse from "html-react-parser";import { addNotification } from "../../../redux/notification/notification.actions";import Spinner from "../../../shared/loading-spinner/Spinner";import { setTimelineUrl } from "../../../redux/feed/feed.actions";import FeedSection from "../../../dashboard/components/feed-section/FeedSection";const TABS = {FEEDS: "FEEDS",INFO: "INFO",};const View = (props) => {// backendVars destructuringconst {companyId,cover,image,totalFollowers,facebook,twitter,instagram,companyName,overview,locations,industry,companySize,foundationYear,website,timeline,} = props.backendVars;// redux destructuringconst { addNotification, setTimelineUrl } = props;// const [isFollower, setIsFollower] = useState(!!+follower);const [authorizedLinks, setAuthorizedLinks] = useState(null);const [loading, setLoading] = useState(false);const [followers, setFollowers] = useState(totalFollowers);const [initialLoading, setInitialLoading] = useState(true);const [isFollower, setIsFollower] = useState(false);const [currentTab, setCurrentTab] = useState(TABS.INFO);const [suggestionCompanies, setSuggestionCompanies] = useState([])const shouldSetInitialTab = useRef(true);useEffect(() => {setTimelineUrl(timeline);fetchAuthorizedLinks();shouldSetInitialTab.current = false;setInitialLoading(false);getSuggestionCompanies()}, []);const getSuggestionCompanies = async () => {try {setLoading(true);const response = await axios.get(`/helpers/company-suggestion/${companyId}`);if (response.data.success)setSuggestionCompanies(response.data.data)} catch (error) {console.log('>>: error > ', error)} finally {setLoading(false)}}useEffect(() => {isFollower? setCurrentTab(TABS.FEEDS): setCurrentTab(TABS.INFO)}, [isFollower]);const fetchAuthorizedLinks = async () => {setLoading(true);const response = await axios.get(`/company/view/${companyId}`);const resData = response.data;(resData);if (resData.success) {setAuthorizedLinks(resData.data);setFollowers(resData.data.total_followers);if (resData.data.link_unfollow) {setIsFollower(true);if (shouldSetInitialTab.current) setCurrentTab(TABS.FEEDS);} else {setIsFollower(false);}}return setLoading(false);};const handleButtonAction = async (link) => {setLoading(true);const response = await axios.post(link);const resData = response.data;if (resData.success) {addNotification({style: "success",msg: resData.data,});fetchAuthorizedLinks();} else {setLoading(false);addNotification({style: "danger",msg: "ha ocurrido un error",});}};const changeCurrentTab = (tab) => {('>>: tab> ', tab)setCurrentTab(tab)}return (<React.Fragment><section className="cover-sec"><imgid="user-cover-img"src={`/storage/type/company-cover/code/${companyId}/${cover ? `filename/${cover}` : ""}`}alt="cover-image"/></section><main><div className="main-section"><div className="container"><div className="main-section-data"><div className="row"><div className="col-lg-3"><div className="main-left-sidebar"><div className="user_profile"><div className="user-pro-img"><imgid="company-img"src={`/storage/type/company/code/${companyId}/${image ? `filename/${image}` : ""}`}alt="profile-image"/></div>{/* <!--user-pro-img end--> */}<div className="user_pro_status"><h1>{companyName}</h1><ul className="flw-status"><li><span style={{ fontSize: '1rem' }} >Seguidores</span><b style={{ fontSize: '1rem' }} id="total-followers">{followers}</b></li></ul></div>{/* <!--user_pro_status end--> */}<divclassName="row"style={{margin: '-1px'}}>{facebook && (<divclassName="col col-md col-sm"><i onClick={() => window.location.href = facebook} className="cursor-pointer fa fa-facebook-square" style={{ fontSize: '1.4rem' }} /></div>)}{twitter && (<divclassName="col col-md col-sm"><i onClick={() => window.location.href = twitter} className="cursor-pointer fa fa-twitter" style={{ fontSize: '1.4rem' }} /></div>)}{instagram && (<divclassName="col col-md col-sm"><i onClick={() => window.location.href = instagram} className="fa fa-instagram cursor-pointer" style={{ fontSize: '1.4rem' }} /></div>)}</div></div>{/* <!--user_profile end--> */}<CompanyFollowersHelper companyId={companyId} /></div>{/* <!--main-left-sidebar end--> */}</div><div className="col-lg-6"><div className="main-ws-sec"><div className="user-tab-sec rewivew">{!initialLoading&&<divclassName="row">{isFollower&&<divclassName="col text-right"><buttonclassName="btn btn-link"onClick={() => changeCurrentTab(TABS.FEEDS)}><img src="/images/ic1.png" alt="" /><span className="p-2 default-link ">Ver Publicaciones</span></button></div>}<divclassName="col text-left"><buttonclassName="btn btn-link"onClick={() => changeCurrentTab(TABS.INFO)}><img src="/images/ic2.png" alt="" /><span className="p-2 default-link">Ver Info</span></button></div></div>}{/* <!-- tab-feed end--> */}</div>{currentTab === TABS.FEEDS&&<divclassName="product-feed-tab animated fadeIn"id="feed-dd feed"style={{ display: 'block' }}><div className="posts-section"><FeedSection routeTimeline={timeline} /></div></div>}{currentTab === TABS.INFO&&< divclassName="product-feed-tab animated fadeIn"id="feed-dd info"style={{ display: 'block' }}>{overview&&<div className="user-profile-extended-ov"><h3>Visión general</h3><span>{parse(overview)}</span></div>}{locations&&<div className="user-profile-extended-ov st2"><h3>Ubicación</h3><span>{locations.map(({ formatted_address, is_main }, index) => (<React.Fragment key={index}>{index >= 0 ? <hr /> : ""}<p>{`${formatted_address} ${is_main === "y" ? "(Principal)" : ""}`}</p></React.Fragment>))}</span></div>}{industry&&<div className="user-profile-ov"><h3>Industria</h3><span>{industry}</span></div>}{companySize&&<div className="user-profile-ov"><h3>Tamaño de la empresa</h3><span>{companySize}</span></div>}{foundationYear&&<div className="user-profile-ov"><h3>Año de fundación</h3><span>{foundationYear}</span></div>}{website&&<div className="user-profile-ov"><h3>Página web</h3><span>{website}</span></div>}</div>}{initialLoading&&<divstyle={{display: "flex",justifyContent: "center",alignItems: "center",}}><Spinner /></div>}</div></div><div className="col-lg-3"><div className="right-sidebar">{/* <?php echo $this->companySuggestionHelper($company_id)?> */}<divclassName="message-btn"id="div-user-buttons"style={{ position: "relative" }}>{authorizedLinks?.link_unfollow && (<ahref="#"className="btn-remove-follower"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_unfollow);}}><i className="fa fa-user-times"></i> Dejar de seguir</a>)}{authorizedLinks?.link_follow && (<ahref="#"className="btn-add-follower"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_follow);}}><i className="fa fa-plus"></i> Seguir</a>)}{authorizedLinks?.link_request && (<ahref="#"className="btn-request"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_request);}}><i className="fa fa-user-plus"></i>Trabaja en esta empresa?</a>)}{authorizedLinks?.link_accept && (<ahref="#"className="btn-accept"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_accept);}}><i className="fa fa-check"></i> Aceptar</a>)}{authorizedLinks?.link_cancel && (<ahref="#"title=""className="btn-cancel"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_cancel);}}><i className="fa fa-user-times "></i> Cancelar</a>)}{authorizedLinks?.link_reject && (<ahref="#"title=""className="btn-reject"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_reject);}}><i className="fa fa-user-times "></i> Rechazar</a>)}{authorizedLinks?.link_leave && (<ahref="#"data-link="{{>link_leave}}"title=""className="btn-leave"onClick={(e) => {e.preventDefault();handleButtonAction(authorizedLinks?.link_leave);}}><i className="fa fa-user-times "></i>Abandonar esta empresa</a>)}{authorizedLinks?.link_contact && (<ahref={authorizedLinks?.link_contact}title=""className="btn-send-message"><i className="fa fa-envelope "></i> Mensaje</a>)}{loading && (<div className="spinner-container"><Spinner /></div>)}</div><divclassName="widget suggestions full-width d-none d-md-block d-lg-block"style={{height: "450px",overflowY: "auto",}}><div className="sd-title"><h3>Empresas similares</h3></div>{/* <!--sd-title end--> */}{suggestionCompanies.length ? (suggestionCompanies.map(element => {return (<div className="suggestion-usd" key={element.id}><imgstyle={{ width: "50px", height: "auto" }}src={element.image}alt=""/><divclassName="sgt-text"><a href={element.profile} target="_blank"><h4 className="text-dark">{element.name}</h4></a></div></div>)})) : (<div className="view-more">Sin empresas similares</div>)}</div></div>{/* <!--right-sidebar end--> */}</div></div></div>{/* <!-- main-section-data end--> */}</div></div></main></React.Fragment >);};// const mapStateToProps = (state) => ({// })const mapDispatchToProps = {addNotification: (notification) => addNotification(notification),setTimelineUrl: (url) => setTimelineUrl(url),};export default connect(null, mapDispatchToProps)(View);