Files
Suman/apps/suman-bosna/src/modules/account/components/account-nav/index.tsx
Nermin Karic ada6fd857c design upgrade
2026-11-23 00:59:47 +01:00

61 lines
2.2 KiB
TypeScript

"use client"
import { useParams, usePathname } from "next/navigation"
import { signout } from "@lib/data/customer"
import { HttpTypes } from "@medusajs/types"
import LocalizedClientLink from "@modules/common/components/localized-client-link"
import { cn } from "@/lib/utils"
const NAV_LINKS = [
{ href: "/account", label: "Pregled" },
{ href: "/account/profile", label: "Profil" },
{ href: "/account/addresses", label: "Adrese" },
{ href: "/account/orders", label: "Narudžbe" },
]
/** Account tabs, same pill style as the catalog category tabs */
const AccountNav = ({ customer: _customer }: { customer: HttpTypes.StoreCustomer | null }) => {
const route = usePathname()
const { countryCode } = useParams() as { countryCode: string }
const isActive = (href: string) => {
const full = `/${countryCode}${href}`
// Order details live under /account/orders/details/...
return href === "/account" ? route === full : route.startsWith(full)
}
return (
<nav aria-label="Moj račun" className="flex justify-center" data-testid="account-nav">
<div className="inline-flex max-w-full items-center gap-1 overflow-x-auto rounded-lg bg-muted p-1 text-sm">
{NAV_LINKS.map((link) => {
const active = isActive(link.href)
return (
<LocalizedClientLink
key={link.href}
href={link.href}
aria-current={active ? "page" : undefined}
className={cn(
"whitespace-nowrap rounded-md px-4 py-2 transition-colors",
active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
)}
data-testid={link.href === "/account" ? "account-main-link" : undefined}
>
{link.label}
</LocalizedClientLink>
)
})}
<button
type="button"
onClick={() => signout(countryCode)}
className="whitespace-nowrap rounded-md px-4 py-2 text-muted-foreground transition-colors hover:text-destructive"
data-testid="logout-button"
>
Odjava
</button>
</div>
</nav>
)
}
export default AccountNav