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