diff --git a/migrations/versions/2309db853ee5_.py b/migrations/versions/72e27a338232_.py similarity index 97% rename from migrations/versions/2309db853ee5_.py rename to migrations/versions/72e27a338232_.py index 27d785e2e1..f4f6d7d975 100644 --- a/migrations/versions/2309db853ee5_.py +++ b/migrations/versions/72e27a338232_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 2309db853ee5 +Revision ID: 72e27a338232 Revises: -Create Date: 2025-03-20 14:23:41.224215 +Create Date: 2025-03-20 18:45:28.776433 """ from alembic import op @@ -10,7 +10,7 @@ # revision identifiers, used by Alembic. -revision = '2309db853ee5' +revision = '72e27a338232' down_revision = None branch_labels = None depends_on = None diff --git a/src/front/js/pages/vistaMascota.js b/src/front/js/pages/vistaMascota.js index 206952ff07..51811b6e62 100644 --- a/src/front/js/pages/vistaMascota.js +++ b/src/front/js/pages/vistaMascota.js @@ -1,8 +1,7 @@ import React, { useEffect, useState, useContext } from 'react'; -import { useParams, useNavigate } from 'react-router-dom'; +import { useParams, useNavigate, Link } from 'react-router-dom'; import { Context } from "../store/appContext"; import { Modal, Button, Form } from 'react-bootstrap'; -import "../../styles/home.css"; export const VistaMascota = () => { const { id } = useParams(); @@ -22,32 +21,30 @@ export const VistaMascota = () => { }); const [foodSuggestions, setFoodSuggestions] = useState([]); - const getPetDetails = async (id) => { - try { - const resp = await fetch(`${process.env.BACKEND_URL}/api/pets/${id}`); - if (resp.status === 404) { + useEffect(() => { + const getPetDetails = async (id) => { + try { + const resp = await fetch(`${process.env.BACKEND_URL}/api/pets/${id}`); + if (resp.status === 404) { + setPetDetails(null); + } else { + const petData = await resp.json(); + setPetDetails(petData); + setEditedPet({ + name: petData.name || "", + animal_type: petData.animal_type || "", + breed: petData.breed || "", + size: petData.size || "", + age: petData.age || "", + pathologies: petData.pathologies || "" + }); + } + } catch (error) { setPetDetails(null); - } else { - const petData = await resp.json(); - setPetDetails(petData); - setEditedPet({ - name: petData.name || "", - animal_type: petData.animal_type || "", - breed: petData.breed || "", - size: petData.size || "", - age: petData.age || "", - pathologies: petData.pathologies || "" - }); + } finally { + setLoading(false); } - } catch (error) { - console.error("Error al obtener los detalles de la mascota", error); - setPetDetails(null); - } finally { - setLoading(false); - } - }; - - useEffect(() => { + }; getPetDetails(id); }, [id]); @@ -59,7 +56,6 @@ export const VistaMascota = () => { } }, [petDetails, id]); - useEffect(() =>{console.log(foodSuggestions)},[foodSuggestions]) useEffect(() => { if (!loading && petDetails === null) { navigate("/not-found"); @@ -69,18 +65,14 @@ export const VistaMascota = () => { const handleDelete = async () => { try { await actions.deletePet(id); - } catch (error) { - console.error("Error al eliminar la mascota (se ignora):", error); - } + } catch (error) {} navigate("/perfilUsuario"); }; const handleEdit = async () => { try { await actions.editPet(id, editedPet); - } catch (error) { - console.error("Error al editar la mascota (se ignora):", error); - } + } catch (error) {} setShowModal(false); navigate("/perfilUsuario"); }; @@ -90,149 +82,222 @@ export const VistaMascota = () => { return (
-

Detalles de la Mascota

-
-
-
- {petDetails.name} -
-
{petDetails.name}
-

Especie: {petDetails.animal_type}

-

Raza: {petDetails.breed}

-

Tamaño: {petDetails.size}

-

Edad: {petDetails.age}

-

Patologías: {petDetails.pathologies}

- - -
-
+

🐾 Detalles de la Mascota

+ + {/* Diseño mejorado para mostrar la imagen y el nombre al lado */} +
+
+
+ + {/* Contenedor de la imagen y el nombre */} +
+ {petDetails.name} + {/* Nombre de la mascota debajo de la imagen */} +

{petDetails.name}

+
+ + {/* Contenedor de los datos a la derecha */} +
+

Raza: {petDetails.breed}

+

Tamaño: {petDetails.size}

+

Edad: {petDetails.age}

+

Patologías: {petDetails.pathologies}

+ + {/* Contenedor de los botones alineados a la derecha */} +
+ +
-
-
-

Comida Recomendada

-
- {foodSuggestions.length > 0 ? ( - foodSuggestions.map((food, index) => ( -
- {food.name} -
-
{food.name}
- {food.description &&

{food.description}

} -
-
- )) - ) : ( -

No se encontraron sugerencias de comida.

+
+
+
+ + {/* Comida Recomendada */} +
+

🍽️ Comida Recomendada

+
+ {foodSuggestions.length > 0 ? ( + foodSuggestions.map((food, index) => ( +
+ {food.name} +
+
+ + {food.name} + +
+ {food.description && ( +

+ {food.description.length > 80 ? food.description.substring(0, 80) + "..." : food.description} +

)}
-
+ )) + ) : ( +

No se encontraron sugerencias de comida.

+ )} +
+
+ {/* Modal para editar mascota */} - setShowModal(false)}> - - Editar Mascota - - -
- - Nombre - setEditedPet({ ...editedPet, name: e.target.value })} - /> - - - - Especie - setEditedPet({ ...editedPet, animal_type: e.target.value })} - > - - - - - - - - - Raza - setEditedPet({ ...editedPet, breed: e.target.value })} - /> - - - - Tamaño - setEditedPet({ ...editedPet, size: e.target.value })} - > - - - - - - - - - Etapa Vital - setEditedPet({ ...editedPet, age: e.target.value })} - > - - - - - - - - - Patologías - setEditedPet({ ...editedPet, pathologies: e.target.value })} - > - - - - - - - - - -
-
- - - - -
+{/* Modal para editar mascota */} + setShowModal(false)} centered> + + Editar Mascota + + + +
+ + Nombre + setEditedPet({ ...editedPet, name: e.target.value })} + placeholder="Ej: Max, Luna, Rex..." + style={{ fontSize: "1rem", padding: "10px" }} + /> + + + + Especie + setEditedPet({ ...editedPet, animal_type: e.target.value })} + style={{ fontSize: "1rem", padding: "10px" }} + > + + + + + + + + + Raza + setEditedPet({ ...editedPet, breed: e.target.value })} + placeholder="Ej: Labrador, Siamés, Iguana..." + style={{ fontSize: "1rem", padding: "10px" }} + /> + + + + Tamaño + setEditedPet({ ...editedPet, size: e.target.value })} + style={{ fontSize: "1rem", padding: "10px" }} + > + + + + + + + + + Etapa Vital + setEditedPet({ ...editedPet, age: e.target.value })} + style={{ fontSize: "1rem", padding: "10px" }} + > + + + + + + + + + Patologías + setEditedPet({ ...editedPet, pathologies: e.target.value })} + style={{ fontSize: "1rem", padding: "10px" }} + > + + + + + + + + + +
+
+ + + + + + +
); -}; +}; \ No newline at end of file