Header shows the user's package and what is left of it
- /v1/me: `package` = the running unlimited package, or the latest main package bought or given (top-ups do not count; an ended unlimited not) - header badge: "Család · 11 elemzés", "Korlátlan · 2027. november 17-ig", "Páros · elfogyott"; links to the packages page, details in the tooltip Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { Me } from "@/lib/types";
|
||||
|
||||
import { LogoutButton } from "./LogoutButton";
|
||||
@@ -13,6 +14,41 @@ export function Logo() {
|
||||
);
|
||||
}
|
||||
|
||||
/** The user's package and what is left of it; leads to the packages page. */
|
||||
function PackageBadge({ me }: { me: Me }) {
|
||||
const { natal, synastry } = me.analyses_left;
|
||||
const left = natal + synastry;
|
||||
let name: string;
|
||||
let detail: string | null;
|
||||
if (me.unlimited_until) {
|
||||
name = "Korlátlan";
|
||||
detail = `${formatDate(me.unlimited_until).replace(/\.$/, "")}-ig`;
|
||||
} else if (me.package) {
|
||||
name = me.package.name;
|
||||
detail = left > 0 ? `${left} elemzés` : "elfogyott";
|
||||
} else if (left > 0) {
|
||||
name = `${left} elemzés`;
|
||||
detail = null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
const units = me.unlimited_until
|
||||
? "Korlátlan elemzés és összevetés"
|
||||
: `Képletelemzés: ${natal}, kapcsolati elemzés: ${synastry}`;
|
||||
const empty = !me.unlimited_until && left === 0;
|
||||
return (
|
||||
<Link
|
||||
href="/csomagok"
|
||||
className={empty ? "pkg-pill pkg-pill-empty" : "pkg-pill"}
|
||||
title={units}
|
||||
aria-label={`Csomagod: ${name}${detail ? `, ${detail}` : ""}. ${units}.`}
|
||||
>
|
||||
<span className="pkg-pill-name">{name}</span>
|
||||
{detail && <span className="pkg-pill-detail">{detail}</span>}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
export function SiteHeader({ me }: { me: Me }) {
|
||||
const links = [
|
||||
{ href: "/keplet", label: "Képletem" },
|
||||
@@ -27,7 +63,8 @@ export function SiteHeader({ me }: { me: Me }) {
|
||||
<Logo />
|
||||
<NavLinks links={links} />
|
||||
<div className="who">
|
||||
<span>{me.user.display_name || me.user.email}</span>
|
||||
<PackageBadge me={me} />
|
||||
<span className="who-name">{me.user.display_name || me.user.email}</span>
|
||||
<LogoutButton />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user