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,8 +48,38 @@ 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() {
await fetch('http://localhost:4000/user/findUserById/' + cookies.id, { method: 'GET' }) await fetch('http://localhost:4000/user/findUserById/' + cookies.id, { method: 'GET' })
.then((response) => response.json()) .then((response) => response.json())
@ -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='col-6'>
<div className='row my-4'> {community && (
<div className=" col-12 md:col-12"> <div className="card">
<h3>Información Básica</h3> <div className='container text-center'>
</div>
<div className=" col-6 md:col-6"> <div className='row my-5'>
<i className="pi pi-home icon-khaki"></i> <div className=" col-12 md:col-12">
<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="p-inputgroup align-items-center justify-content-evenly">
<p>{community.phone}</p>
</div>
</div> <h3> Viviendas</h3>
</div> <div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
</div> <div className="p-inputgroup justify-content-evenly">
<div className='row my-5'> <DataTable
<div className=" col-12 md:col-12"> value={community.houses}
<h3>Ubicación</h3> paginator
</div> rows={5}
<div className=" col-4 col-md-4 md:col-4"> scrollable
<i className="pi pi-map-marker icon-khaki"></i> scrollHeight="200px"
scrollDirection="both"
<p><strong>Provincia</strong></p> rowsPerPageOptions={[5, 10, 25]}
<div className="p-0 col-10 md:col-10"> className="datatable-responsive mt-3"
<div className="p-inputgroup align-items-center justify-content-evenly"> paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
<p>{community.province}</p> currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} viviendas"
</div> globalFilter={globalFilter}
>
</div> <Column
</div> field="number_house"
<div className=" col-4 md:col-4"> header={headerNumberHouses}
<i className="pi pi-map-marker icon-khaki"></i> style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
></Column>
<p><strong>Cantón</strong></p> <Column
<div className="p-0 col-10 md:col-10"> field="tenants"
<div className="p-inputgroup align-items-center justify-content-evenly"> header={headerTenant}
<p>{community.canton}</p> body={tenantsBodyTemplate}
</div> style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
></Column>
</div> </DataTable>
</div> </div>
<div className=" col-4 md:col-4"> </div>
<i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Distrito</strong></p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{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 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> </>
) )