Áreacomúnparainquilino: Auto stash before merge of "US-30-ReservarÁreacomúnparainquilino" and "US-32-ListarReservas"

This commit is contained in:
Mariela 2022-08-24 16:14:33 -06:00
parent d2c9915669
commit 1da7b2c63f
1 changed files with 72 additions and 2 deletions

View File

@ -41,7 +41,9 @@ const Reservations = () => {
const dt = useRef(null); const dt = useRef(null);
const [cookies, setCookies] = useCookies() const [cookies, setCookies] = useCookies()
const [areas, setAreas] = useState([]); const [areas, setAreas] = useState([]);
const [areaId, setAreaId] = useState();
const [tenants, setTenants] = useState([]); const [tenants, setTenants] = useState([]);
const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar")
async function tenantsList(id) { async function tenantsList(id) {
await fetch(`http://localhost:4000/user/findTenants/${id}`, await fetch(`http://localhost:4000/user/findTenants/${id}`,
@ -105,8 +107,8 @@ const Reservations = () => {
reservations.map((item) => { reservations.map((item) => {
let tenant = tenants.find(item2 => item2._id == item.user_id); let tenant = tenants.find(item2 => item2._id == item.user_id);
if(tenant){ if (tenant) {
item.user_name = tenant.name + ' ' + tenant.last_name; item.user_name = tenant.name + ' ' + tenant.last_name;
} }
}); });
@ -115,7 +117,13 @@ const Reservations = () => {
reservationList(cookies.community_id); reservationList(cookies.community_id);
}, []) }, [])
const saveReservation = () => {
if (reservation.common_area_id) {
} else {
setSubmitted(true);
}
}
const actionsReservation = (rowData) => { const actionsReservation = (rowData) => {
@ -144,6 +152,12 @@ const Reservations = () => {
setDeleteReservationsDialog(true); setDeleteReservationsDialog(true);
}; };
const cancelEdit = () => {
setReservation(emptyReservation);
setSaveButtonTitle('Registrar');
setAreaId('');
}
const leftToolbarTemplate = () => { const leftToolbarTemplate = () => {
return ( return (
<React.Fragment> <React.Fragment>
@ -250,6 +264,16 @@ const Reservations = () => {
); );
}; };
const handleAreas = (e) => {
const getAreaId = e.target.value;
setAreaId(getAreaId);
}
const aList = areas.map((item) => ({
label: item.name,
value: item._id,
}));
return ( return (
<div className="grid"> <div className="grid">
<div className="col-12"> <div className="col-12">
@ -343,7 +367,53 @@ const Reservations = () => {
</div> </div>
</div> </div>
<div className="col-12">
<div className="card">
<h5>Reservar Área para Inquilino</h5>
<div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6">
<label htmlFor="common_area_id">Área Común: </label>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup">
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-home"></i>
</span>
<Dropdown
placeholder="--Seleccione el Area Común a Reservar--"
id="common_area_id"
value={areaId}
options={aList}
onChange={handleAreas}
required autoFocus
className={
classNames({ 'p-invalid': submitted && !areaId })}
/>
</div>
{submitted
&& !areaId
&& <small className="p-invalid">Área Común es requerida.</small>}
</div>
</div>
<div style={{
display: "flex",
justifyContent: "center",
gap: "10px",
width: "100%"
}}>
<Button
label={`${saveButtonTitle}`}
onClick={saveReservation}
/>
{saveButtonTitle === 'Actualizar' && (
<Button
label="Cancelar"
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div>
</div>
</div>
</div> </div>