obtencion de datos correctos

This commit is contained in:
Mariela 2022-08-31 01:09:58 -06:00
parent 6668d70cfb
commit 11ac9b0232
1 changed files with 196 additions and 122 deletions

View File

@ -48,6 +48,36 @@ const PerfilAdminComunidad = () => {
const [globalFilter, setGlobalFilter] = useState(null); const [globalFilter, setGlobalFilter] = useState(null);
//para el perfil de la comunidad //para el perfil de la comunidad
const [tenants, setTenants] = useState([]); const [tenants, setTenants] = useState([]);
const [commonAreaList, setCommonAreaList] = useState([]);
const [provincesList, setProvincesList] = useState([]);
const [cantonsList, setCantonsList] = useState([]);
const [districtsList, setDistrictsList] = useState([]);
async function getProvinces() {
const response = await fetch('assets/demo/data/provincias.json', {
method: 'GET',
});
return await response.json();
}
async function getCantons() {
const response = await fetch('assets/demo/data/cantones.json', {
method: 'GET',
});
return await response.json();
}
async function getDistricts() {
const response = await fetch('assets/demo/data/distritos.json', {
method: 'GET',
});
return await response.json();
}
async function getAdmin() { async function getAdmin() {
@ -71,11 +101,16 @@ const PerfilAdminComunidad = () => {
}, []) }, [])
async function getCommunity() { async function getCommunity() {
let pList = await getProvinces();
fetch(`http://localhost:4000/community/findCommunityName/${cookies.community_id}`, { method: 'GET' }) let cList = await getCantons();
let dList = await getDistricts();
await fetch(`http://localhost:4000/community/findCommunityName/${cookies.community_id}`, { method: 'GET' })
.then((response2) => response2.json()) .then((response2) => response2.json())
.then(data => data.message) .then(data => data.message)
.then(data => { .then(data => {
data.province = pList.find((p) => p.code === data.province).name;
data.canton = cList.find((p) => p.code === data.canton).name;
data.district = dList.find((p) => p.code === data.district).name;
setCommunity(data) setCommunity(data)
}) })
} }
@ -100,6 +135,8 @@ const PerfilAdminComunidad = () => {
tenantsList(community._id); tenantsList(community._id);
}, []) }, [])
function findNameTenant(tenant_id) { function findNameTenant(tenant_id) {
let name = ''; let name = '';
if (tenant_id == '') { if (tenant_id == '') {
@ -147,138 +184,175 @@ const PerfilAdminComunidad = () => {
} }
return ( return (
<div className="grid"> <>
<div className="card"> <div className="grid justify-content-center">
<div className='container text-center'>
<div className="p-fluid formgrid grid"> <div className="col-6" >
<div className="field col-12 md:col-12"> <div className="card">
<p id='name'>{admin.name}</p> <div className='container text-center'>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Información Básica</h3>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-home icon-khaki"></i>
<p><strong>Nombre Completo</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.name + ' ' + admin.last_name}</p>
</div>
</div>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-id-card icon-khaki"></i>
<p><strong>Identificación</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.dni}</p>
</div>
</div>
</div>
</div>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Contacto</h3>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-at icon-khaki"></i>
<p><strong>Correo Electrónico</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.email}</p>
</div>
</div>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-phone icon-khaki"></i>
<p><strong>Número de teléfono</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.phone}</p>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
<div className='col-6'>
{community && (
<div className="card">
<div className='container text-center'>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Comunidad Asignada</h3>
</div>
<div className=" col-4 md:col-4">
<i className="pi pi-home icon-khaki"></i>
<p><strong>Nombre</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.name}</p>
</div>
</div>
</div>
<div className="col-4 md:col-4">
<i className="pi pi-phone icon-khaki"></i>
<p><strong>Teléfono Administrativo</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.phone}</p>
</div>
</div>
</div>
<div className=" col-4 col-md-4 md:col-4">
<i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Ubicación</strong></p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.province}, {community.canton}, {community.district}</p>
</div>
</div>
</div>
</div>
<div className='row my-5'>
<div className=" col-12 md:col-12">
<h3>Viviendas de la Comunidad</h3>
</div>
<div className=" col-12 md:col-12">
<i className="pi pi-hashtag icon-khaki"></i>
<p><strong>Cantidad de Viviendas</strong></p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{community.num_houses}</p>
</div>
</div>
</div>
</div>
</div>
</div>
)}
</div>
</div> </div>
{community && ( <div className='grid justify-content-center'>
<div className="card">
<div className='container text-center'>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Información Básica</h3>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-home icon-khaki"></i>
<p><strong>Nombre</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.name}</p>
</div>
</div>
</div>
<div className="col-6 md:col-6">
<i className="pi pi-phone icon-khaki"></i>
<p><strong>Teléfono Administrativo</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}> <div className='col-6'>
<div className="p-inputgroup align-items-center justify-content-evenly"> {community && (
<p>{community.phone}</p> <div className="card">
</div> <div className='container text-center'>
</div> <div className='row my-5'>
</div> <div className=" col-12 md:col-12">
</div>
<div className='row my-5'>
<div className=" col-12 md:col-12">
<h3>Ubicación</h3>
</div>
<div className=" col-4 col-md-4 md:col-4">
<i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Provincia</strong></p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.province}</p>
</div>
</div> <h3> Viviendas</h3>
</div> <div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className=" col-4 md:col-4"> <div className="p-inputgroup justify-content-evenly">
<i className="pi pi-map-marker icon-khaki"></i> <DataTable
value={community.houses}
<p><strong>Cantón</strong></p> paginator
<div className="p-0 col-10 md:col-10"> rows={5}
<div className="p-inputgroup align-items-center justify-content-evenly"> scrollable
<p>{community.canton}</p> scrollHeight="200px"
</div> scrollDirection="both"
rowsPerPageOptions={[5, 10, 25]}
</div> className="datatable-responsive mt-3"
</div> paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
<div className=" col-4 md:col-4"> currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} viviendas"
<i className="pi pi-map-marker icon-khaki"></i> globalFilter={globalFilter}
>
<p><strong>Distrito</strong></p> <Column
<div className="p-0 col-10 md:col-10"> field="number_house"
<div className="p-inputgroup align-items-center justify-content-evenly"> header={headerNumberHouses}
<p>{community.district}</p> style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
</div> ></Column>
<Column
</div> field="tenants"
</div> header={headerTenant}
</div> body={tenantsBodyTemplate}
<div className='row my-5'> style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
<div className=" col-12 md:col-12"> ></Column>
<h3>Viviendas de la Comunidad</h3> </DataTable>
</div> </div>
<div className=" col-12 md:col-12"> </div>
<i className="pi pi-hashtag icon-khaki"></i>
<p><strong>Cantidad de Viviendas</strong></p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{community.num_houses}</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div className='row my-5'> )}
<div className=" col-12 md:col-12">
<p> <i className="pi pi-home icon-khaki"></i> Viviendas</p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<DataTable
value={community.houses}
paginator
rows={5}
scrollable
scrollHeight="200px"
scrollDirection="both"
rowsPerPageOptions={[5, 10, 25]}
className="datatable-responsive mt-3"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} viviendas"
globalFilter={globalFilter}
>
<Column
field="number_house"
header={headerNumberHouses}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
></Column>
<Column
field="tenants"
header={headerTenant}
body={tenantsBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
></Column>
</DataTable>
</div>
</div>
</div>
</div>
</div>
</div> </div>
)} </div>
</div> </>
) )