Persons: other people's charts with package slots, list page, switcher
- 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:
@@ -330,3 +330,61 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.tabs { scroll-margin-top: 88px; }
|
||||
.tab-panel { padding-top: 20px; }
|
||||
@media (max-width: 640px) { .tab { padding: 12px 10px; font-size: 14px; } .tabs { scroll-margin-top: 120px; } }
|
||||
|
||||
/* Charts list, persons */
|
||||
.chart-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
|
||||
.chart-card {
|
||||
background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
.chart-card:hover { border-color: var(--line-2); }
|
||||
.chart-card-link, .chart-card-new { display: flex; flex-direction: column; gap: 6px; padding: 20px; color: inherit; text-decoration: none; flex: 1; }
|
||||
.chart-card-name { font-family: var(--font-display); font-size: 24px; font-weight: 600; color: var(--ink); }
|
||||
.chart-card-tag { margin: 0 20px 16px; font-size: 13px; color: var(--gold); }
|
||||
.chart-card-new { border-style: dashed; justify-content: center; align-items: flex-start; min-height: 150px; }
|
||||
.chart-card-new:hover { border-color: var(--gold); }
|
||||
.chart-card-plus { font-size: 28px; line-height: 1; color: var(--gold); }
|
||||
.sign-trio { display: flex; gap: 16px; margin-top: 8px; }
|
||||
.sign-trio > span { display: inline-flex; align-items: baseline; gap: 4px; }
|
||||
.sign-trio .sym:first-child, .trio-ac { color: var(--muted); font-size: 14px; }
|
||||
.trio-ac { font: 600 11px var(--font-body); letter-spacing: 0.3px; }
|
||||
.trio-sign { color: var(--gold); font-size: 20px; }
|
||||
.person-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 0 12px 12px; border-top: 1px solid var(--line); padding-top: 8px; margin: 0 8px; }
|
||||
.btn-danger { border-color: var(--danger); color: var(--danger); }
|
||||
.btn-danger:hover { background: rgba(242, 160, 160, 0.08); color: var(--danger); border-color: var(--danger); }
|
||||
.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
|
||||
.pack {
|
||||
display: flex; flex-direction: column; gap: 6px; align-items: flex-start; padding: 16px 18px;
|
||||
background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius);
|
||||
}
|
||||
.pack strong { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
|
||||
.pack .btn { margin-top: 8px; }
|
||||
|
||||
/* Chart switcher (the chart page title) */
|
||||
.switcher { position: relative; align-self: flex-start; }
|
||||
.switcher h1 { margin: 0; }
|
||||
.switcher-button {
|
||||
font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
|
||||
display: inline-flex; align-items: baseline; gap: 10px;
|
||||
}
|
||||
.switcher-button:hover .switcher-caret, .switcher-button[aria-expanded="true"] .switcher-caret { color: var(--gold); }
|
||||
.switcher-button:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 4px; }
|
||||
.switcher-caret { font-size: 0.55em; color: var(--muted); transition: color 0.15s; }
|
||||
.switcher-menu {
|
||||
position: absolute; z-index: 20; top: calc(100% + 8px); left: 0; min-width: 280px; max-width: min(360px, calc(100vw - 32px));
|
||||
background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
|
||||
padding: 6px; font-family: var(--font-body);
|
||||
}
|
||||
.switcher-menu ul { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
|
||||
.switcher-menu li a {
|
||||
display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 12px; min-height: 44px;
|
||||
border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 15px;
|
||||
}
|
||||
.switcher-menu li a strong { font-weight: 500; }
|
||||
.switcher-menu li a .muted { font-size: 13px; white-space: nowrap; }
|
||||
.switcher-menu li a:hover { background: var(--panel-2); }
|
||||
.switcher-menu li a[aria-current="page"] { background: var(--panel-2); }
|
||||
.switcher-menu li a[aria-current="page"] strong { color: var(--gold); }
|
||||
.switcher-foot { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); margin-top: 6px; padding: 10px 12px 6px; font-size: 14px; }
|
||||
.switcher-foot a { color: var(--gold); text-decoration: none; }
|
||||
.switcher-foot a:hover { text-decoration: underline; }
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { BirthForm } from "@/app/profil/BirthForm";
|
||||
import type { BirthData } from "@/lib/types";
|
||||
|
||||
export function EditPerson({
|
||||
id,
|
||||
name,
|
||||
initial,
|
||||
}: {
|
||||
id: string;
|
||||
name: string;
|
||||
initial: BirthData & { placeName: string | null; region: string | null };
|
||||
}) {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<BirthForm
|
||||
initial={initial}
|
||||
person={{ chartId: id, name }}
|
||||
onCancel={() => router.push("/kepletek")}
|
||||
onSaved={() => {
|
||||
router.push(`/kepletek/${id}`);
|
||||
router.refresh();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { Chart } from "@/lib/types";
|
||||
|
||||
import { EditPerson } from "./EditPerson";
|
||||
|
||||
export const metadata: Metadata = { title: "Adatok javítása" };
|
||||
|
||||
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
/** Correcting a person's birth data (within an hour of adding them; admins any time). */
|
||||
export default async function EditPersonPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const me = await requireMe(`/kepletek/${id}/javitas`);
|
||||
if (!UUID.test(id)) notFound();
|
||||
const chart = await backendGet<Chart>(`/v1/charts/${id}`);
|
||||
if (!chart || chart.kind !== "person") notFound();
|
||||
const editable =
|
||||
me.user.roles.includes("admin") || (chart.editable_until !== null && Date.parse(chart.editable_until) > Date.now());
|
||||
|
||||
return (
|
||||
<main className="page">
|
||||
<div className="page-head">
|
||||
<h1>{chart.label} adatai</h1>
|
||||
<p className="muted">
|
||||
A javítás után újraszámoljuk a képletet és a rövid összefoglalót.
|
||||
</p>
|
||||
</div>
|
||||
<section className="card" aria-label="Születési adatok">
|
||||
{editable ? (
|
||||
<EditPerson
|
||||
id={id}
|
||||
name={chart.label}
|
||||
initial={{
|
||||
...chart.birth_data,
|
||||
placeName: chart.chart.location.place?.name ?? null,
|
||||
region: chart.chart.location.place?.region ?? null,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<p className="muted">A személy születési adatai csak a felvételt követő egy órán belül javíthatók.</p>
|
||||
<Link href={`/kepletek/${id}`} className="btn" style={{ alignSelf: "flex-start" }}>
|
||||
Vissza a képlethez
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -3,12 +3,13 @@ import { notFound } from "next/navigation";
|
||||
|
||||
import { AspectGrid, AspectList, BigThree, PositionTables } from "@/components/ChartTables";
|
||||
import { ChartSummary } from "@/components/ChartSummary";
|
||||
import { ChartSwitcher } from "@/components/ChartSwitcher";
|
||||
import { DetailedAnalysis } from "@/components/DetailedAnalysis";
|
||||
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
|
||||
import { Tabs } from "@/components/Tabs";
|
||||
import { ASPECTS, ELEMENTS, MODALITIES, MOON_PHASES, countryName, formatBirthDate, pointName } from "@/lib/astro";
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { Analysis, Chart, PublicConfig } from "@/lib/types";
|
||||
import type { Analysis, Chart, ChartListItem, PublicConfig } from "@/lib/types";
|
||||
|
||||
export const metadata: Metadata = { title: "Képlet" };
|
||||
|
||||
@@ -21,11 +22,13 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
|
||||
const { id } = await params;
|
||||
const me = await requireMe(`/kepletek/${id}`);
|
||||
if (!UUID.test(id)) notFound();
|
||||
const [chart, analyses, config] = await Promise.all([
|
||||
const [chart, analyses, config, chartList] = await Promise.all([
|
||||
backendGet<Chart>(`/v1/charts/${id}`),
|
||||
backendGet<{ analyses: Analysis[] }>(`/v1/charts/${id}/analyses`),
|
||||
backendGet<PublicConfig>("/v1/config"),
|
||||
backendGet<{ charts: ChartListItem[] }>("/v1/charts"),
|
||||
]);
|
||||
const charts = chartList?.charts ?? [];
|
||||
if (!chart) notFound();
|
||||
const list = analyses?.analyses ?? [];
|
||||
const summary = list.find((a) => a.kind === "summary" && a.status !== "failed") ?? null;
|
||||
@@ -43,7 +46,13 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<div className="page-head">
|
||||
<h1>{chart.is_primary ? "Születési képletem" : chart.label}</h1>
|
||||
<ChartSwitcher
|
||||
title={chart.is_primary ? "Születési képletem" : chart.label}
|
||||
currentId={chart.id}
|
||||
own={charts.find((c) => c.is_primary) ?? null}
|
||||
persons={charts.filter((c) => c.kind === "person")}
|
||||
canAdd={me.persons.left !== 0}
|
||||
/>
|
||||
<p className="muted">
|
||||
{formatBirthDate(chart.birth_data.date)}
|
||||
{timeKnown ? `, ${result.time.local.slice(11, 16)} (UTC${result.time.utc_offset}${result.time.dst ? ", nyári idő" : ""})` : ", ismeretlen időpont"}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
|
||||
import { ChartCard } from "@/components/ChartCard";
|
||||
import { PersonActions } from "@/components/PersonActions";
|
||||
import { PersonPacks } from "@/components/PersonPacks";
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { ChartListItem, PublicConfig } from "@/lib/types";
|
||||
|
||||
export const metadata: Metadata = { title: "Képletek" };
|
||||
|
||||
/** The user's own chart and the persons they added, with room for a new one. */
|
||||
export default async function ChartsPage() {
|
||||
const me = await requireMe("/kepletek");
|
||||
const [list, config] = await Promise.all([
|
||||
backendGet<{ charts: ChartListItem[] }>("/v1/charts"),
|
||||
backendGet<PublicConfig>("/v1/config"),
|
||||
]);
|
||||
const charts = list?.charts ?? [];
|
||||
const own = charts.find((c) => c.is_primary);
|
||||
const persons = charts.filter((c) => c.kind === "person");
|
||||
const isAdmin = me.user.roles.includes("admin");
|
||||
const slots = me.persons;
|
||||
const full = slots.left === 0;
|
||||
const now = Date.now();
|
||||
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1080 }}>
|
||||
<div className="page-head">
|
||||
<h1>Képletek</h1>
|
||||
<p className="muted">A saját képleted és azoké, akiket felvettél: mindegyikhez kérhetsz részletes elemzést.</p>
|
||||
</div>
|
||||
|
||||
<div className="chart-cards">
|
||||
{own ? (
|
||||
<ChartCard chart={own} title="Én">
|
||||
<span className="chart-card-tag">Saját képletem</span>
|
||||
</ChartCard>
|
||||
) : (
|
||||
<Link href="/profil#birth" className="chart-card chart-card-new">
|
||||
<strong className="chart-card-name">Én</strong>
|
||||
<span className="muted">Add meg a születési adataidat a profilodban.</span>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{persons.map((p) => (
|
||||
<ChartCard key={p.id} chart={p} title={p.label}>
|
||||
<PersonActions
|
||||
id={p.id}
|
||||
name={p.label}
|
||||
editable={isAdmin || (p.editable_until !== null && Date.parse(p.editable_until) > now)}
|
||||
/>
|
||||
</ChartCard>
|
||||
))}
|
||||
|
||||
{!full && (
|
||||
<Link href="/kepletek/uj" className="chart-card chart-card-new">
|
||||
<span className="chart-card-plus" aria-hidden="true">
|
||||
+
|
||||
</span>
|
||||
<strong className="chart-card-name">Új személy</strong>
|
||||
<span className="muted">
|
||||
{slots.unlimited ? "Korlátlan számú személy" : `Még ${slots.left} személyt vehetsz fel`}
|
||||
</span>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!slots.unlimited && (
|
||||
<section className="card" aria-labelledby="slots-title">
|
||||
<div className="card-head">
|
||||
<h2 id="slots-title">Személyek</h2>
|
||||
<span className="badge">
|
||||
{slots.used} / {slots.limit} hely
|
||||
</span>
|
||||
</div>
|
||||
<p className="muted">
|
||||
{full
|
||||
? "Elfogytak a helyeid. Újabb személyhez válassz csomagot."
|
||||
: "A felvett személyek képletét és elemzéseit itt éred el. Egy törölt személy helye nem szabadul fel."}
|
||||
</p>
|
||||
<PersonPacks packSize={config?.person_pack_size ?? 5} canPay={config?.mock_payments ?? false} />
|
||||
</section>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { BirthForm } from "@/app/profil/BirthForm";
|
||||
|
||||
export function NewPerson() {
|
||||
const router = useRouter();
|
||||
return (
|
||||
<BirthForm
|
||||
initial={null}
|
||||
person={{}}
|
||||
onCancel={() => router.push("/kepletek")}
|
||||
onSaved={(id) => router.push(`/kepletek/${id}`)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
import { PersonPacks } from "@/components/PersonPacks";
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { PublicConfig } from "@/lib/types";
|
||||
|
||||
import { NewPerson } from "./NewPerson";
|
||||
|
||||
export const metadata: Metadata = { title: "Új személy" };
|
||||
|
||||
export default async function NewPersonPage() {
|
||||
const me = await requireMe("/kepletek/uj");
|
||||
const config = await backendGet<PublicConfig>("/v1/config");
|
||||
const slots = me.persons;
|
||||
|
||||
return (
|
||||
<main className="page">
|
||||
<div className="page-head">
|
||||
<h1>Új személy</h1>
|
||||
<p className="muted">
|
||||
Társad, családtagod, barátod: a születési adataiból elkészül a képlete és egy rövid összefoglaló.
|
||||
{!slots.unlimited && slots.left !== null && slots.left > 0 && ` Még ${slots.left} személyt vehetsz fel.`}
|
||||
</p>
|
||||
</div>
|
||||
<section className="card" aria-label="Születési adatok">
|
||||
{slots.left === 0 ? (
|
||||
<>
|
||||
<p className="muted">Elfogytak a helyeid. Újabb személyhez válassz csomagot.</p>
|
||||
<PersonPacks packSize={config?.person_pack_size ?? 5} canPay={config?.mock_payments ?? false} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<NewPerson />
|
||||
<p className="hint">Az adatokat a felvételt követő egy órán belül még javíthatod, utána nem módosíthatók.</p>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -16,15 +16,22 @@ const ERRORS: Record<string, string> = {
|
||||
invalid_date: "Érvénytelen dátum.",
|
||||
};
|
||||
|
||||
/** Someone else's chart: added with a name, or (with `chartId`) corrected. */
|
||||
export type PersonTarget = { chartId?: string; name?: string };
|
||||
|
||||
export function BirthForm({
|
||||
initial,
|
||||
person,
|
||||
onCancel,
|
||||
onSaved,
|
||||
}: {
|
||||
initial: Initial;
|
||||
/** Not given: the user's own birth data. */
|
||||
person?: PersonTarget;
|
||||
onCancel?: () => void;
|
||||
onSaved: (chartId: string) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(person?.name ?? "");
|
||||
const [date, setDate] = useState(initial?.date ?? "");
|
||||
const [time, setTime] = useState(initial?.time?.slice(0, 5) ?? "");
|
||||
const [timeUnknown, setTimeUnknown] = useState(initial ? !initial.time : false);
|
||||
@@ -49,24 +56,29 @@ export function BirthForm({
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
if (person && !name.trim()) return setError("Add meg a nevét.");
|
||||
if (!date) return setError("Add meg a születési dátumot.");
|
||||
if (!timeUnknown && !time) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod.");
|
||||
if (!place) return setError("Válaszd ki a születési helyet a listából.");
|
||||
setBusy(true);
|
||||
try {
|
||||
const saved = await api<{ id: string }>("/charts", {
|
||||
body: {
|
||||
label: "Saját képlet",
|
||||
is_primary: true,
|
||||
birth: {
|
||||
date,
|
||||
...(timeUnknown ? {} : { time }),
|
||||
country,
|
||||
geonames_id: place.geonames_id,
|
||||
...(ambiguous ? { ambiguous_time: ambiguity } : {}),
|
||||
},
|
||||
},
|
||||
});
|
||||
const birth = {
|
||||
date,
|
||||
...(timeUnknown ? {} : { time }),
|
||||
country,
|
||||
geonames_id: place.geonames_id,
|
||||
...(ambiguous ? { ambiguous_time: ambiguity } : {}),
|
||||
};
|
||||
const saved = person?.chartId
|
||||
? await api<{ id: string }>(`/charts/${person.chartId}`, {
|
||||
method: "PATCH",
|
||||
body: { label: name.trim(), birth },
|
||||
})
|
||||
: await api<{ id: string }>("/charts", {
|
||||
body: person
|
||||
? { label: name.trim(), is_primary: false, birth }
|
||||
: { label: "Saját képlet", is_primary: true, birth },
|
||||
});
|
||||
onSaved(saved.id);
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.code === "ambiguous_local_time") {
|
||||
@@ -84,6 +96,20 @@ export function BirthForm({
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} className="field" style={{ gap: 18 }} noValidate>
|
||||
{person && (
|
||||
<div className="field" style={{ maxWidth: 420 }}>
|
||||
<label htmlFor="person-name">Név</label>
|
||||
<input
|
||||
id="person-name"
|
||||
className="inp"
|
||||
value={name}
|
||||
maxLength={100}
|
||||
autoComplete="off"
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor="birth-date">Születési dátum</label>
|
||||
@@ -132,7 +158,7 @@ export function BirthForm({
|
||||
{ambiguous && (
|
||||
<fieldset className="field" style={{ border: 0, padding: 0, margin: 0 }}>
|
||||
<legend className="label" style={{ marginBottom: 8 }}>
|
||||
Melyik időpontban születtél?
|
||||
{person ? "Melyik időpontban született?" : "Melyik időpontban születtél?"}
|
||||
</legend>
|
||||
<label className="check">
|
||||
<input type="radio" name="ambiguity" checked={ambiguity === "earlier"} onChange={() => setAmbiguity("earlier")} />
|
||||
@@ -152,7 +178,7 @@ export function BirthForm({
|
||||
)}
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy}>
|
||||
{busy ? "Számolás…" : "Mentés és képlet számítása"}
|
||||
{busy ? "Számolás…" : person?.chartId ? "Javítás mentése" : "Mentés és képlet számítása"}
|
||||
</button>
|
||||
{onCancel && (
|
||||
<button type="button" className="btn btn-ghost" onClick={onCancel} disabled={busy}>
|
||||
|
||||
@@ -46,6 +46,10 @@ export default async function ProfilePage() {
|
||||
<dd>
|
||||
{me.analyses_left.natal} képlet, {me.analyses_left.synastry} szinasztria
|
||||
</dd>
|
||||
<dt>Személyek</dt>
|
||||
<dd>
|
||||
{me.persons.unlimited ? `${me.persons.used} felvéve, korlátlan` : `${me.persons.used} / ${me.persons.limit} hely`}
|
||||
</dd>
|
||||
<dt>Tag óta</dt>
|
||||
<dd>{formatDate(user.created_at)}</dd>
|
||||
</dl>
|
||||
|
||||
@@ -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" });
|
||||
|
||||
@@ -18,6 +18,15 @@ export interface Me {
|
||||
primary_chart_id: string | null;
|
||||
analyses_left: UnitBalance;
|
||||
birth_change: BirthChange;
|
||||
persons: PersonSlots;
|
||||
}
|
||||
|
||||
/** How many persons the user may still add (`left`/`limit` null: no limit). */
|
||||
export interface PersonSlots {
|
||||
used: number;
|
||||
limit: number | null;
|
||||
left: number | null;
|
||||
unlimited: boolean;
|
||||
}
|
||||
|
||||
/** Limit on changing the own birth data (the notice text comes from the backend). */
|
||||
@@ -41,6 +50,7 @@ export interface PublicConfig {
|
||||
password_login: boolean;
|
||||
password_min_length: number;
|
||||
mock_payments: boolean;
|
||||
person_pack_size: number;
|
||||
}
|
||||
|
||||
export interface Position {
|
||||
@@ -87,16 +97,33 @@ export interface BirthData {
|
||||
geonames_id?: number | null;
|
||||
}
|
||||
|
||||
export type ChartKind = "own" | "person";
|
||||
|
||||
export interface Chart {
|
||||
id: string;
|
||||
label: string;
|
||||
is_primary: boolean;
|
||||
kind: ChartKind;
|
||||
/** A person's birth data can be corrected until then (admins: any time). */
|
||||
editable_until: string | null;
|
||||
birth_data: BirthData;
|
||||
highlights: { sun: string | null; moon: string | null; ascendant: string | null; time_known: boolean };
|
||||
chart: ChartResult;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** A chart in the list (`GET /v1/charts`). */
|
||||
export interface ChartListItem {
|
||||
id: string;
|
||||
label: string;
|
||||
is_primary: boolean;
|
||||
kind: ChartKind;
|
||||
editable_until: string | null;
|
||||
birth: { date: string; time: string | null; place: string | null };
|
||||
highlights: Chart["highlights"];
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Analysis {
|
||||
id: string;
|
||||
kind: "natal" | "synastry" | "summary";
|
||||
|
||||
Reference in New Issue
Block a user