Skip to content

Commit

Permalink
Fechas
Browse files Browse the repository at this point in the history
Corrección en la búsqueda por fechas del Search
Corrección en visualización de las reservas, al formatear perdía un día
  • Loading branch information
Karen1308 committed Dec 7, 2023
1 parent 40d314a commit 9a8efb7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
10 changes: 7 additions & 3 deletions Front/src/Components/card/Card.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import PropTypes from 'prop-types';
import { useLocation } from 'react-router-dom';
import Image from "./../image/Image";
import Category_pills from "./../category/CategoryPills";
import Button from "./../buttons/Button";
import FavButton from "./../buttons/FavButton";

const Card = (props) => {
const { id, titulo, subtitulo, precioBase, categoria, rating, duracion, dificultad, salidaDTO, imagenes } = props.data;
const currentPath = useLocation().pathname;

return (
<div className="card" data-aos="fade-up">
Expand All @@ -26,9 +28,11 @@ const Card = (props) => {
Desde <strong>USD {precioBase}</strong>
</p>
</div>
<div className="col-12 col-md-5 btn-container">
<Button url={`tour/${id}`} buttonName="Ver detalle" />
</div>
{currentPath != "/profile/favs" &&
<div className="col-12 col-md-5 btn-container">
<Button url={`tour/${id}`} buttonName="Ver detalle" />
</div>
}
</div>
<div className="card-footer">
<div className="rating">
Expand Down
6 changes: 1 addition & 5 deletions Front/src/Components/utils/ProtectedRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import React from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import PropTypes from 'prop-types';
import NotFound from '../../Routes/NotFound';

const ProtectedRoute = ({ children, onlyAdmin }) => {
const isAuthenticated = Boolean(localStorage.getItem('userData'));

const location = useLocation();

const currentPath = location.pathname;

const isReservationDetailRoute = currentPath === '/detailReservation';
const isReservationDetailRoute = currentPath === '/reserve';
const isFavsRoute = currentPath === '/profile/favs';

const getRedirectState = () => {
Expand Down
28 changes: 4 additions & 24 deletions Front/src/Routes/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,16 @@ const Home = () => {
}
}, [startDate, endDate]);

/*
const filteredTours = result.filter((tour) => {
const fechaDesdeArray = tour.salidaDTO.fechaSalidaDesde;
const fechaHastaArray = tour.salidaDTO.fechaSalidaHasta;
const tourName = tour.titulo || "";
const fechaDesde = new Date(tour.salidaDTO.fechaSalidaDesde)
const fechaHasta = new Date(tour.salidaDTO.fechaSalidaHasta)

const fechaDesde = new Date(fechaDesdeArray[0], fechaDesdeArray[1] - 1, fechaDesdeArray[2])
const fechaHasta = new Date(fechaHastaArray[0], fechaHastaArray[1] - 1, fechaHastaArray[2])
const categoryFilter = !clickedCategoryName || tour.categoria === clickedCategoryName;
const dateFilter =
(endDate === null || startDate >= fechaDesde && startDate <= fechaHasta);
return categoryFilter && dateFilter && tourName.toLowerCase().includes(search.toLowerCase());
}); */

const filteredTours = result.filter((tour) => {
const tourName = tour.titulo || "";
const fechaDesde = new Date(tour.salidaDTO.fechaSalidaDesde);

// Ajuste para el índice del mes (restar 1)
const correctedMonth = fechaDesde.getMonth();

const categoryFilter = !clickedCategoryName || tour.categoria === clickedCategoryName;
const dayFilter = startDate ? fechaDesde.getDate() === startDate.getDate() : true;
const monthFilter = startDate ? correctedMonth === (startDate.getMonth()) : true;
const dateFilter = (endDate === null || startDate >= fechaDesde && startDate <= fechaHasta);
const searchFilter = tourName.toLowerCase().includes(search.toLowerCase());

return categoryFilter && (dayFilter || monthFilter) && searchFilter;
return categoryFilter && dateFilter && searchFilter;
});

useEffect(() => {
Expand Down Expand Up @@ -126,7 +107,6 @@ const Home = () => {
endDate={endDate}
search={search}
/>
{/* <Search onSearchChange={handleSearchChange} onSearchSubmit={handleSearchSubmit} search={search} /> */}

<CategoryNav
clickedCategoryName={clickedCategoryName}
Expand Down
36 changes: 26 additions & 10 deletions Front/src/Routes/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,26 @@ const Login = () => {
texto: "Inicio de sesión exitoso.",
});
if (location.state?.fromReserve) {
navigate("/detailReservation");
/*
<Link
className="btn btn-lg w-full w-lg-auto"
to={"/reserve"}
state={{
tourData: result,
hotelData: lodging,
userData: JSON.parse(localStorage.getItem("userData")),
reserveData: {
stateDate: stateDate[0],
numberOfAdults,
numberOfChildren,
},
}}
>
Iniciar reserva
</Link>
*/
// navigate("/reserve");
navigate("/");
} else {
navigate("/");
}
Expand Down Expand Up @@ -169,9 +188,8 @@ const Login = () => {
</label>
<input
type="text"
className={`form-control ${
errors.email ? "is-invalid" : ""
}`}
className={`form-control ${errors.email ? "is-invalid" : ""
}`}
id="email"
value={formData.email}
onChange={handleInputChange}
Expand All @@ -186,9 +204,8 @@ const Login = () => {
</label>
<input
type="password"
className={`form-control ${
errors.password ? "is-invalid" : ""
}`}
className={`form-control ${errors.password ? "is-invalid" : ""
}`}
id="password"
value={formData.password}
onChange={handleInputChange}
Expand All @@ -211,9 +228,8 @@ const Login = () => {
</p>
{mensaje && (
<div
className={`mt-3 alert alert-${
mensaje.tipo === "error" ? "danger" : "success"
}`}
className={`mt-3 alert alert-${mensaje.tipo === "error" ? "danger" : "success"
}`}
>
{mensaje.texto}
</div>
Expand Down
4 changes: 2 additions & 2 deletions Front/src/Routes/Reservation.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from "react";
import { format } from 'date-fns';
import { format, parseISO } from 'date-fns';
import Breadcrumb from "../Components/breadcrumb/Breadcrumb";
import Banner from "../Components/ui-components/banner/Banner";
import Pagination from "../Components/ui-components/pagination/Pagination";
Expand Down Expand Up @@ -87,7 +87,7 @@ const Reservation = () => {
<tbody>
{combinedData.map((combinedData) => (
<tr key={combinedData.idReserva}>
<td>{format(new Date(combinedData.fechaSalida), 'dd/MM/yyyy')}</td>
<td>{format(parseISO(combinedData.fechaSalida), 'dd/MM/yyyy', { timeZone: 'UTC' })}</td>
<td>{combinedData.tourData.titulo}</td>
<td>{combinedData.tourData.categoria}</td>
<td>{combinedData.acompaniantes_mayores} </td>
Expand Down
5 changes: 1 addition & 4 deletions Front/src/Routes/Reserve.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const Reserve = () => {
const { tourData, hotelData, userData, reserveData } = location.state || {};
const { stateDate, numberOfAdults, numberOfChildren } = reserveData;
const { startDate, endDate } = stateDate;
const formattedDates =
("0" + new Date(startDate).getDate()).slice(-2) +
" al " +
format(new Date(endDate), "dd 'de' MMMM 'del' yyyy", { locale: esLocale });
const formattedDates = ("0" + new Date(startDate).getDate()).slice(-2) + " al " + format(new Date(endDate), "dd 'de' MMMM 'del' yyyy", { locale: esLocale });
const { nombre, apellido, email } = userData;
const [mensaje, setMensaje] = useState(null);

Expand Down

0 comments on commit 9a8efb7

Please sign in to comment.