diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 879c2cba..f693cb8d 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -59,9 +59,18 @@ const Inquilinos = () => { .then((response) => response.json()) .then(data => data.message) .then(data => { - + data = data.filter( + (val) => val.status != -1, + ) data.map((item) => { - if(item.number_house ==""){ + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } + + + if (item.number_house == "") { item.number_house = "Sin vivienda asignada"; } }) @@ -193,6 +202,50 @@ const Inquilinos = () => { }); }; + const cambiarStatusUser = () => { + if (tenant.status == '1') { + tenant.status = '0'; + tenant.status_text = 'Inactivo'; + + } else if (tenant.status == '0') { + tenant.status = '1'; + tenant.status_text = 'Activo'; + } + var data = { + id: tenant._id, + status: tenant.status, + }; + fetch('http://localhost:4000/user/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) { + setChangeStatusTenantDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Inquilino Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } const hideDeleteTenantDialog = () => { setDeleteTenantDialog(false); @@ -211,11 +264,37 @@ const Inquilinos = () => { setDeleteTenantsDialog(true); }; + const hideChangeStatusTenantDialog = () => { + setChangeStatusTenantDialog(false); + }; + + const confirmChangeStatusTenant = (tenant) => { + setTenant(tenant); + setChangeStatusTenantDialog(true); + }; const actionsTenant = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Inquilino" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Inquilino" + + } return (