Header: an account menu under the user's name
Profile, invoices, redeeming a code and logging out moved from the crowded top right and the main menu into a menu that opens from the name; on phones the name shows too (shortened), so the profile stays reachable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -64,6 +64,28 @@ p { margin: 0; }
|
|||||||
.nav a { color: var(--ink-2); text-decoration: none; padding: 10px 12px; border-radius: 8px; min-height: 44px; display: inline-flex; align-items: center; }
|
.nav a { color: var(--ink-2); text-decoration: none; padding: 10px 12px; border-radius: 8px; min-height: 44px; display: inline-flex; align-items: center; }
|
||||||
.nav a:hover, .nav a[aria-current="page"] { color: var(--gold); background: rgba(217, 180, 106, 0.08); }
|
.nav a:hover, .nav a[aria-current="page"] { color: var(--gold); background: rgba(217, 180, 106, 0.08); }
|
||||||
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
|
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
|
||||||
|
.user-menu { position: relative; }
|
||||||
|
.who-name {
|
||||||
|
display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 10px; cursor: pointer;
|
||||||
|
border: 1px solid var(--line-2); border-radius: 999px; background: none; color: var(--ink-2); font: inherit; font-size: 14px;
|
||||||
|
}
|
||||||
|
.who-name:hover, .who-name[aria-expanded="true"] { color: var(--gold); border-color: #5a6790; }
|
||||||
|
.who-chevron { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
||||||
|
.who-name[aria-expanded="true"] .who-chevron { transform: rotate(180deg); }
|
||||||
|
.user-menu-list {
|
||||||
|
position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 200px; padding: 6px;
|
||||||
|
display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
|
||||||
|
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
|
||||||
|
}
|
||||||
|
.user-menu-item {
|
||||||
|
display: flex; align-items: center; min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: none;
|
||||||
|
color: var(--ink); font: inherit; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer;
|
||||||
|
}
|
||||||
|
.user-menu-item:hover, .user-menu-item:focus-visible { background: rgba(255, 255, 255, 0.05); color: var(--gold); }
|
||||||
|
.user-menu-item[aria-current="page"] { color: var(--gold); }
|
||||||
|
.user-menu-logout { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; padding-top: 2px; color: var(--muted); }
|
||||||
|
.who-name-text { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.who-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
|
||||||
.pkg-pill {
|
.pkg-pill {
|
||||||
display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
|
display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
|
||||||
border: 1px solid rgba(217, 180, 106, 0.5); color: var(--gold); text-decoration: none; font-size: 13px; white-space: nowrap;
|
border: 1px solid rgba(217, 180, 106, 0.5); color: var(--gold); text-decoration: none; font-size: 13px; white-space: nowrap;
|
||||||
@@ -334,7 +356,8 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|||||||
h1 { font-size: 32px; }
|
h1 { font-size: 32px; }
|
||||||
.site-header { padding: 10px 16px; gap: 12px; }
|
.site-header { padding: 10px 16px; gap: 12px; }
|
||||||
.nav { order: 3; flex-basis: 100%; }
|
.nav { order: 3; flex-basis: 100%; }
|
||||||
.who-name { display: none; }
|
.who-name-text { max-width: 120px; }
|
||||||
|
.who { margin-left: auto; }
|
||||||
.card { padding: 18px; }
|
.card { padding: 18px; }
|
||||||
.auth-aside { padding: 28px 20px; min-height: 0; }
|
.auth-aside { padding: 28px 20px; min-height: 0; }
|
||||||
.wheel { width: 60%; }
|
.wheel { width: 60%; }
|
||||||
@@ -741,8 +764,6 @@ a.pair-row:hover strong { color: var(--gold); }
|
|||||||
.share-cta .btn { align-self: flex-start; }
|
.share-cta .btn { align-self: flex-start; }
|
||||||
|
|
||||||
/* Promo codes: redeeming (header, packages page, /bevaltas) and the admin page */
|
/* Promo codes: redeeming (header, packages page, /bevaltas) and the admin page */
|
||||||
.redeem-link { color: var(--ink-2); font-size: 13px; text-decoration: none; white-space: nowrap; }
|
|
||||||
.redeem-link:hover { color: var(--gold); text-decoration: underline; text-underline-offset: 3px; }
|
|
||||||
.redeem { display: flex; flex-direction: column; gap: 8px; }
|
.redeem { display: flex; flex-direction: column; gap: 8px; }
|
||||||
.redeem-row { display: flex; gap: 8px; flex-wrap: wrap; }
|
.redeem-row { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||||
.redeem-input { flex: 1 1 220px; width: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1.5px; text-transform: uppercase; }
|
.redeem-input { flex: 1 1 220px; width: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1.5px; text-transform: uppercase; }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useState } from "react";
|
|||||||
|
|
||||||
import { api } from "@/lib/api";
|
import { api } from "@/lib/api";
|
||||||
|
|
||||||
export function LogoutButton() {
|
export function LogoutButton({ className = "btn btn-sm", role }: { className?: string; role?: "menuitem" }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
async function logout() {
|
async function logout() {
|
||||||
@@ -20,7 +20,7 @@ export function LogoutButton() {
|
|||||||
router.refresh();
|
router.refresh();
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<button type="button" className="btn btn-sm" onClick={logout} disabled={busy}>
|
<button type="button" className={className} role={role} onClick={logout} disabled={busy}>
|
||||||
Kilépés
|
Kilépés
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import Link from "next/link";
|
|||||||
|
|
||||||
import type { Me } from "@/lib/types";
|
import type { Me } from "@/lib/types";
|
||||||
|
|
||||||
import { LogoutButton } from "./LogoutButton";
|
|
||||||
import { NavLinks } from "./NavLinks";
|
import { NavLinks } from "./NavLinks";
|
||||||
|
import { UserMenu } from "./UserMenu";
|
||||||
|
|
||||||
/** The mark: the orbit, the thread (an S, with the crossbar an f) and a star on the rim. */
|
/** The mark: the orbit, the thread (an S, with the crossbar an f) and a star on the rim. */
|
||||||
export function LogoMark({ className = "logo-mark" }: { className?: string }) {
|
export function LogoMark({ className = "logo-mark" }: { className?: string }) {
|
||||||
@@ -91,8 +91,6 @@ export function SiteHeader({ me }: { me: Me }) {
|
|||||||
{ href: "/osszevetesek", label: "Összevetések" },
|
{ href: "/osszevetesek", label: "Összevetések" },
|
||||||
{ href: "/kartyajoslas", label: "Kártyajóslás" },
|
{ href: "/kartyajoslas", label: "Kártyajóslás" },
|
||||||
{ href: "/csomagok", label: "Csomagok" },
|
{ href: "/csomagok", label: "Csomagok" },
|
||||||
...(me.invoice_count > 0 ? [{ href: "/szamlak", label: "Számláim" }] : []),
|
|
||||||
{ href: "/profil", label: "Profil" },
|
|
||||||
];
|
];
|
||||||
if (me.user.roles.includes("admin")) links.push({ href: "/admin", label: "Admin" });
|
if (me.user.roles.includes("admin")) links.push({ href: "/admin", label: "Admin" });
|
||||||
return (
|
return (
|
||||||
@@ -101,11 +99,7 @@ export function SiteHeader({ me }: { me: Me }) {
|
|||||||
<NavLinks links={links} />
|
<NavLinks links={links} />
|
||||||
<div className="who">
|
<div className="who">
|
||||||
<PackageBadge me={me} />
|
<PackageBadge me={me} />
|
||||||
<Link href="/bevaltas" className="redeem-link">
|
<UserMenu name={me.user.display_name || me.user.email} invoices={me.invoice_count > 0} />
|
||||||
Kód beváltása
|
|
||||||
</Link>
|
|
||||||
<span className="who-name">{me.user.display_name || me.user.email}</span>
|
|
||||||
<LogoutButton />
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
import { useEffect, useId, useRef, useState } from "react";
|
||||||
|
|
||||||
|
import { LogoutButton } from "./LogoutButton";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The account menu under the user's name (top right): profile, invoices,
|
||||||
|
* redeeming a code, logging out. Closes on a click outside, Escape, or
|
||||||
|
* moving to another page.
|
||||||
|
*/
|
||||||
|
export function UserMenu({ name, invoices }: { name: string; invoices: boolean }) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const box = useRef<HTMLDivElement>(null);
|
||||||
|
const button = useRef<HTMLButtonElement>(null);
|
||||||
|
const menuId = useId();
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
useEffect(() => setOpen(false), [pathname]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const outside = (e: PointerEvent) => {
|
||||||
|
if (box.current && !box.current.contains(e.target as Node)) setOpen(false);
|
||||||
|
};
|
||||||
|
document.addEventListener("pointerdown", outside);
|
||||||
|
return () => document.removeEventListener("pointerdown", outside);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
function keydown(e: React.KeyboardEvent) {
|
||||||
|
if (e.key === "Escape" && open) {
|
||||||
|
setOpen(false);
|
||||||
|
button.current?.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
{ href: "/profil", label: "Profil" },
|
||||||
|
...(invoices ? [{ href: "/szamlak", label: "Számláim" }] : []),
|
||||||
|
{ href: "/bevaltas", label: "Kód beváltása" },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="user-menu" ref={box} onKeyDown={keydown}>
|
||||||
|
<button
|
||||||
|
ref={button}
|
||||||
|
type="button"
|
||||||
|
className="who-name"
|
||||||
|
aria-expanded={open}
|
||||||
|
aria-controls={menuId}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
onClick={() => setOpen((o) => !o)}
|
||||||
|
>
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" className="who-icon">
|
||||||
|
<circle cx="12" cy="8" r="4" />
|
||||||
|
<path d="M4 20c1.5-4 4.5-6 8-6s6.5 2 8 6" />
|
||||||
|
</svg>
|
||||||
|
<span className="who-name-text">{name}</span>
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true" className="who-chevron">
|
||||||
|
<path d="M6 9l6 6 6-6" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
{open && (
|
||||||
|
<div id={menuId} className="user-menu-list" role="menu" aria-label="Fiók">
|
||||||
|
{items.map((item) => (
|
||||||
|
<Link
|
||||||
|
key={item.href}
|
||||||
|
href={item.href}
|
||||||
|
role="menuitem"
|
||||||
|
className="user-menu-item"
|
||||||
|
aria-current={pathname.startsWith(item.href) ? "page" : undefined}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
<LogoutButton className="user-menu-item user-menu-logout" role="menuitem" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user