fixes functions de cambiar estado

Se deja una sola función y un solo botón para cambiar el estado... también se realizar un filtro para que no se muestren las comunidades marcadas como eliminadas
This commit is contained in:
Mariela 2022-08-02 21:00:38 -06:00
parent 112813c216
commit 6d8fcd264e
1 changed files with 52 additions and 102 deletions

View File

@ -14,6 +14,7 @@ import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
import { faEllipsis } from '@fortawesome/free-solid-svg-icons';
import { faHashtag } from '@fortawesome/free-solid-svg-icons';
import { icon } from '@fortawesome/fontawesome-svg-core';
const Communities = () => {
let emptyCommunity = {
@ -161,7 +162,11 @@ const Communities = () => {
let pList = await getProvinces();
let cList = await getCantons();
let dList = await getDistricts();
await resJson.message.map((item) => {
let data = await resJson.message.filter(
(val) => val.status != -1,
)
await data.map((item) => {
item.province = pList.find((p) => p.code === item.province).name;
item.canton = cList.find((p) => p.code === item.canton).name;
item.district = dList.find((p) => p.code === item.district).name;
@ -169,7 +174,7 @@ const Communities = () => {
item.name_admin = 'Sin Administrador';
}
});
setCommunitiesList(await resJson.message);
setCommunitiesList(await data);
}
useEffect(() => {
@ -181,6 +186,9 @@ const Communities = () => {
.then((response) => response.json())
.then(data => data.message)
.then(data => {
data = data.filter(
(val) => val.status != -1,
)
setTenants(data)
});
}
@ -265,7 +273,7 @@ const Communities = () => {
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'];
}
console.log(name);
@ -323,50 +331,17 @@ const Communities = () => {
setCommunity(community);
setEditCommunityDialog(true);
};
//desactivar o activar una comunidad
const cambiarDesactivarEstadoCommunity = () => {
var data = {
id: community._id,
status: "0",
};
console.log(data);
fetch('http://localhost:4000/community/changeStatus', {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(
function (response) {
if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}
)
.then(
function (response) {
setEditCommunityDialog(false);
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Comunidad de Viviendas Actualizada',
life: 3000,
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
//desactivar o activar una comunidad
const cambiarActivarEstadoCommunity = () => {
const cambiarEstadoCommunity = () => {
if (community.status == '1') {
community.status = '0';
} else if (community.status == '0') {
community.status = '1';
}
var data = {
id: community._id,
status: "1",
status: community.status,
};
console.log(data);
fetch('http://localhost:4000/community/changeStatus', {
@ -435,8 +410,11 @@ const Communities = () => {
}
);
*/
let _community = communitiesList.filter((val) => val._id !== community._id);
setCommunitiesList(_community);
let _communities = communitiesList.filter((val) => val._id !== community._id);
_communities = _communities.filter(
(val) => val.status != -1,
)
setCommunitiesList(_communities);
setDeleteCommunityDialog(false);
setCommunity(emptyCommunity);
toast.current.show({
@ -460,6 +438,9 @@ const Communities = () => {
}
})
})*/
_communities = _communities.filter(
(val) => val.status != -1,
)
setCommunitiesList(_communities);
setDeleteCommunitiesDialog(false);
setSelectedCommunities(null);
@ -472,23 +453,26 @@ const Communities = () => {
};
const actionsCommunity = (rowData) => {
let icono = '';
if (rowData.status == '0') {
icono = "pi pi-eye";
} else if (rowData.status == '1') {
icono = "pi pi-eye-slash";
}
return (
<div className="actions">
<Button
icon="pi pi-eye"
className="p-button-rounded p-button-success mt-2 mx-2"
onClick={() => confirmEditCommunity(rowData)}
/>
<Button
icon="pi pi-eye-slash"
className="p-button-rounded p-button-danger mt-2 mx-2"
onClick={() => confirmEditCommunity(rowData)}
/>
<Button
icon="pi pi-exclamation-circle"
className="p-button-rounded p-button-primary mt-2 mx-2"
className="p-button-rounded p-button-info mt-2 mx-2"
onClick={() => infoCommunity(rowData)}
/>
<Button
icon={`${icono}`}
className={`p-button-rounded p-button-warning mt-2 mx-2`}
onClick={() => confirmEditCommunity(rowData)}
/>
<Button
icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2 mx-2"
@ -528,7 +512,7 @@ const Communities = () => {
const header = (
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
<h5 className="m-0">Comunidade de Viviendas</h5>
<h5 className="m-0">Comunidades de Viviendas</h5>
<span className="block mt-2 md:mt-0 p-input-icon-left">
<i className="pi pi-search" />
<InputText
@ -585,7 +569,7 @@ const Communities = () => {
/>
</>
);
const editDesactivarCommunityDialogFooter = (
const editEstadoCommunityDialogFooter = (
<>
<Button
label="No"
@ -597,27 +581,12 @@ const Communities = () => {
label="Yes"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarDesactivarEstadoCommunity}
onClick={cambiarEstadoCommunity}
/>
</>
);
const editActivarCommunityDialogFooter = (
<>
<Button
label="No"
icon="pi pi-times"
className="p-button-text"
onClick={hideEditCommunityDialog}
/>
<Button
label="Yes"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarActivarEstadoCommunity}
/>
</>
);
const headerName = (
<>
@ -797,7 +766,7 @@ const Communities = () => {
></Column>
<Column
body={actionsCommunity}
style={{ flexGrow: 1, flexBasis: '180px' }}
style={{ flexGrow: 1, flexBasis: '100px' }}
></Column>
</DataTable>
@ -927,32 +896,13 @@ const Communities = () => {
</div>
</Dialog>
<Dialog
visible={editCommunityDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={editActivarCommunityDialogFooter}
onHide={hideEditCommunityDialog}
>
<div className="flex align-items-center justify-content-center">
<i
className="pi pi-exclamation-triangle mr-3"
style={{ fontSize: '2rem' }}
/>
{community && (
<span>
¿Estás seguro que desea cambiar estado a <b>{community.name}</b>?
</span>
)}
</div>
</Dialog>
<Dialog
visible={editCommunityDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={editDesactivarCommunityDialogFooter}
footer={editEstadoCommunityDialogFooter}
onHide={hideEditCommunityDialog}
>
<div className="flex align-items-center justify-content-center">