Paid detailed analyses with per-kind units; example analysis page
- Credits become analysis units (migration 0006): a natal analysis uses one 'natal' unit, a synastry analysis one 'synastry' unit. No monthly free credits, no model tiers: ANALYSIS_MODEL (default Opus 5.5) writes every paid analysis. Admins grant units per kind; the worker refunds the right unit on failure. - Chart page: the detailed analysis card (offer with units left and a confirmation, progress while writing, the finished six sections). - Public /pelda page: a full Opus analysis of a made-up chart, with the free summary and a login call to action. - The worker sends the JSON schema with properties in 'required' order. serde_json sorted them, so the title came after ~9000 tokens of text and Opus sometimes left it empty (3 failed attempts in a live test); with the order fixed the same analysis succeeded at the first try. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -6,7 +6,11 @@ import { api, errorText } from "@/lib/api";
|
||||
import { ROLE_LABELS, formatDate } from "@/lib/astro";
|
||||
import type { AdminUser, Role } from "@/lib/types";
|
||||
|
||||
const EDITABLE_ROLES: Role[] = ["user", "premium", "vip", "creator", "admin"];
|
||||
const EDITABLE_ROLES: Role[] = ["user", "creator", "admin"];
|
||||
const UNITS: { value: "natal" | "synastry"; label: string }[] = [
|
||||
{ value: "natal", label: "képlet" },
|
||||
{ value: "synastry", label: "szinasztria" },
|
||||
];
|
||||
|
||||
export function AdminUsers({ selfId }: { selfId: string }) {
|
||||
const [query, setQuery] = useState("");
|
||||
@@ -57,7 +61,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
|
||||
<tr>
|
||||
<th scope="col">Felhasználó</th>
|
||||
<th scope="col">Szerepkörök</th>
|
||||
<th scope="col">Kredit</th>
|
||||
<th scope="col">Részletes elemzések</th>
|
||||
<th scope="col">Képletek</th>
|
||||
<th scope="col">Regisztrált</th>
|
||||
<th scope="col">Utoljára belépett</th>
|
||||
@@ -84,6 +88,7 @@ function UserRow({ user, isSelf, onChange }: { user: AdminUser; isSelf: boolean;
|
||||
const [status, setStatus] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [delta, setDelta] = useState("");
|
||||
const [unit, setUnit] = useState<"natal" | "synastry">("natal");
|
||||
|
||||
async function toggleRole(role: Role, on: boolean) {
|
||||
const roles = on ? [...user.roles, role] : user.roles.filter((r) => r !== role);
|
||||
@@ -107,10 +112,13 @@ function UserRow({ user, isSelf, onChange }: { user: AdminUser; isSelf: boolean;
|
||||
setBusy(true);
|
||||
setStatus(null);
|
||||
try {
|
||||
await api(`/admin/users/${user.id}/credits`, { body: { delta: n, note: "admin" } });
|
||||
onChange({ ...user, credits: user.credits + n });
|
||||
const res = await api<{ analyses_left: AdminUser["analyses_left"] }>(`/admin/users/${user.id}/credits`, {
|
||||
body: { unit, delta: n, note: "admin" },
|
||||
});
|
||||
onChange({ ...user, analyses_left: res.analyses_left });
|
||||
setDelta("");
|
||||
setStatus({ ok: true, text: n > 0 ? `+${n} kredit` : `${n} kredit` });
|
||||
const label = UNITS.find((u) => u.value === unit)?.label;
|
||||
setStatus({ ok: true, text: `${n > 0 ? "+" : ""}${n} ${label}` });
|
||||
} catch (e) {
|
||||
setStatus({ ok: false, text: errorText(e) });
|
||||
} finally {
|
||||
@@ -149,18 +157,36 @@ function UserRow({ user, isSelf, onChange }: { user: AdminUser; isSelf: boolean;
|
||||
</td>
|
||||
<td>
|
||||
<form onSubmit={grant} className="row" style={{ gap: 6, flexWrap: "nowrap" }}>
|
||||
<span className="num" style={{ minWidth: 28 }}>
|
||||
{user.credits}
|
||||
<span className="num" style={{ minWidth: 92, fontSize: 13 }}>
|
||||
képlet {user.analyses_left.natal}
|
||||
<br />
|
||||
szinasztria {user.analyses_left.synastry}
|
||||
</span>
|
||||
<label className="sr-only" htmlFor={`unit-${user.id}`}>
|
||||
Elemzés fajtája
|
||||
</label>
|
||||
<select
|
||||
id={`unit-${user.id}`}
|
||||
className="inp"
|
||||
style={{ width: 118, minHeight: 36 }}
|
||||
value={unit}
|
||||
onChange={(e) => setUnit(e.target.value as "natal" | "synastry")}
|
||||
>
|
||||
{UNITS.map((u) => (
|
||||
<option key={u.value} value={u.value}>
|
||||
{u.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<label className="sr-only" htmlFor={`delta-${user.id}`}>
|
||||
Kredit jóváírása
|
||||
Jóváírt darabszám
|
||||
</label>
|
||||
<input
|
||||
id={`delta-${user.id}`}
|
||||
className="inp"
|
||||
style={{ width: 76, minHeight: 36 }}
|
||||
inputMode="numeric"
|
||||
placeholder="+10"
|
||||
placeholder="+1"
|
||||
value={delta}
|
||||
onChange={(e) => setDelta(e.target.value)}
|
||||
/>
|
||||
|
||||
@@ -15,7 +15,7 @@ export default async function AdminPage() {
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<div className="page-head">
|
||||
<h1>Felhasználók</h1>
|
||||
<p className="muted">Szerepkörök és kreditek kezelése. A prémium és a VIP szerepkör nyitja meg a drágább elemző modelleket.</p>
|
||||
<p className="muted">Szerepkörök kezelése és részletes elemzések jóváírása (ajándék, reklamáció). A vásárlások is ide könyvelődnek majd.</p>
|
||||
</div>
|
||||
<AdminUsers selfId={me.user.id} />
|
||||
</main>
|
||||
|
||||
@@ -147,6 +147,21 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.tagline { font-family: var(--font-display); font-size: 36px; font-weight: 600; line-height: 1.1; }
|
||||
.gsi-slot { min-height: 44px; display: flex; justify-content: center; }
|
||||
|
||||
/* Detailed analysis */
|
||||
.analysis-card { gap: 14px; }
|
||||
.analysis { display: flex; flex-direction: column; gap: 28px; max-width: 72ch; }
|
||||
.analysis-head { display: flex; flex-direction: column; gap: 12px; }
|
||||
.analysis-head h2 { font-size: 34px; }
|
||||
.analysis-lead { font-size: 17px; line-height: 1.7; color: var(--ink-2); font-style: italic; }
|
||||
.analysis-section { display: flex; flex-direction: column; gap: 12px; }
|
||||
.analysis-section h3 { font-size: 24px; color: var(--gold); }
|
||||
.analysis-section p, .analysis-lists li { font-size: 16px; line-height: 1.75; color: var(--ink-2); }
|
||||
.analysis strong { color: var(--ink); font-weight: 600; }
|
||||
.analysis-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; }
|
||||
.analysis-lists h3 { font-size: 22px; margin-bottom: 8px; }
|
||||
.analysis-lists ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.analysis-advice { border-top: 1px solid var(--line); padding-top: 24px; }
|
||||
|
||||
/* Chart page */
|
||||
.summary-card { gap: 10px; border-color: rgba(217, 180, 106, 0.35); }
|
||||
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); }
|
||||
|
||||
@@ -4,6 +4,7 @@ import { notFound } from "next/navigation";
|
||||
|
||||
import { BigThree, ChartTables } from "@/components/ChartTables";
|
||||
import { ChartSummary } from "@/components/ChartSummary";
|
||||
import { DetailedAnalysis } from "@/components/DetailedAnalysis";
|
||||
import { ChartWheel } from "@/components/ChartWheel";
|
||||
import { ELEMENTS, MODALITIES, MOON_PHASES, countryName, formatBirthDate, pointName } from "@/lib/astro";
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
@@ -16,14 +17,17 @@ 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;
|
||||
await requireMe(`/kepletek/${id}`);
|
||||
const me = await requireMe(`/kepletek/${id}`);
|
||||
if (!UUID.test(id)) notFound();
|
||||
const [chart, analyses] = await Promise.all([
|
||||
backendGet<Chart>(`/v1/charts/${id}`),
|
||||
backendGet<{ analyses: Analysis[] }>(`/v1/charts/${id}/analyses`),
|
||||
]);
|
||||
if (!chart) notFound();
|
||||
const summary = analyses?.analyses.find((a) => a.kind === "summary" && a.status !== "failed") ?? null;
|
||||
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;
|
||||
@@ -110,6 +114,8 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<DetailedAnalysis chartId={chart.id} initial={detailed} left={me.analyses_left.natal} />
|
||||
|
||||
<section className="card" aria-labelledby="positions">
|
||||
<h2 id="positions">Pozíciók</h2>
|
||||
<ChartTables chart={chart} />
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
|
||||
import { AnalysisView } from "@/components/AnalysisView";
|
||||
import { ChartWheel } from "@/components/ChartWheel";
|
||||
import { Rich } from "@/components/Rich";
|
||||
import { Logo } from "@/components/SiteHeader";
|
||||
import example from "@/content/pelda.json";
|
||||
import { getMe } from "@/lib/server";
|
||||
import type { AnalysisContent, ChartResult } from "@/lib/types";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Példaelemzés",
|
||||
description: "Így néz ki egy részletes Sorsfonalak-elemzés: egy kitalált születési képlet teljes értelmezése.",
|
||||
};
|
||||
|
||||
/** A full example analysis of a made-up chart, for visitors and free users. */
|
||||
export default async function ExamplePage() {
|
||||
const me = await getMe();
|
||||
const chart = example.chart as unknown as ChartResult;
|
||||
return (
|
||||
<>
|
||||
{!me && (
|
||||
<header className="site-header">
|
||||
<Logo />
|
||||
</header>
|
||||
)}
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">Példaelemzés</span>
|
||||
<h1>Így néz ki egy részletes elemzés</h1>
|
||||
<p className="muted">
|
||||
A képlet kitalált ({example.birth}). A saját képletednél ugyanígy készül: a rövid összefoglaló ingyenes, a
|
||||
részletes elemzés fizetős.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<section className="chart-layout" aria-label="A példa képlete">
|
||||
<div className="card chart-wheel-card">
|
||||
<ChartWheel chart={chart} timeKnown />
|
||||
</div>
|
||||
<div className="field" style={{ gap: 16 }}>
|
||||
<section className="card summary-card" aria-labelledby="example-summary">
|
||||
<span className="eyebrow">Röviden · ingyenes</span>
|
||||
<h2 id="example-summary" className="summary-title">
|
||||
{example.summary.title}
|
||||
</h2>
|
||||
<p className="summary-text">
|
||||
<Rich text={example.summary.summary} />
|
||||
</p>
|
||||
</section>
|
||||
<div className="card" style={{ gap: 12 }}>
|
||||
<p>
|
||||
{me ? "Nézd meg a saját képletedet és az ingyenes összefoglalódat." : "Lépj be Google-fiókkal, add meg a születési adataidat, és ingyen megkapod a saját rövid összefoglalódat."}
|
||||
</p>
|
||||
<div className="form-actions">
|
||||
<Link href={me ? "/keplet" : "/belepes?vissza=/keplet"} className="btn btn-primary">
|
||||
{me ? "A saját képletem" : "Belépés és saját képlet"}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="card analysis-card" aria-label="Részletes példaelemzés">
|
||||
<span className="eyebrow">Részletes elemzés · fizetős</span>
|
||||
<AnalysisView content={example.analysis as AnalysisContent} />
|
||||
</section>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -42,8 +42,10 @@ export default async function ProfilePage() {
|
||||
</dd>
|
||||
<dt>Belépés</dt>
|
||||
<dd>{me.providers.map((p) => PROVIDERS[p] ?? p).join(", ") || "–"}</dd>
|
||||
<dt>Kreditek</dt>
|
||||
<dd>{me.credits}</dd>
|
||||
<dt>Részletes elemzések</dt>
|
||||
<dd>
|
||||
{me.analyses_left.natal} képlet, {me.analyses_left.synastry} szinasztria
|
||||
</dd>
|
||||
<dt>Tag óta</dt>
|
||||
<dd>{formatDate(user.created_at)}</dd>
|
||||
</dl>
|
||||
|
||||
Reference in New Issue
Block a user