Persons: other people's charts with package slots, list page, switcher
CI / test (push) Failing after 43s
CI / build (push) Skipped
CI / deploy (push) Skipped

- charts.kind own/person; a new person uses a 'person' unit (not refunded
  on delete); person packages and an unlimited entitlement; admins unlimited
- a person's birth data can be corrected within an hour (admins any time)
- /kepletek list with tiles, /kepletek/uj, correction page, mock person
  packages, chart page title switches between charts keeping the tab

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 11:03:55 +00:00
co-authored by Claude Opus 5.5
parent 50875c0006
commit fef1605848
28 changed files with 1008 additions and 54 deletions
@@ -0,0 +1,43 @@
import Link from "next/link";
import { SIGNS, formatBirthDate } from "@/lib/astro";
import type { ChartListItem } from "@/lib/types";
/** Sun, Moon and Ascendant sign glyphs of a chart. */
export function SignTrio({ chart }: { chart: ChartListItem }) {
const h = chart.highlights;
const items: [string, string | null][] = [
["☉", h.sun],
["☽", h.moon],
["AC", h.time_known ? h.ascendant : null],
];
return (
<span className="sign-trio" aria-hidden="true">
{items.map(([k, sign]) => (
<span key={k}>
<span className={k === "AC" ? "trio-ac" : "sym"}>{k}</span>
<span className="sym trio-sign">{sign ? SIGNS[sign]?.glyph : "–"}</span>
</span>
))}
</span>
);
}
/** One chart in the list: name, birth date and place, the three main signs. */
export function ChartCard({ chart, title, children }: { chart: ChartListItem; title: string; children?: React.ReactNode }) {
const { birth } = chart;
return (
<div className="chart-card">
<Link href={`/kepletek/${chart.id}`} className="chart-card-link">
<strong className="chart-card-name">{title}</strong>
<span className="muted">
{formatBirthDate(birth.date)}
{birth.time ? `, ${birth.time.slice(0, 5)}` : ""}
{birth.place ? ` · ${birth.place}` : ""}
</span>
<SignTrio chart={chart} />
</Link>
{children}
</div>
);
}
@@ -0,0 +1,93 @@
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { formatBirthDate } from "@/lib/astro";
import type { ChartListItem } from "@/lib/types";
/**
* The chart page title as a menu of the user's charts. Switching keeps the
* open tab (#matrix etc.), so two people's charts are easy to compare.
*/
export function ChartSwitcher({
title,
currentId,
own,
persons,
canAdd,
}: {
title: string;
currentId: string;
own: ChartListItem | null;
persons: ChartListItem[];
canAdd: boolean;
}) {
const router = useRouter();
const [open, setOpen] = useState(false);
const root = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!open) return;
const close = (e: MouseEvent | KeyboardEvent) => {
if (e instanceof KeyboardEvent ? e.key === "Escape" : !root.current?.contains(e.target as Node)) setOpen(false);
};
document.addEventListener("mousedown", close);
document.addEventListener("keydown", close);
return () => {
document.removeEventListener("mousedown", close);
document.removeEventListener("keydown", close);
};
}, [open]);
function go(e: React.MouseEvent, id: string) {
e.preventDefault();
setOpen(false);
router.push(`/kepletek/${id}${window.location.hash}`);
}
const items = [...(own ? [{ chart: own, name: "Én" }] : []), ...persons.map((p) => ({ chart: p, name: p.label }))];
return (
<div className="switcher" ref={root}>
<h1>
<button
type="button"
className="switcher-button"
aria-haspopup="true"
aria-expanded={open}
onClick={() => setOpen((o) => !o)}
>
{title}
<span className="switcher-caret" aria-hidden="true">
▾
</span>
<span className="sr-only">: másik képlet választása</span>
</button>
</h1>
{open && (
<div className="switcher-menu">
<ul>
{items.map(({ chart, name }) => (
<li key={chart.id}>
<a
href={`/kepletek/${chart.id}`}
aria-current={chart.id === currentId ? "page" : undefined}
onClick={(e) => go(e, chart.id)}
>
<strong>{name}</strong>
<span className="muted">{formatBirthDate(chart.birth.date)}</span>
</a>
</li>
))}
</ul>
<div className="switcher-foot">
{canAdd && <Link href="/kepletek/uj">+ Új személy</Link>}
<Link href="/kepletek">Összes képlet</Link>
</div>
</div>
)}
</div>
);
}
@@ -0,0 +1,59 @@
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
/** Correct (while allowed) or delete a person. */
export function PersonActions({ id, name, editable }: { id: string; name: string; editable: boolean }) {
const router = useRouter();
const [confirm, setConfirm] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function remove() {
setBusy(true);
setError(null);
try {
await api(`/charts/${id}`, { method: "DELETE" });
router.refresh();
} catch (e) {
setError(errorText(e));
setBusy(false);
}
}
return (
<div className="person-actions">
{confirm ? (
<>
<span className="hint">Törlöd {name} képletét és elemzéseit? A hely nem szabadul fel.</span>
<button type="button" className="btn btn-sm btn-danger" onClick={remove} disabled={busy}>
{busy ? "Törlés…" : "Igen, törlöm"}
</button>
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setConfirm(false)} disabled={busy}>
Mégse
</button>
</>
) : (
<>
{editable && (
<Link href={`/kepletek/${id}/javitas`} className="btn btn-sm btn-ghost">
Adatok javítása
</Link>
)}
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setConfirm(true)}>
Törlés
</button>
</>
)}
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
</div>
);
}
@@ -0,0 +1,64 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
/**
* Person packages: a few more persons, or any number. Until Stripe is
* connected the payment is a stand-in (MOCK_PAYMENTS) that grants it at once.
*/
export function PersonPacks({ packSize, canPay }: { packSize: number; canPay: boolean }) {
const router = useRouter();
const [busy, setBusy] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
async function buy(pkg: "persons" | "persons_unlimited") {
setBusy(pkg);
setError(null);
try {
await api("/payments/mock", { body: { package: pkg } });
router.refresh();
} catch (e) {
setError(errorText(e));
} finally {
setBusy(null);
}
}
if (!canPay) {
return <p className="hint">További személyekhez csomag kell; a csomagok hamarosan elérhetők.</p>;
}
return (
<div className="field" style={{ gap: 12 }}>
<div className="packs">
<div className="pack">
<strong>+{packSize} személy</strong>
<span className="muted">Még {packSize} ember képlete és elemzése.</span>
<button type="button" className="btn btn-primary btn-sm" onClick={() => buy("persons")} disabled={busy !== null}>
{busy === "persons" ? "Fizetés…" : "Fizetés"}
</button>
</div>
<div className="pack">
<strong>Korlátlan</strong>
<span className="muted">Bárkit felvehetsz, nincs felső határ.</span>
<button
type="button"
className="btn btn-primary btn-sm"
onClick={() => buy("persons_unlimited")}
disabled={busy !== null}
>
{busy === "persons_unlimited" ? "Fizetés…" : "Fizetés"}
</button>
</div>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<p className="hint">Tesztüzem: a fizetés még nincs bekötve, a gomb nem terhel semmit.</p>
</div>
);
}
@@ -15,7 +15,7 @@ export function Logo() {
export function SiteHeader({ me }: { me: Me }) {
const links = [
{ href: "/keplet", label: "Képletem" },
{ href: "/kepletek", label: "Képletek" },
{ href: "/profil", label: "Profil" },
];
if (me.user.roles.includes("admin")) links.push({ href: "/admin", label: "Admin" });