diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index e3b1c4ce..f80f1157 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -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,69 +341,66 @@ const Communities = () => { method: 'POST', body: JSON.stringify(data), headers: { - 'Content-Type': 'application/json' - } + '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) - ); - } + .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)); + }; 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) { - 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); - 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 }); - } - ); - let _communities = communitiesList.filter((val) => val._id !== community._id); - _communities = _communities.filter( - (val) => val.status != -1, - ) + .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, + ); + 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, + }); + }); + let _communities = communitiesList.filter( + (val) => val._id !== community._id, + ); + _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 = ( <>
@@ -668,8 +655,8 @@ const Communities = () => { <>
{' '}
-
{' '}
-
+ {' '}
+