diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index 025ae00a..087302c4 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -33,7 +33,7 @@ const Communities = () => { const [cantonId, setCantonId] = useState(null); const [districtsList, setDistrictsList] = useState([]); const [districtId, setDistrictId] = useState(null); - const [codeHouses, setCodeHouses] = useState(null); + const [codeHouses, setCodeHouses] = useState(''); const [submitted, setSubmitted] = useState(false); const toast = useRef(null); const dt = useRef(null); @@ -59,7 +59,7 @@ const Communities = () => { })) - + useEffect(() => { @@ -138,11 +138,11 @@ const Communities = () => { let pList = await getProvinces(); let cList = await getCantons(); let dList = await getDistricts(); - await resJson.message.map((item) => { + await resJson.message.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 - if(!item.id_admin){ + if (!item.id_admin) { item.name_admin = "Sin Administrador" } }) @@ -151,15 +151,12 @@ const Communities = () => { useEffect(() => { getCommunites(); - }, []) const saveCommunity = () => { - setSubmitted(true); - - if (community.name.trim()) { + if (community.name.trim() ) { let _communities = [...communitiesList]; let _community = { ...community }; _community.province = provinciaId; @@ -168,12 +165,12 @@ const Communities = () => { - for (let i = 0; i < _community.num_houses; i++){ + for (let i = 0; i < _community.num_houses; i++) { _community.houses.push({ - number_house: codeHouses + (i+1), + number_house: codeHouses + (i + 1), }) } - // console.log(houses) + // console.log(houses) fetch('http://localhost:4000/community/createCommunity', { cache: 'no-cache', method: 'POST', @@ -182,40 +179,44 @@ const Communities = () => { '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(() => { - - _community.province = provincesList.find(p => p.code === _community.province).name - _community.canton = cantonsList.find(p => p.code === _community.canton).name - _community.district = districtsList.find(p => p.code === _community.district).name + .then( + function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } + ) + .then(() => { - _communities.push(_community); - toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Comunidad de vivienda Creada', life: 3000 }); + _community.province = provincesList.find(p => p.code === _community.province).name + _community.canton = cantonsList.find(p => p.code === _community.canton).name + _community.district = districtsList.find(p => p.code === _community.district).name - setCommunitiesList(_communities); + _communities.push(_community); + toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Comunidad de vivienda Creada', life: 3000 }); + + setCommunitiesList(_communities); - setProvinciaId(''); - setCantonId(''); - setDistrictId(''); - setCodeHouses(''); + setProvinciaId(''); + setCantonId(''); + setDistrictId(''); + setCodeHouses(''); - setCommunity(emptyCommunity); - }) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); + setCommunity(emptyCommunity); + + }) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + + + } else { + setSubmitted(true); - } - + } const onInputChange = (e, name) => { @@ -245,20 +246,20 @@ const Communities = () => {