2022-07-20 01:26:00 +00:00
|
|
|
import { Button } from 'primereact/button';
|
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-24 05:54:26 +00:00
|
|
|
import React, { useEffect, useState, useRef } from 'react'
|
|
|
|
import { DataTable } from 'primereact/datatable';
|
|
|
|
import { Column } from 'primereact/column';
|
|
|
|
import { Dropdown } from 'primereact/dropdown';
|
|
|
|
import { Toast } from 'primereact/toast';
|
|
|
|
import classNames from 'classnames';
|
2022-07-16 07:48:36 +00:00
|
|
|
|
|
|
|
const Inquilinos = () => {
|
2022-07-20 01:22:50 +00:00
|
|
|
const [communitiesList, setCommunitiesList] = useState([]);
|
2022-07-24 05:54:26 +00:00
|
|
|
const [tenants, setTenants] = useState([]);
|
|
|
|
|
|
|
|
const [tenant, setTenant] = useState(emptyTenant);
|
|
|
|
|
|
|
|
let emptyTenant = {
|
|
|
|
_id: null,
|
|
|
|
dni: '',
|
|
|
|
name: '',
|
|
|
|
last_name: '',
|
|
|
|
email: '',
|
|
|
|
phone: '',
|
|
|
|
password: '',
|
|
|
|
user_type: '1',
|
|
|
|
community_id: '',
|
|
|
|
community_name: '',
|
|
|
|
number_house: '',
|
|
|
|
status: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
async function getTenants() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-20 01:22:50 +00:00
|
|
|
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>
|
2022-07-24 05:54:26 +00:00
|
|
|
<Button label="Registrar" onClick={registrarInquilino} />
|
2022-07-20 00:28:41 +00:00
|
|
|
</div>
|
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);
|