import React, { useEffect, useState, useRef } from 'react'; import { useCookies } from "react-cookie"; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faHashtag } from '@fortawesome/free-solid-svg-icons'; import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; const PerfilAdminComunidad = () => { let emptyAdminCommunity = { _id: null, dni: '', name: '', last_name: '', email: '', phone: '', password: '', confirmPassword: '', community_id: '', community_name: '', user_type: '2', date_entry: new Date(), status: '1', status_text: '', }; let emptyCommunity = { _id: null, name: '', province: '', canton: '', district: '', phone: '', num_houses: 0, status: '1', status_text: '', date_entry: new Date(), houses: [], }; const [admin, setAdmin] = useState(emptyAdminCommunity); const [community, setCommunity] = useState(emptyCommunity); const [cookies, setCookie] = useCookies(); const [globalFilter, setGlobalFilter] = useState(null); //para el perfil de la comunidad const [tenants, setTenants] = useState([]); async function getAdmin() { await fetch('http://localhost:4000/user/findUserById/' + cookies.id, { method: 'GET' }) .then((response) => response.json()) .then(data => { let item = data.message; setAdmin(item); if (item.community_id || item.community_id != '') { getCommunity() } else { item.community_name = "Sin Comunidad Asignada"; } }) } useEffect(() => { getAdmin(); }, []) async function getCommunity() { fetch(`http://localhost:4000/community/findCommunityName/${cookies.community_id}`, { method: 'GET' }) .then((response2) => response2.json()) .then(data => data.message) .then(data => { setCommunity(data) }) } useEffect(() => { getCommunity(); }, []) async function tenantsList(id) { await fetch(`http://localhost:4000/user/findTenants/${id}`, { method: 'GET' }) .then((response) => response.json()) .then(data => data.message) .then(data => { data = data.filter( (val) => val.status != -1, ) setTenants(data) }); } useEffect(() => { tenantsList(community._id); }, []) function findNameTenant(tenant_id) { let name = ''; if (tenant_id == '') { name = 'Sin inquilino'; } else { let tenant = tenants.find(t => t._id == tenant_id) name = tenant['name'] + ' ' + tenant['last_name']; } return name; } const headerNumberHouses = ( <>
{' '}
{' '}
{admin.name}
Nombre
{community.name}
Teléfono Administrativo
{community.phone}
Provincia
{community.province}
Cantón
{community.canton}
Distrito
{community.district}
Cantidad de Viviendas
{community.num_houses}
Viviendas