- Toggling an item only disables that row, so several items can be marked in a row; failures roll back just that item and show a toast, and the list refetches once the last toggle settles. - Sidebar, bottom nav and header share one set of sections (Inicio / Listas / Ajustes); the bottom nav drops the duplicated "Cuenta" link and the header drops the non-functional search button. - Settings: the name is saved through BetterAuth, the email is shown read-only, and the fake notification switches are replaced by a real theme picker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
3.4 KiB
TypeScript
101 lines
3.4 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { ChevronsUpDownIcon, LogOutIcon, SettingsIcon } from 'lucide-react'
|
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu'
|
|
import {
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
useSidebar,
|
|
} from '@/components/ui/sidebar'
|
|
import { signOut, useSession } from '@/lib/auth-client'
|
|
|
|
function initials(name: string) {
|
|
return name
|
|
.split(' ')
|
|
.map((part) => part[0])
|
|
.filter(Boolean)
|
|
.slice(0, 2)
|
|
.join('')
|
|
.toUpperCase()
|
|
}
|
|
|
|
export function NavUser() {
|
|
const { isMobile } = useSidebar()
|
|
const { data: session } = useSession()
|
|
const navigate = useNavigate()
|
|
|
|
const user = session?.user
|
|
const name = user?.name ?? 'Sin sesión'
|
|
const email = user?.email ?? ''
|
|
|
|
return (
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
>
|
|
<Avatar className="size-8 rounded-lg">
|
|
<AvatarImage src={user?.image ?? undefined} alt={name} />
|
|
<AvatarFallback className="rounded-lg">{initials(name) || '?'}</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
|
<span className="truncate font-medium">{name}</span>
|
|
<span className="text-muted-foreground truncate text-xs">{email}</span>
|
|
</div>
|
|
<ChevronsUpDownIcon className="ml-auto size-4" />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
|
side={isMobile ? 'bottom' : 'right'}
|
|
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="size-8 rounded-lg">
|
|
<AvatarFallback className="rounded-lg">{initials(name) || '?'}</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
|
<span className="truncate font-medium">{name}</span>
|
|
<span className="text-muted-foreground truncate text-xs">{email}</span>
|
|
</div>
|
|
</div>
|
|
</DropdownMenuLabel>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem onClick={() => void navigate({ to: '/settings' })}>
|
|
<SettingsIcon />
|
|
Ajustes
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
onClick={async () => {
|
|
await signOut()
|
|
await navigate({ to: '/sign-in' })
|
|
}}
|
|
>
|
|
<LogOutIcon />
|
|
Cerrar sesión
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
)
|
|
}
|