diff --git a/src/App.tsx b/src/App.tsx
index 8ed5e94..f3a68bd 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -16,6 +16,7 @@ import {AuthProvider} from "./context/AuthContext";
import {Toaster} from "react-hot-toast";
import type {JSX} from "react";
import {AnimalsProvider} from "./context/AnimalsContext.tsx";
+import { AdoptionsProvider } from "./context/AdoptionsContext";
const ProtectedLayout = ({children}: { children: JSX.Element }) => (
@@ -34,32 +35,34 @@ export default function App() {
return (
-
+
+
-
-
- }/>
+
+
+ }/>
- }/>}/>
- }/>}/>
+ }/>}/>
+ }/>}/>
- }/>}/>
- }/>}/>
+ }/>}/>
+ }/>}/>
- }/>}/>
- }/>}/>
+ }/>}/>
+ }/>}/>
- }/>}/>
- }/>}/>
+ }/>}/>
+ }/>}/>
- }/>}/>
+ }/>}/>
- }/>}/>
- }/>}/>
+ }/>}/>
+ }/>}/>
- }/>}/>
-
-
+ }/>}/>
+
+
+
);
diff --git a/src/context/AdoptionsContext.tsx b/src/context/AdoptionsContext.tsx
new file mode 100644
index 0000000..d4675b6
--- /dev/null
+++ b/src/context/AdoptionsContext.tsx
@@ -0,0 +1,48 @@
+import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
+import { collection, onSnapshot } from "firebase/firestore";
+import { db } from "../lib/firebase";
+
+export type Adoption = {
+ id: string;
+ adopterId: string;
+ animalId: string;
+ employeeId: string;
+ status: string;
+ notes?: string;
+ adoptionDate?: string;
+};
+
+type AdoptionsContextType = {
+ adoptions: Adoption[];
+};
+
+const AdoptionsContext = createContext
(undefined);
+
+export const AdoptionsProvider = ({ children }: { children: ReactNode }) => {
+ const [adoptions, setAdoptions] = useState([]);
+
+ useEffect(() => {
+ const adoptionsCol = collection(db, "adoptions");
+ const unsubscribe = onSnapshot(adoptionsCol, (snapshot) => {
+ const formatted = snapshot.docs.map((doc) => ({
+ id: doc.id,
+ ...(doc.data() as Omit),
+ }));
+ setAdoptions(formatted);
+ });
+
+ return () => unsubscribe();
+ }, []);
+
+ return (
+
+ {children}
+
+ );
+};
+
+export const useAdoptions = () => {
+ const context = useContext(AdoptionsContext);
+ if (!context) throw new Error("useAdoptions deve ser usado dentro de um AdoptionsProvider");
+ return context;
+};
diff --git a/src/pages/Animal/AnimalList.tsx b/src/pages/Animal/AnimalList.tsx
index 2a2759a..1378a03 100644
--- a/src/pages/Animal/AnimalList.tsx
+++ b/src/pages/Animal/AnimalList.tsx
@@ -39,12 +39,28 @@ export default function AnimalList() {
const calcularIdade = (birthDate?: string) => {
if (!birthDate) return "Não informado";
+
const nascimento = new Date(birthDate);
const hoje = new Date();
- let idade = hoje.getFullYear() - nascimento.getFullYear();
- const m = hoje.getMonth() - nascimento.getMonth();
- if (m < 0 || (m === 0 && hoje.getDate() < nascimento.getDate())) idade--;
- return `${idade} ano${idade !== 1 ? "s" : ""}`;
+
+ let anos = hoje.getFullYear() - nascimento.getFullYear();
+ let meses = hoje.getMonth() - nascimento.getMonth();
+ let dias = hoje.getDate() - nascimento.getDate();
+
+ if (dias < 0) {
+ meses--;
+ const ultimoDiaMesAnterior = new Date(hoje.getFullYear(), hoje.getMonth(), 0).getDate();
+ dias += ultimoDiaMesAnterior;
+ }
+
+ if (meses < 0) {
+ anos--;
+ meses += 12;
+ }
+
+ if (anos > 0) return `${anos} ano${anos !== 1 ? "s" : ""}`;
+ if (meses > 0) return `${meses} mês${meses !== 1 ? "es" : ""}`;
+ return `${dias} dia${dias !== 1 ? "s" : ""}`;
};
const inputStyle = (error?: boolean) =>
@@ -161,7 +177,6 @@ export default function AnimalList() {
)}
- {/* Modal de Edição */}