"use client"; import { useEffect, useState } from "react"; import { User, Mail, Building, Calendar, Shield, Briefcase, Globe, Phone } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Separator } from "@/components/ui/separator"; import { Skeleton } from "@/components/ui/skeleton"; import { getUser } from "@/lib/usersService"; import { getProjects } from "@/lib/projectsService"; import { Project } from "@/types/project"; interface DolibarrUser { id: string; login: string; firstname: string; lastname: string; email: string; admin: string; statut: string; employee: string; job: string; address: string; zip: string; town: string; state_id: string; office_phone: string; user_mobile: string; fk_member: string; datelastlogin: number; datepreviouslogin: number; datec: string; datem: string; fk_soc: string; entity: string; } export default function PerfilPage() { const [user, setUser] = useState(null); const [projects, setProjects] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { async function loadData() { try { const [userData, projectsData] = await Promise.all([ getUser(), getProjects(), ]); setUser(userData); setProjects(projectsData); } catch (err) { console.error("Error loading profile data:", err); setError("No se pudo cargar la información del perfil"); } finally { setIsLoading(false); } } loadData(); }, []); if (isLoading) { return ; } if (error || !user) { return (

Error al cargar el perfil

{error}

); } const fullName = `${user.firstname} ${user.lastname}`; const initials = `${user.firstname?.charAt(0) || ""}${user.lastname?.charAt(0) || ""}`; const isAdmin = user.admin === "1"; const isActive = user.statut === "1"; const isEmployee = user.employee === "1"; // Stats from projects const activeProjects = projects.filter((p) => p.status === "1").length; const completedProjects = projects.filter((p) => p.status === "2").length; const totalBudget = projects.reduce((acc, p) => acc + (p.budget || 0), 0); const formatDate = (timestamp: number | string) => { if (!timestamp) return "N/A"; const ts = typeof timestamp === "string" ? parseInt(timestamp) : timestamp; const date = new Date(ts * 1000); return date.toLocaleDateString("es-ES", { day: "2-digit", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", }); }; return (
{/* Header */}

Mi Perfil

Información de tu cuenta de Dolibarr

{/* Profile card */}
{/* Avatar */} {initials} {/* Info */}

{fullName}

@{user.login}

{isActive ? "Activo" : "Inactivo"} {isAdmin && ( Administrador )} {isEmployee && ( Empleado )}
{/* Stats */}

{activeProjects}

Proyectos activos

{completedProjects}

Proyectos completados

{totalBudget.toLocaleString("es-ES")} €

Presupuesto total gestionado

{/* Details */}
{/* Contact info */} Información de Contacto Datos de contacto registrados en Dolibarr {/* Account info */} Información de la Cuenta Detalles de tu cuenta en el sistema
{/* Address */} {(user.address || user.town || user.zip) && ( Dirección
{user.address &&

{user.address}

} {(user.zip || user.town) && (

{[user.zip, user.town].filter(Boolean).join(", ")}

)}
)}
); } // Reusable info row component function InfoRow({ icon: Icon, label, value }: { icon: React.ComponentType<{ className?: string }>; label: string; value: string }) { return (

{label}

{value}

); } // Skeleton function ProfileSkeleton() { return (
{[1, 2, 3].map((i) => ( ))}
{[1, 2].map((i) => ( {[1, 2, 3, 4].map((j) => (
))}
))}
); }