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

223 lines
7.0 KiB
JavaScript
Raw Normal View History

import { Button } from 'primereact/button';
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';
2022-07-25 04:38:48 +00:00
import { InputText } from 'primereact/inputtext';
import React, { useEffect, useState } from 'react';
2022-07-24 05:54:26 +00:00
import { Toast } from 'primereact/toast';
2022-07-24 23:44:25 +00:00
import { Dialog } from 'primereact/dialog';
import { Toolbar } from 'primereact/toolbar';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faHome } from '@fortawesome/free-solid-svg-icons';
import { faUserAlt } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
import { faAt } from '@fortawesome/free-solid-svg-icons';
import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons';
import { faEllipsis } from '@fortawesome/free-solid-svg-icons';
import { faHashtag } from '@fortawesome/free-solid-svg-icons';
const Inquilinos = () => {
const [communitiesList, setCommunitiesList] = useState([]);
2022-07-25 04:38:48 +00:00
const communityIdList = communitiesList.map((community) => community.id);
async function getCommunites() {
2022-07-25 04:38:48 +00:00
let response = await fetch(
'http://localhost:4000/community/allCommunities',
{ method: 'GET' },
);
let list = await response.json();
2022-07-24 23:44:25 +00:00
setCommunitiesList(await list);
}
useEffect(() => {
getCommunites();
}, [])
2022-07-24 23:44:25 +00:00
function registrarInquilino() {
let data = {
2022-07-27 02:13:47 +00:00
dni: document.getElementById('identificacion').value,
name: document.getElementById('nombre').value,
last_name: document.getElementById('apellidos').value,
phone: document.getElementById('telefono').value,
email: document.getElementById('correo_electronico').value,
community_id: document.getElementById('numero_vivienda').value,
2022-07-27 02:13:47 +00:00
password: document.getElementById('password').value,
2022-07-20 00:28:41 +00:00
user_type: '3',
status: '1',
2022-07-25 04:38:48 +00:00
};
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) {
2022-07-25 04:38:48 +00:00
alert('Inquilino registrado correctamente');
2022-07-20 00:28:41 +00:00
} else {
2022-07-25 04:38:48 +00:00
alert('Error al registrar inquilino');
2022-07-20 00:28:41 +00:00
}
2022-07-25 04:38:48 +00:00
});
}
2022-07-18 01:20:03 +00:00
2022-07-24 23:44:25 +00:00
const cList = communitiesList.map((item) => ({
label: item.name,
value: item.id,
}))
const actionsAdmin = (rowData) => {
return (
<div className="actions">
<Button icon="pi pi-trash" className="p-button-rounded p-button-danger mt-2" onClick={() => confirmDeleteAdminSystem(rowData)} />
</div>
);
}
const leftToolbarTemplate = () => {
return (
<React.Fragment>
<div className="my-2">
<Button label="Eliminar" icon="pi pi-trash" className="p-button-danger" onClick={confirmDeleteSelected} disabled={!selectedAdministrators || !selectedAdministrators.length} />
</div>
</React.Fragment>
)
}
const rightToolbarTemplate = () => {
return (
<React.Fragment>
<Button label="Exportar" icon="pi pi-upload" className="p-button-help" />
</React.Fragment>
)
}
const header = (
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
<h5 className="m-0">Administradores del sistema</h5>
<span className="block mt-2 md:mt-0 p-input-icon-left">
<i className="pi pi-search" />
<InputText type="search" onInput={(e) => setGlobalFilter(e.target.value)} placeholder="Buscar..." />
</span>
</div>
);
const deleteAdminSystemDialogFooter = (
<>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteAdminSystemDialog} />
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteSysAdmin} />
</>
);
const deleteAdminsSystemDialogFooter = (
<>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteAdminsSystemsDialog} />
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteSelectedAdminsSystem} />
</>
);
const headerName = (
<>
<p> <FontAwesomeIcon icon={faUserAlt} style={{color: "#C08135"}} /> Nombre</p>
</>
)
const headerLastName = (
<>
<p> <FontAwesomeIcon icon={faUserAlt} style={{color: "#D7A86E"}} /> Apellidos</p>
</>
)
const headerDNI = (
<>
<p> <FontAwesomeIcon icon={faIdCardAlt} style={{color: "#C08135"}} /> Identificación</p>
</>
)
const headerEmail = (
<>
<p> <FontAwesomeIcon icon={faAt} style={{color: "#D7A86E"}} /> Correo Electrónico</p>
</>
)
const headerPhone = (
<>
<p> <FontAwesomeIcon icon={faPhoneAlt} style={{color: "#C08135"}} /> Teléfono</p>
</>
)
const headerCommuntiy = (
<>
<p> <FontAwesomeIcon icon={faHome} style={{ color: "#D7A86E" }} /> Comunidad</p>
</>
)
const headerNumberHouse = (
<>
<p> <FontAwesomeIcon icon={faHashtag} style={{ color: "#C08135" }} /> Número de vivienda</p>
</>
)
const headerOptions = (
<>
<p>Opciones <FontAwesomeIcon icon={faEllipsis} style={{ color: "#D7A86E" }} /></p>
</>
)
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">
2022-07-28 03:02:59 +00:00
<div className="field col-12 md:col-6">
2022-07-27 02:13:47 +00:00
<label htmlFor="nombre">Nombre</label>
2022-07-27 02:14:32 +00:00
<InputText type="text" className="form-control" id="nombre" />
2022-07-27 02:13:47 +00:00
</div>
2022-07-28 03:02:59 +00:00
<div className="field col-12 md:col-6">
2022-07-27 02:13:47 +00:00
<label htmlFor="apellidos">Apellidos</label>
2022-07-27 02:14:32 +00:00
<InputText type="text" className="form-control" id="apellidos" />
2022-07-27 02:13:47 +00:00
</div>
2022-07-28 03:02:59 +00:00
<div className="field col-12 md:col-6">
2022-07-27 02:13:47 +00:00
<label htmlFor="identificacion">Identificación</label>
2022-07-27 02:14:32 +00:00
<InputText
type="text"
className="form-control"
id="identificacion"
/>
2022-07-27 02:13:47 +00:00
</div>
2022-07-28 03:02:59 +00:00
<div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label>
2022-07-25 04:38:48 +00:00
<InputText
type="email"
className="form-control"
id="correo_electronico"
/>
</div>
2022-07-28 03:02:59 +00:00
<div className="field col-12 md:col-6">
<label htmlFor="numero_vivienda">Número de Vivienda</label>
2022-07-24 23:44:25 +00:00
<Dropdown id="numero_vivienda" value={communityId} options={cList} />
2022-07-20 00:28:41 +00:00
</div>
2022-07-28 03:02:59 +00:00
<div className="field col-12 md:col-6">
2022-07-27 02:13:47 +00:00
<label htmlFor="identificacion">Identificación</label>
2022-07-27 02:14:32 +00:00
<InputText
type="password"
className="form-control"
id="identificacion"
/>
2022-07-27 02:13:47 +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-25 04:38:48 +00:00
);
};
2022-07-18 01:30:06 +00:00
2022-07-25 04:38:48 +00:00
export default React.memo(Inquilinos);