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)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user