2022-07-20 01:23:36 +00:00
|
|
|
import { Dropdown } from 'primereact/dropdown';
|
2022-07-20 00:54:20 +00:00
|
|
|
import { InputText } from 'primereact/inputtext'
|
2022-07-20 01:21:37 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2022-07-16 07:48:36 +00:00
|
|
|
|
|
|
|
const Inquilinos = () => {
|
2022-07-20 01:22:50 +00:00
|
|
|
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();
|
|
|
|
}, [])
|
2022-07-16 07:48:36 +00:00
|
|
|
function registrarInquilino() {
|
|
|
|
let data = {
|
|
|
|
email: document.getElementById('correo_electronico').value,
|
2022-07-20 01:21:56 +00:00
|
|
|
community_id: document.getElementById('numero_vivienda').value,
|
2022-07-20 00:28:41 +00:00
|
|
|
user_type: '3',
|
2022-07-16 07:48:36 +00:00
|
|
|
status: '1',
|
|
|
|
}
|
2022-07-20 00:28:41 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
}
|
|
|
|
})
|
2022-07-16 07:48:36 +00:00
|
|
|
}
|
2022-07-18 01:20:03 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="grid">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="card">
|
2022-07-20 01:23:36 +00:00
|
|
|
<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} />
|
2022-07-20 00:28:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-20 01:23:36 +00:00
|
|
|
<button type="button" className="btn btn-primary" onClick={registrarInquilino}>
|
|
|
|
Registrar
|
|
|
|
</button>
|
2022-07-18 01:20:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
2022-07-16 07:48:36 +00:00
|
|
|
}
|
2022-07-18 01:30:06 +00:00
|
|
|
|
2022-07-20 00:54:20 +00:00
|
|
|
export default React.memo(Inquilinos);
|