189 lines
6.0 KiB
TypeScript
189 lines
6.0 KiB
TypeScript
"use client";
|
|
import { useEffect, useState } from "react";
|
|
import { getUser } from "@/lib/usersService";
|
|
|
|
import {
|
|
Sidebar,
|
|
SidebarContent,
|
|
SidebarFooter,
|
|
SidebarGroup,
|
|
SidebarGroupContent,
|
|
SidebarGroupLabel,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
} from "@/components/ui/sidebar";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
import { UserProfileDialog } from "@/components/user-profile";
|
|
import {
|
|
Home,
|
|
FolderKanban,
|
|
BarChart3,
|
|
Settings,
|
|
ChevronUp,
|
|
LogOut,
|
|
User,
|
|
GanttChart
|
|
} from "lucide-react";
|
|
|
|
// Datos del menú
|
|
const items = [
|
|
{
|
|
title: "Dashboard",
|
|
url: "/",
|
|
icon: Home,
|
|
},
|
|
{
|
|
title: "Proyectos",
|
|
url: "/proyectos",
|
|
icon: FolderKanban,
|
|
},
|
|
{
|
|
title: "Estadísticas",
|
|
url: "/estadisticas",
|
|
icon: BarChart3,
|
|
},
|
|
{
|
|
title: "Gantt",
|
|
url: "/gantt",
|
|
icon: GanttChart,
|
|
},
|
|
];
|
|
|
|
export function AppSidebar() {
|
|
const [user, setUser] = useState({
|
|
name: "Cargando...",
|
|
email: "",
|
|
avatar: "/avatar.jpg",
|
|
initials: "..."
|
|
});
|
|
const [isProfileOpen, setIsProfileOpen] = useState(false);
|
|
|
|
useEffect(() => {
|
|
async function loadUser() {
|
|
try {
|
|
const realUser = await getUser();
|
|
setUser({
|
|
name: `${realUser.firstname} ${realUser.lastname}`,
|
|
email: realUser.email,
|
|
avatar: "/avatar.jpg",
|
|
initials: `${realUser.firstname.charAt(0)}${realUser.lastname.charAt(0)}`
|
|
});
|
|
} catch (error) {
|
|
console.error("Failed to load user:", error);
|
|
setUser(prev => ({ ...prev, name: "Usuario desconocido" }));
|
|
}
|
|
}
|
|
loadUser();
|
|
}, []);
|
|
|
|
return (
|
|
<Sidebar>
|
|
<SidebarContent>
|
|
{/* Header del Sidebar */}
|
|
<SidebarGroup>
|
|
<div className="px-4 py-6">
|
|
<h2 className="text-xl font-semibold text-gray-900">Dolibarr</h2>
|
|
<p className="text-sm text-gray-500">Gestión de Proyectos</p>
|
|
</div>
|
|
</SidebarGroup>
|
|
|
|
{/* Menú de navegación */}
|
|
<SidebarGroup>
|
|
<SidebarGroupLabel className="text-sm">Menú Principal</SidebarGroupLabel>
|
|
<SidebarGroupContent>
|
|
<SidebarMenu>
|
|
{items.map((item) => (
|
|
<SidebarMenuItem key={item.title}>
|
|
<SidebarMenuButton asChild size="lg">
|
|
<a href={item.url} className="text-base">
|
|
<item.icon className="w-5 h-5" />
|
|
<span>{item.title}</span>
|
|
</a>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
))}
|
|
</SidebarMenu>
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
</SidebarContent>
|
|
|
|
{/* Footer con Dropdown del Usuario */}
|
|
<SidebarFooter>
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
>
|
|
<Avatar className="h-8 w-8 rounded-lg">
|
|
<AvatarImage src={user.avatar} alt={user.name} />
|
|
<AvatarFallback className="rounded-lg bg-gradient-to-br from-blue-500 to-purple-600 text-white">
|
|
{user.initials}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
|
<span className="truncate font-semibold">{user.name}</span>
|
|
<span className="truncate text-xs text-gray-500">{user.email}</span>
|
|
</div>
|
|
<ChevronUp className="ml-auto size-4" />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg"
|
|
side="bottom"
|
|
align="end"
|
|
sideOffset={4}
|
|
>
|
|
<DropdownMenuLabel className="p-0 font-normal">
|
|
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
|
<Avatar className="h-8 w-8 rounded-lg">
|
|
<AvatarImage src={user.avatar} alt={user.name} />
|
|
<AvatarFallback className="rounded-lg bg-gradient-to-br from-blue-500 to-purple-600 text-white">
|
|
{user.initials}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
|
<span className="truncate font-semibold">{user.name}</span>
|
|
<span className="truncate text-xs text-gray-500">{user.email}</span>
|
|
</div>
|
|
</div>
|
|
</DropdownMenuLabel>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem onClick={() => setIsProfileOpen(true)}>
|
|
<User className="mr-2 h-4 w-4" />
|
|
<span>Perfil</span>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem>
|
|
<Settings className="mr-2 h-4 w-4" />
|
|
<span>Ajustes</span>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem className="text-red-600">
|
|
<LogOut className="mr-2 h-4 w-4" />
|
|
<span>Cerrar sesión</span>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</SidebarFooter>
|
|
|
|
{/* Dialog de perfil de usuario */}
|
|
<UserProfileDialog
|
|
open={isProfileOpen}
|
|
onOpenChange={setIsProfileOpen}
|
|
/>
|
|
</Sidebar>
|
|
);
|
|
} |