katoikia-app/web-ui/web-react/src/components/Inquilinos.js

65 lines
2.1 KiB
JavaScript
Raw Normal View History

import { Dropdown } from 'primereact/dropdown';
2022-07-20 00:54:20 +00:00
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,
2022-07-20 00:28:41 +00:00
user_type: '3',
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-18 01:20:03 +00:00
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} />
2022-07-20 00:28:41 +00:00
</div>
</div>
<button type="button" className="btn btn-primary" onClick={registrarInquilino}>
Registrar
</button>
2022-07-18 01:20:03 +00:00
</div>
</div>
</div>
)
}
2022-07-18 01:30:06 +00:00
2022-07-20 00:54:20 +00:00
export default React.memo(Inquilinos);