Files
sorsfonalak/services/frontend/src/app/kepletek/[id]/page.tsx
T
fecoandClaude Opus 5.5 e004ea696b
CI / test (push) Successful in 47s
CI / build (push) Successful in 4m19s
CI / deploy (push) Skipped
Packages: from one analysis to unlimited, admin can give them
A fixed catalog (packages.rs, reasoning in docs/csomagok.md): Egy elemzés
2 990 Ft, Páros 6 990 Ft, Család 11 990 Ft (featured), Korlátlan 17 990 Ft
for a year, and two top-ups. Every grant is a package_orders row; units are
credit_ledger rows with reason 'package' and never expire. The unlimited
package is a time-limited 'unlimited' entitlement: analyses use no unit and
persons have no limit, with a daily fair-use cap (UNLIMITED_DAILY_LIMIT, 5);
buying it again extends it by a year.

- GET /v1/packages, mock payment by package id, /v1/me unlimited_until
- POST /v1/admin/users/{id}/packages: give a package as a gift
- /csomagok page; the paid step of an analysis offers three packages with
  the bigger one featured; person packs use the catalog; admin user list
  has a package column
- PERSON_PACK_SIZE is replaced by the catalog's +5 személy top-up

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-17 16:19:20 +00:00

195 lines
7.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Metadata } from "next";
import Link from "next/link";
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 { CompareButton } from "@/components/CompareButton";
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, ChartListItem, PublicConfig } from "@/lib/types";
export const metadata: Metadata = { title: "Képlet" };
const GRID_LEGEND = ["conjunction", "sextile", "square", "trine", "opposition"];
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
/** One saved chart: the wheel and the tables, read from the database (not recalculated). */
export default async function ChartPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const me = await requireMe(`/kepletek/${id}`);
if (!UUID.test(id)) notFound();
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 ?? [];
const persons = charts.filter((c) => c.kind === "person");
const own = charts.find((c) => c.is_primary) ?? null;
if (!chart) notFound();
const list = analyses?.analyses ?? [];
const summary = list.find((a) => a.kind === "summary" && a.status !== "failed") ?? null;
const natal = list.filter((a) => a.kind === "natal");
const detailed = natal.find((a) => a.status !== "failed") ?? natal[0] ?? null;
const result = chart.chart;
const timeKnown = chart.highlights.time_known;
const place = result.location.place;
const country = place?.country_code ?? chart.birth_data.country;
const elements = result.summary?.elements;
const modalities = result.summary?.modalities;
const phase = result.moon_phase;
return (
<main className="page" style={{ maxWidth: 1180 }}>
<div className="page-head">
<ChartSwitcher
title={chart.is_primary ? "Születési képletem" : chart.label}
currentId={chart.id}
own={own}
persons={persons}
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"}
{" · "}
{place?.name ?? chart.birth_data.place ?? "–"}
{country ? `, ${countryName(country)}` : ""}
</p>
</div>
<section className="chart-layout" aria-label="Képletrajz">
<div className="card chart-wheel-card">
<ChartWheel chart={result} timeKnown={timeKnown} />
<WheelLegend />
</div>
<div className="field chart-side">
<ChartSummary chartId={chart.id} initial={summary} detailedDone={detailed?.status === "done"} />
<BigThree chart={chart} />
{(elements || modalities || phase) && (
<div className="card" style={{ gap: 12 }}>
<dl className="facts">
{elements && (
<>
<dt>Elemek</dt>
<dd>
{Object.entries(elements)
.map(([k, v]) => `${ELEMENTS[k] ?? k} ${v.count}`)
.join(" · ")}
</dd>
</>
)}
{modalities && (
<>
<dt>Minőségek</dt>
<dd>
{Object.entries(modalities)
.map(([k, v]) => `${MODALITIES[k] ?? k} ${v.count}`)
.join(" · ")}
</dd>
</>
)}
{phase && (
<>
<dt>Holdfázis</dt>
<dd>
{MOON_PHASES[phase.phase] ?? phase.phase}, {Math.round(phase.illumination * 100)}%
</dd>
</>
)}
</dl>
{elements && (
<p className="hint">
Az elemek és minőségek a tíz bolygóból számolva:{" "}
{Object.entries(elements)
.filter(([, v]) => v.count > 0)
.map(([k, v]) => `${ELEMENTS[k] ?? k}: ${v.points.map(pointName).join(", ")}`)
.join("; ")}
.
</p>
)}
</div>
)}
{!chart.is_primary && own && (
<div className="card compare-tile">
<span className="eyebrow">Összevetés</span>
<strong>Te és {chart.label}</strong>
<span className="muted">Két képlet egy körön: mi vonz, hol súrlódtok, és mit ad a kapcsolat.</span>
<div className="form-actions">
<CompareButton chart1={own.id} chart2={chart.id} label="Összevetés velem" className="btn" />
</div>
</div>
)}
{chart.is_primary && (
<Link href="/szemelyek" className="card persons-tile">
<span className="eyebrow">Személyek</span>
<strong>
{persons.length > 0 ? `${persons.length} felvett személy` : "Társad, családod képlete"}
</strong>
<span className="muted">
{persons.length > 0
? persons.slice(0, 3).map((p) => p.label).join(", ") + (persons.length > 3 ? "…" : "")
: "Vedd fel őket, és nézd meg az ő képletüket és elemzésüket is."}
</span>
<span className="persons-tile-arrow" aria-hidden="true">
→
</span>
</Link>
)}
</div>
</section>
<section className="card chart-tabs" aria-label="Elemzés és táblázatok">
<Tabs
label="Képlet részletei"
tabs={[
{
id: "elemzes",
label: "Elemzés",
content: (
<DetailedAnalysis
target={{ kind: "natal", chartId: chart.id }}
initial={detailed}
left={me.analyses_left.natal}
isAdmin={me.user.roles.includes("admin")}
unlimited={me.unlimited_until !== null}
canPay={config?.mock_payments ?? false}
/>
),
},
{ id: "bolygok", label: "Bolygók", content: <PositionTables chart={chart} /> },
{
id: "matrix",
label: "Mátrix",
content: (
<div className="field" style={{ gap: 16 }}>
<AspectGrid chart={chart} />
<ul className="grid-legend" aria-label="Jelmagyarázat">
{GRID_LEGEND.map((k) => (
<li key={k}>
<span className={`sym asp asp-${k}`} aria-hidden="true">
{ASPECTS[k]?.glyph}
</span>{" "}
{ASPECTS[k]?.hu}
</li>
))}
</ul>
</div>
),
},
{ id: "reszletek", label: "Részletek", content: <AspectList chart={chart} /> },
]}
/>
</section>
</main>
);
}