Merge pull request #108 from DeimosPr4/US-38-Registrar-Inquilinos

agregar registro de inquilinos
This commit is contained in:
Maria Sánchez 2022-07-22 14:16:38 -06:00 committed by GitHub
commit e34fb7d5cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 0 deletions

View File

@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
"name": "api-gateway",
"version": "0.0.1",
"license": "UNLICENSED",
"dependencies": {

View File

@ -32,6 +32,7 @@ import AdministradoresSistema from './components/AdministradoresSistema';
import AdministradoresComunidad from './components/AdministradoresComunidad';
import GuardasSeguridad from './components/GuardasSeguridad';
import Communities from './components/ComunidadViviendas';
import Inquilinos from './components/Inquilinos';
import Crud from './pages/Crud';
import EmptyPage from './pages/EmptyPage';
@ -169,6 +170,7 @@ const App = () => {
{label: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresComunidad'},
{label: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad'},
{label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas'},
{label: 'Inquilinos', icon: 'pi pi-fw pi-id-card', to: '/inquilinos'},
{label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'}
]
},
@ -326,6 +328,7 @@ const App = () => {
<Route path="/administradoresComunidad" component={AdministradoresComunidad} />
<Route path="/guardasSeguridad" component={GuardasSeguridad} />
<Route path="/comunidadesViviendas" component={Communities} />
<Route path="/inquilinos" component={Inquilinos} />
<Route path="/logIn" component={LogIn} />
</div>

View File

@ -0,0 +1,64 @@
import { Button } from 'primereact/button';
import { Dropdown } from 'primereact/dropdown';
import { InputText } from 'primereact/inputtext'
import React, { useEffect, useState } from 'react'
const Inquilinos = () => {
const [communitiesList, setCommunitiesList] = useState([]);
const communityIdList = communitiesList.map(community => community.id);
async function getCommunites() {
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' });
let list = await response.json();
setCommunitiesList(list.message);
}
useEffect(() => {
getCommunites();
}, [])
function registrarInquilino() {
let data = {
email: document.getElementById('correo_electronico').value,
community_id: document.getElementById('numero_vivienda').value,
user_type: '3',
status: '1',
}
fetch('http://localhost:3000/api/createUser', {
method: 'POST',
cache: 'no-cache',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
}).then((response) => {
if (response.ok) {
alert('Inquilino registrado correctamente')
} else {
alert('Error al registrar inquilino')
}
})
}
return (
<div className="grid">
<div className="col-12">
<div className="card">
<h5 className="card-header">Registrar Inquilino</h5>
<div className="p-fluid formgrid grid">
<div className="p-field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label>
<InputText type="email" className="form-control" id="correo_electronico" />
</div>
<div className="p-field col-12 md:col-6">
<label htmlFor="numero_vivienda">Número de Vivienda</label>
<Dropdown id="numero_vivienda" value={communityIdList[0]} options={communitiesList} />
</div>
<Button label="Registrar" onClick={registrarInquilino} />
</div>
</div>
</div>
</div>
)
}
export default React.memo(Inquilinos);