formatting

This commit is contained in:
Eduardo Quiros 2022-09-01 10:12:22 -06:00
parent ca2015ee0b
commit 0321b6ad00
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
1 changed files with 150 additions and 132 deletions

View File

@ -41,7 +41,7 @@ const Communities = () => {
const [districtId, setDistrictId] = useState(null); const [districtId, setDistrictId] = useState(null);
const [codeHouses, setCodeHouses] = useState(''); const [codeHouses, setCodeHouses] = useState('');
const [submitted, setSubmitted] = useState(false); const [submitted, setSubmitted] = useState(false);
const [saveButtonLabel, setSaveButtonLabel] = useState('Registrar') const [saveButtonLabel, setSaveButtonLabel] = useState('Registrar');
const [selectedCommunities, setSelectedCommunities] = useState(null); const [selectedCommunities, setSelectedCommunities] = useState(null);
const [globalFilter, setGlobalFilter] = useState(null); const [globalFilter, setGlobalFilter] = useState(null);
const [deleteCommunityDialog, setDeleteCommunityDialog] = useState(false); const [deleteCommunityDialog, setDeleteCommunityDialog] = useState(false);
@ -50,15 +50,11 @@ const Communities = () => {
const toast = useRef(null); const toast = useRef(null);
const dt = useRef(null); const dt = useRef(null);
//para el perfil de la comunidad //para el perfil de la comunidad
const [tenants, setTenants] = useState([]); const [tenants, setTenants] = useState([]);
const [communityDialog, setCommunityDialog] = useState(false); const [communityDialog, setCommunityDialog] = useState(false);
const p = provincesList.map((item) => ({ const p = provincesList.map((item) => ({
label: item.name, label: item.name,
value: item.code, value: item.code,
@ -76,7 +72,6 @@ const Communities = () => {
parent: item.parentCode, parent: item.parentCode,
})); }));
async function getProvinces() { async function getProvinces() {
const response = await fetch('assets/demo/data/provincias.json', { const response = await fetch('assets/demo/data/provincias.json', {
method: 'GET', method: 'GET',
@ -119,7 +114,6 @@ const Communities = () => {
setDistrictsList(await districts); setDistrictsList(await districts);
} }
useEffect(() => { useEffect(() => {
fillProvinces(); fillProvinces();
}, []); }, []);
@ -132,7 +126,6 @@ const Communities = () => {
fillDistricts(); fillDistricts();
}, [cantonId]); }, [cantonId]);
const handleProvinces = (event) => { const handleProvinces = (event) => {
const getprovinciaId = event.target.value; const getprovinciaId = event.target.value;
setProvinciaId(getprovinciaId); setProvinciaId(getprovinciaId);
@ -162,9 +155,7 @@ const Communities = () => {
let pList = await getProvinces(); let pList = await getProvinces();
let cList = await getCantons(); let cList = await getCantons();
let dList = await getDistricts(); let dList = await getDistricts();
let data = await resJson.message.filter( let data = await resJson.message.filter((val) => val.status != -1);
(val) => val.status != -1,
)
await data.map((item) => { await data.map((item) => {
if (item.status == '1') { if (item.status == '1') {
item.status_text = 'Activo'; item.status_text = 'Activo';
@ -188,21 +179,20 @@ const Communities = () => {
}, []); }, []);
async function tenantsList(id) { async function tenantsList(id) {
await fetch(`http://localhost:4000/user/findTenants/${id}`, { method: 'GET' }) await fetch(`http://localhost:4000/user/findTenants/${id}`, {
method: 'GET',
})
.then((response) => response.json()) .then((response) => response.json())
.then(data => data.message) .then((data) => data.message)
.then(data => { .then((data) => {
data = data.filter( data = data.filter((val) => val.status != -1);
(val) => val.status != -1, setTenants(data);
)
setTenants(data)
}); });
} }
useEffect(() => { useEffect(() => {
tenantsList(community._id); tenantsList(community._id);
}, []) }, []);
const saveCommunity = () => { const saveCommunity = () => {
if ( if (
@ -272,14 +262,12 @@ const Communities = () => {
} }
}; };
function findNameTenant(tenant_id) { function findNameTenant(tenant_id) {
let name = ''; let name = '';
if (tenant_id == '') { if (tenant_id == '') {
name = 'Sin inquilino'; name = 'Sin inquilino';
} else { } else {
let tenant = tenants.find(t => t._id == tenant_id) let tenant = tenants.find((t) => t._id == tenant_id);
name = tenant['name'] + ' ' + tenant['last_name']; name = tenant['name'] + ' ' + tenant['last_name'];
} }
return name; return name;
@ -340,7 +328,6 @@ const Communities = () => {
if (community.status == '1') { if (community.status == '1') {
community.status = '0'; community.status = '0';
community.status_text = 'Inactivo'; community.status_text = 'Inactivo';
} else if (community.status == '0') { } else if (community.status == '0') {
community.status = '1'; community.status = '1';
community.status_text = 'Activo'; community.status_text = 'Activo';
@ -354,69 +341,66 @@ const Communities = () => {
method: 'POST', method: 'POST',
body: JSON.stringify(data), body: JSON.stringify(data),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
} },
}) })
.then( .then(function(response) {
function(response) { if (response.status != 201)
if (response.status != 201) console.log('Ocurrió un error con el servicio: ' + response.status);
console.log('Ocurrió un error con el servicio: ' + response.status); else return response.json();
else })
return response.json(); .then(function(response) {
} setEditCommunityDialog(false);
) toast.current.show({
.then( severity: 'success',
function(response) { summary: 'Éxito',
setEditCommunityDialog(false); detail: 'Comunidad de Viviendas Actualizada',
toast.current.show({ life: 3000,
severity: 'success', });
summary: 'Éxito', })
detail: 'Comunidad de Viviendas Actualizada', .catch((err) => console.log('Ocurrió un error con el fetch', err));
life: 3000, };
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
const deleteCommunity = () => { const deleteCommunity = () => {
fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
cache: 'no-cache', cache: 'no-cache',
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
} },
}) })
.then( .then(function(response) {
function(response) { if (response.status != 201)
if (response.status != 201) console.log('Ocurrió un error con el servicio: ' + response.status);
console.log('Ocurrió un error con el servicio: ' + response.status); else return response.json();
else })
return response.json(); .then(function(response) {
} let _community = communitiesList.filter(
) (val) => val._id !== community._id,
.then( );
function(response) { setCommunitiesList(_community);
setDeleteCommunityDialog(false);
let _community = communitiesList.filter(val => val._id !== community._id); setCommunity(emptyCommunity);
setCommunitiesList(_community); toast.current.show({
setDeleteCommunityDialog(false); severity: 'success',
setCommunity(emptyCommunity); summary: 'Exito',
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); detail: 'Comunidad de Viviendas Eliminada',
} life: 3000,
) });
.catch( })
err => { .catch((err) => {
console.log('Ocurrió un error con el fetch', err) console.log('Ocurrió un error con el fetch', err);
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); toast.current.show({
} severity: 'danger',
); summary: 'Error',
let _communities = communitiesList.filter((val) => val._id !== community._id); detail: 'Comunidad de Viviendas no se pudo eliminar',
_communities = _communities.filter( life: 3000,
(val) => val.status != -1, });
) });
let _communities = communitiesList.filter(
(val) => val._id !== community._id,
);
_communities = _communities.filter((val) => val.status != -1);
setCommunitiesList(_communities); setCommunitiesList(_communities);
setDeleteCommunityDialog(false); setDeleteCommunityDialog(false);
setCommunity(emptyCommunity); setCommunity(emptyCommunity);
@ -441,9 +425,7 @@ const Communities = () => {
} }
}) })
})*/ })*/
_communities = _communities.filter( _communities = _communities.filter((val) => val.status != -1);
(val) => val.status != -1,
)
setCommunitiesList(_communities); setCommunitiesList(_communities);
setDeleteCommunitiesDialog(false); setDeleteCommunitiesDialog(false);
setSelectedCommunities(null); setSelectedCommunities(null);
@ -462,15 +444,23 @@ const Communities = () => {
setProvinciaId(community.provincia); setProvinciaId(community.provincia);
setCantonId(community.canton); setCantonId(community.canton);
setDistrictId(community.district); setDistrictId(community.district);
};
const cancelEdit = () => {
setCommunity(emptyCommunity);
setCantonId('');
setHousesList([]);
setProvinciaId('');
setDistrictId('');
setSaveButtonLabel('Registrar');
} }
const actionsCommunity = (rowData) => { const actionsCommunity = (rowData) => {
let icono = ''; let icono = '';
if (rowData.status == '0') { if (rowData.status == '0') {
icono = "pi pi-eye"; icono = 'pi pi-eye';
} else if (rowData.status == '1') { } else if (rowData.status == '1') {
icono = "pi pi-eye-slash"; icono = 'pi pi-eye-slash';
} }
return ( return (
@ -550,7 +540,6 @@ const Communities = () => {
className="p-button-text" className="p-button-text"
onClick={hideCommunityDialog} onClick={hideCommunityDialog}
/> />
</> </>
); );
@ -604,8 +593,6 @@ const Communities = () => {
</> </>
); );
const headerName = ( const headerName = (
<> <>
<p> <p>
@ -668,8 +655,8 @@ const Communities = () => {
<> <>
<p> <p>
{' '} {' '}
<FontAwesomeIcon icon={faHashtag} style={{ color: '#D7A86E' }} />{' '} <FontAwesomeIcon icon={faHashtag} style={{ color: '#D7A86E' }} /> Número
Número de viviendas de viviendas
</p> </p>
</> </>
); );
@ -686,12 +673,16 @@ const Communities = () => {
const headerStatus = ( const headerStatus = (
<> <>
<p> {' '} <p>
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#D7A86E" }} />{' '} {' '}
<FontAwesomeIcon
icon={faCircleQuestion}
style={{ color: '#D7A86E' }}
/>{' '}
Estado Estado
</p> </p>
</> </>
) );
//ver perfil comunidad //ver perfil comunidad
const headerTenant = ( const headerTenant = (
@ -701,16 +692,13 @@ const Communities = () => {
<FontAwesomeIcon icon={faUserAlt} style={{ color: '#C08135' }} />{' '} <FontAwesomeIcon icon={faUserAlt} style={{ color: '#C08135' }} />{' '}
Inquilinos Inquilinos
</p> </p>
</> </>
); );
const statusBodyTemplate = (rowData) => { const statusBodyTemplate = (rowData) => {
return ( return (
<> <>
<span <span className={`status status-${rowData.status}`}>
className={`status status-${rowData.status}`}
>
{rowData.status_text} {rowData.status_text}
</span> </span>
</> </>
@ -724,11 +712,7 @@ const Communities = () => {
name = findNameTenant(tenants.tenant_id); name = findNameTenant(tenants.tenant_id);
} }
return ( return <>{name}</>;
<>
{name}
</>
)
}; };
return ( return (
@ -810,15 +794,19 @@ const Communities = () => {
sortable sortable
header={headerStatus} header={headerStatus}
body={statusBodyTemplate} body={statusBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> style={{
</Column> flexGrow: 1,
flexBasis: '160px',
minWidth: '160px',
wordBreak: 'break-word',
}}
></Column>
<Column <Column
body={actionsCommunity} body={actionsCommunity}
style={{ flexGrow: 1, flexBasis: '100px' }} style={{ flexGrow: 2, flexBasis: '100px', flexDirection: 'row' }}
></Column> ></Column>
</DataTable> </DataTable>
<Dialog <Dialog
visible={communityDialog} visible={communityDialog}
style={{ width: '650px' }} style={{ width: '650px' }}
@ -826,12 +814,16 @@ const Communities = () => {
modal modal
className="p-fluid" className="p-fluid"
footer={communityDialogFooter} footer={communityDialogFooter}
onHide={hideCommunityDialog}> onHide={hideCommunityDialog}
<div className='container text-center'> >
<div className='row my-4'> <div className="container text-center">
<div className="row my-4">
<div className=" col-12 md:col-12"> <div className=" col-12 md:col-12">
<p>Nombre</p> <p>Nombre</p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}> <div
className="p-0 col-2 md:col-2"
style={{ margin: '0 auto' }}
>
<div className="p-inputgroup align-items-center justify-content-evenly"> <div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-home icon-khaki"></i> <i className="pi pi-home icon-khaki"></i>
<p>{community.name}</p> <p>{community.name}</p>
@ -839,30 +831,34 @@ const Communities = () => {
</div> </div>
</div> </div>
</div> </div>
<div className='row my-5'> <div className="row my-5">
<div className=" col-6 md:col-6"> <div className=" col-6 md:col-6">
<p>Administrador</p> <p>Administrador</p>
<div className="p-0 col-6 md:col-6" style={{ margin: '0 auto' }}> <div
className="p-0 col-6 md:col-6"
style={{ margin: '0 auto' }}
>
<div className="p-inputgroup align-items-center justify-content-evenly"> <div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-user icon-khaki"></i> <i className="pi pi-user icon-khaki"></i>
<p>{community.name_admin}</p> <p>{community.name_admin}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-6 md:col-6"> <div className=" col-6 md:col-6">
<p>Teléfono Administrativo</p> <p>Teléfono Administrativo</p>
<div className="p-0 col-6 md:col-6" style={{ margin: '0 auto' }}> <div
className="p-0 col-6 md:col-6"
style={{ margin: '0 auto' }}
>
<div className="p-inputgroup align-items-center justify-content-evenly"> <div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-phone icon-khaki"></i> <i className="pi pi-phone icon-khaki"></i>
<p>{community.phone}</p> <p>{community.phone}</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div className='row my-5'> <div className="row my-5">
<div className=" col-4 col-md-4 md:col-4"> <div className=" col-4 col-md-4 md:col-4">
<p>Provincia</p> <p>Provincia</p>
<div className="p-0 col-10 md:col-10"> <div className="p-0 col-10 md:col-10">
@ -870,7 +866,6 @@ const Communities = () => {
<i className="pi pi-map-marker icon-khaki"></i> <i className="pi pi-map-marker icon-khaki"></i>
<p>{community.province}</p> <p>{community.province}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-4 md:col-4"> <div className=" col-4 md:col-4">
@ -880,7 +875,6 @@ const Communities = () => {
<i className="pi pi-map-marker icon-khaki"></i> <i className="pi pi-map-marker icon-khaki"></i>
<p>{community.canton}</p> <p>{community.canton}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-4 md:col-4"> <div className=" col-4 md:col-4">
@ -890,14 +884,16 @@ const Communities = () => {
<i className="pi pi-map-marker icon-khaki"></i> <i className="pi pi-map-marker icon-khaki"></i>
<p>{community.district}</p> <p>{community.district}</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div className='row my-5'> <div className="row my-5">
<div className=" col-12 md:col-12"> <div className=" col-12 md:col-12">
<p>Número de Viviendas</p> <p>Número de Viviendas</p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}> <div
className="p-0 col-2 md:col-2"
style={{ margin: '0 auto' }}
>
<div className="p-inputgroup justify-content-evenly"> <div className="p-inputgroup justify-content-evenly">
<i className="pi pi-hashtag icon-khaki"></i> <i className="pi pi-hashtag icon-khaki"></i>
<p>{community.num_houses}</p> <p>{community.num_houses}</p>
@ -905,12 +901,16 @@ const Communities = () => {
</div> </div>
</div> </div>
</div> </div>
<div className='row my-5'> <div className="row my-5">
<div className=" col-12 md:col-12"> <div className=" col-12 md:col-12">
<p>
{' '}
<p> <i className="pi pi-home icon-khaki"></i> Viviendas</p> <i className="pi pi-home icon-khaki"></i> Viviendas
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}> </p>
<div
className="p-0 col-12 md:col-12"
style={{ margin: '0 auto' }}
>
<div className="p-inputgroup justify-content-evenly"> <div className="p-inputgroup justify-content-evenly">
<DataTable <DataTable
value={community.houses} value={community.houses}
@ -928,13 +928,21 @@ const Communities = () => {
<Column <Column
field="number_house" field="number_house"
header={headerNumberHouses} header={headerNumberHouses}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }} style={{
flexGrow: 1,
flexBasis: '160px',
minWidth: '160px',
}}
></Column> ></Column>
<Column <Column
field="tenants" field="tenants"
header={headerTenant} header={headerTenant}
body={tenantsBodyTemplate} body={tenantsBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }} style={{
flexGrow: 1,
flexBasis: '160px',
minWidth: '160px',
}}
></Column> ></Column>
</DataTable> </DataTable>
</div> </div>
@ -942,7 +950,6 @@ const Communities = () => {
</div> </div>
</div> </div>
</div> </div>
</Dialog> </Dialog>
<Dialog <Dialog
@ -960,7 +967,8 @@ const Communities = () => {
/> />
{community && ( {community && (
<span> <span>
¿Estás seguro que desea cambiar estado a <b>{community.name}</b>? ¿Estás seguro que desea cambiar estado a{' '}
<b>{community.name}</b>?
</span> </span>
)} )}
</div> </div>
@ -1183,12 +1191,22 @@ const Communities = () => {
)} )}
</div> </div>
</div> </div>
<div className="col-12 md:col-12 py-2"> <div style={{
display: "flex",
justifyContent: "center",
gap: "10px",
width: "100%"
}} className="col-12 md:col-12 py-2">
<Button <Button
label={saveButtonLabel} label={saveButtonLabel}
icon="pi pi-check" icon="pi pi-check"
onClick={saveCommunity} onClick={saveCommunity}
></Button> />
{saveButtonLabel === 'Actualizar' && (
<Button
label="Cancelar"
onClick={cancelEdit}
className="p-button-danger" />)}
</div> </div>
</div> </div>
</div> </div>