cambiar selección de comunidad por selección de casas

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.
This commit is contained in:
Eduardo Quiros 2022-08-21 03:50:27 -06:00
parent 259444b371
commit 20f6aeb376
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
1 changed files with 44 additions and 26 deletions

View File

@ -41,15 +41,14 @@ const Inquilinos = () => {
const [globalFilter, setGlobalFilter] = useState(null) const [globalFilter, setGlobalFilter] = useState(null)
const [deleteTenantDialog, setDeleteTenantDialog] = useState(false) const [deleteTenantDialog, setDeleteTenantDialog] = useState(false)
const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false) const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false)
const [communitiesList, setCommunitiesList] = useState([]) const [community, setCommunity] = useState([])
const [communityId, setCommunityId] = useState(null) const [houseNumber, setHouseNumber] = useState([])
const [housesList, setHousesList] = useState([])
const [submitted, setSubmitted] = useState(false) const [submitted, setSubmitted] = useState(false)
const toast = useRef(null) const toast = useRef(null)
const dt = useRef(null) const dt = useRef(null)
const [cookies] = useCookies()
const [cookies, setCookie] = useCookies() const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false)
const [changeStatusTenantDialog, setChangeStatusTenantDialog] =
useState(false)
async function tenantsList() { async function tenantsList() {
await fetch( await fetch(
@ -75,15 +74,21 @@ const Inquilinos = () => {
}) })
} }
async function getCommunites() { async function getCommunity() {
let response = await fetch( let response = await fetch(
'http://localhost:4000/community/allCommunities', `http://localhost:4000/community/findCommunityName/${cookies.community_id}`,
{ method: 'GET' }, { method: 'GET' },
) )
let resList = await response.json() const responseJson = await response.json()
let list = await resList.message const result = await responseJson.message
list = await list.filter((val) => val.status !== -1) setCommunity(await result)
setCommunitiesList(await list) const houses = await result.houses.filter((house) =>
house.state === "desocupada"
)
setHousesList(houses.map((house) => ({
label: house.number_house, value: house.number_house
}))
)
} }
useEffect(() => { useEffect(() => {
@ -91,20 +96,15 @@ const Inquilinos = () => {
}, [tenantsList]) }, [tenantsList])
useEffect(() => { useEffect(() => {
getCommunites() getCommunity()
}, []) }, [])
const cList = communitiesList.map((item) => ({
label: item.name,
value: item._id,
}))
const saveTenant = () => { const saveTenant = () => {
if (tenant.email && tenant.community_id && tenant.dni if (tenant.email && tenant.number_house && tenant.dni
&& tenant.name && tenant.last_name && tenant.phone) { && tenant.name && tenant.last_name && tenant.phone) {
let _tenants = [...tenants] let _tenants = [...tenants]
let _tenant = { ...tenant } let _tenant = { ...tenant }
_tenant.community_id = communityId; _tenant.community_id = cookies.community_id;
_tenant.password = _tenant.email; _tenant.password = _tenant.email;
console.log(_tenant) console.log(_tenant)
@ -429,6 +429,12 @@ const Inquilinos = () => {
setTenant(_tenant) setTenant(_tenant)
} }
const handleHouses = (e) => {
const getHouseNumber = e.target.value;
setHouseNumber(getHouseNumber);
console.log(getHouseNumber);
}
return ( return (
<div className='grid'> <div className='grid'>
<div className='col-12'> <div className='col-12'>
@ -667,20 +673,32 @@ const Inquilinos = () => {
</span> </span>
<InputText id="phone" value={tenant.phone} onChange={(e) => onInputChange(e, 'phone')} type='tel' required autoFocus className={classNames({ 'p-invalid': submitted && tenant.phone === '' })} /> <InputText id="phone" value={tenant.phone} onChange={(e) => onInputChange(e, 'phone')} type='tel' required autoFocus className={classNames({ 'p-invalid': submitted && tenant.phone === '' })} />
</div> </div>
{submitted && tenant.phone === '' && <small className="p-invalid">Número de teléfono es requerido.</small>} {submitted
&& tenant.phone === ''
&& <small className="p-invalid">Número de teléfono es requerido.</small>}
</div> </div>
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="community_id">Comunidad a asignar: </label> <label htmlFor="number_house">Casa a asignar: </label>
<div className="p-0 col-12 md:col-12"> <div className="p-0 col-12 md:col-12">
<div className="p-inputgroup"> <div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-icon-input-khaki"> <span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-home"></i> <i className="pi pi-home"></i>
</span> </span>
<Dropdown placeholder="--Seleccione la Casa a Asignar--" id="community_id" value={communityId} options={cList} <Dropdown
onChange={(e) => onInputChange(e, 'community_id')} required autoFocus className={classNames({ 'p-invalid': submitted && !communityId })} /> placeholder="--Seleccione la Casa a Asignar--"
id="number_house"
value={houseNumber}
options={housesList}
onChange={handleHouses}
required autoFocus
className={
classNames({ 'p-invalid': submitted && !houseNumber })}
/>
</div> </div>
{submitted && !communityId && <small className="p-invalid">Comunidad es requerida.</small>} {submitted
&& !houseNumber
&& <small className="p-invalid">Casa es requerida.</small>}
</div> </div>
</div> </div>
<Button label="Registrar" onClick={saveTenant} /> <Button label="Registrar" onClick={saveTenant} />