From 9a8efb7015c9c4678924510496dcc7d03635fe05 Mon Sep 17 00:00:00 2001 From: Karen1308 Date: Thu, 7 Dec 2023 17:36:29 -0300 Subject: [PATCH] Fechas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Front/src/Components/card/Card.jsx | 10 ++++-- Front/src/Components/utils/ProtectedRoute.jsx | 6 +--- Front/src/Routes/Home.jsx | 28 +++------------ Front/src/Routes/Login.jsx | 36 +++++++++++++------ Front/src/Routes/Reservation.jsx | 4 +-- Front/src/Routes/Reserve.jsx | 5 +-- 6 files changed, 41 insertions(+), 48 deletions(-) diff --git a/Front/src/Components/card/Card.jsx b/Front/src/Components/card/Card.jsx index c2115fb..7003e5a 100644 --- a/Front/src/Components/card/Card.jsx +++ b/Front/src/Components/card/Card.jsx @@ -1,4 +1,5 @@ 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"; @@ -6,6 +7,7 @@ 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 (
@@ -26,9 +28,11 @@ const Card = (props) => { Desde USD {precioBase}

-
-
+ {currentPath != "/profile/favs" && +
+
+ }
diff --git a/Front/src/Components/utils/ProtectedRoute.jsx b/Front/src/Components/utils/ProtectedRoute.jsx index 3a0d506..6275445 100644 --- a/Front/src/Components/utils/ProtectedRoute.jsx +++ b/Front/src/Components/utils/ProtectedRoute.jsx @@ -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 = () => { diff --git a/Front/src/Routes/Home.jsx b/Front/src/Routes/Home.jsx index 4f74636..9bfb349 100644 --- a/Front/src/Routes/Home.jsx +++ b/Front/src/Routes/Home.jsx @@ -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(() => { @@ -126,7 +107,6 @@ const Home = () => { endDate={endDate} search={search} /> - {/* */} { texto: "Inicio de sesión exitoso.", }); if (location.state?.fromReserve) { - navigate("/detailReservation"); + /* + + Iniciar reserva + + */ + // navigate("/reserve"); + navigate("/"); } else { navigate("/"); } @@ -169,9 +188,8 @@ const Login = () => { { {

{mensaje && (
{mensaje.texto}
diff --git a/Front/src/Routes/Reservation.jsx b/Front/src/Routes/Reservation.jsx index 2ff661e..f89e199 100644 --- a/Front/src/Routes/Reservation.jsx +++ b/Front/src/Routes/Reservation.jsx @@ -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"; @@ -87,7 +87,7 @@ const Reservation = () => { {combinedData.map((combinedData) => ( - {format(new Date(combinedData.fechaSalida), 'dd/MM/yyyy')} + {format(parseISO(combinedData.fechaSalida), 'dd/MM/yyyy', { timeZone: 'UTC' })} {combinedData.tourData.titulo} {combinedData.tourData.categoria} {combinedData.acompaniantes_mayores} diff --git a/Front/src/Routes/Reserve.jsx b/Front/src/Routes/Reserve.jsx index a45a97c..0705325 100644 --- a/Front/src/Routes/Reserve.jsx +++ b/Front/src/Routes/Reserve.jsx @@ -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);