From 20f6aeb376279b4aaf2f47afb62daf2a0294b9ad Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Sun, 21 Aug 2022 03:50:27 -0600 Subject: [PATCH] =?UTF-8?q?cambiar=20selecci=C3=B3n=20de=20comunidad=20por?= =?UTF-8?q?=20selecci=C3=B3n=20de=20casas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no tiene sentido que se pueda seleccionar una comunidad y luego seleccionar una casa, dado que el administrador administra una única comunidad, y esta se puede inferir del administrador mismo. Además, el inquilino se asigna a una casa, no necesariamente a la comunidad. --- web-ui/web-react/src/components/Inquilinos.js | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index c8794b57..7d94ac6d 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -41,15 +41,14 @@ const Inquilinos = () => { const [globalFilter, setGlobalFilter] = useState(null) const [deleteTenantDialog, setDeleteTenantDialog] = useState(false) const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false) - const [communitiesList, setCommunitiesList] = useState([]) - const [communityId, setCommunityId] = useState(null) + const [community, setCommunity] = useState([]) + const [houseNumber, setHouseNumber] = useState([]) + const [housesList, setHousesList] = useState([]) const [submitted, setSubmitted] = useState(false) const toast = useRef(null) const dt = useRef(null) - - const [cookies, setCookie] = useCookies() - const [changeStatusTenantDialog, setChangeStatusTenantDialog] = - useState(false) + const [cookies] = useCookies() + const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false) async function tenantsList() { await fetch( @@ -75,15 +74,21 @@ const Inquilinos = () => { }) } - async function getCommunites() { + async function getCommunity() { let response = await fetch( - 'http://localhost:4000/community/allCommunities', + `http://localhost:4000/community/findCommunityName/${cookies.community_id}`, { method: 'GET' }, ) - let resList = await response.json() - let list = await resList.message - list = await list.filter((val) => val.status !== -1) - setCommunitiesList(await list) + const responseJson = await response.json() + const result = await responseJson.message + setCommunity(await result) + const houses = await result.houses.filter((house) => + house.state === "desocupada" + ) + setHousesList(houses.map((house) => ({ + label: house.number_house, value: house.number_house + })) + ) } useEffect(() => { @@ -91,20 +96,15 @@ const Inquilinos = () => { }, [tenantsList]) useEffect(() => { - getCommunites() + getCommunity() }, []) - const cList = communitiesList.map((item) => ({ - label: item.name, - value: item._id, - })) - const saveTenant = () => { - if (tenant.email && tenant.community_id && tenant.dni - && tenant.name && tenant.last_name && tenant.phone) { + if (tenant.email && tenant.number_house && tenant.dni + && tenant.name && tenant.last_name && tenant.phone) { let _tenants = [...tenants] let _tenant = { ...tenant } - _tenant.community_id = communityId; + _tenant.community_id = cookies.community_id; _tenant.password = _tenant.email; console.log(_tenant) @@ -429,6 +429,12 @@ const Inquilinos = () => { setTenant(_tenant) } + const handleHouses = (e) => { + const getHouseNumber = e.target.value; + setHouseNumber(getHouseNumber); + console.log(getHouseNumber); + } + return (
@@ -667,20 +673,32 @@ const Inquilinos = () => { onInputChange(e, 'phone')} type='tel' required autoFocus className={classNames({ 'p-invalid': submitted && tenant.phone === '' })} />
- {submitted && tenant.phone === '' && Número de teléfono es requerido.} + {submitted + && tenant.phone === '' + && Número de teléfono es requerido.}
- +
- onInputChange(e, 'community_id')} required autoFocus className={classNames({ 'p-invalid': submitted && !communityId })} /> +
- {submitted && !communityId && Comunidad es requerida.} + {submitted + && !houseNumber + && Casa es requerida.}