"use client"; import React, { useState, useEffect } from "react"; import { db, auth } from "@/lib/firebase"; import { collection, onSnapshot, query, orderBy, limit } from "firebase/firestore"; import Link from "next/link"; export default function Dashboard() { const [stats, setStats] = useState({ products: 0, clients: 0, salesCount: 0, revenue: 0, }); useEffect(() => { // Real-time stats from Firestore const unsubProducts = onSnapshot(collection(db, "products"), (snap) => { setStats((prev) => ({ ...prev, products: snap.size })); }); const unsubClients = onSnapshot(collection(db, "clients"), (snap) => { setStats((prev) => ({ ...prev, clients: snap.size })); }); const unsubSales = onSnapshot(collection(db, "sales"), (snap) => { let rev = 0; snap.forEach((doc) => { rev += doc.data().total || 0; }); setStats((prev) => ({ ...prev, salesCount: snap.size, revenue: rev })); }); return () => { unsubProducts(); unsubClients(); unsubSales(); }; }, []); return (
Bienvenido al centro de control de tu negocio
Actualizado en tiempo real con Firestore
{title}
{value}