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.}