Detailed analysis button, loading wheel, birth data change limits
Backend: - own birth data: three corrections within an hour of the first save, then one change per 24 hours (birth_data_changes); 429 birth_data_change_limit with the user-facing message; /v1/me birth_change shows the notice; admins are not limited - admins get detailed analyses free (no unit spent) - POST /v1/payments/mock (MOCK_PAYMENTS): stand-in payment that adds a unit, until Stripe is connected; on in the compose files for now Frontend: - detailed analysis offer: admin starts it free, users with units confirm, others go through the (stand-in) payment step - turning wheel with elapsed time while the summary or the analysis is being written - no "adatok javítása" on the chart page (only in the profile), limit notice there; wheel hover highlighting removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -6,27 +6,35 @@ import { useEffect, useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import type { Analysis } from "@/lib/types";
|
||||
|
||||
import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { AnalysisView } from "./AnalysisView";
|
||||
|
||||
const POLL_MS = 5000;
|
||||
const MAX_POLLS = 120; // 10 minutes
|
||||
|
||||
type Step = "offer" | "confirm" | "pay";
|
||||
|
||||
/**
|
||||
* The paid detailed analysis of a chart: offer (with the units left),
|
||||
* confirmation, progress while the worker writes it, and the finished text.
|
||||
* The detailed analysis of a chart. A saved one is shown at once; otherwise
|
||||
* the offer: admins start it free, users with units confirm, others pay
|
||||
* (a stand-in payment for now). While the worker writes it, a loading wheel.
|
||||
*/
|
||||
export function DetailedAnalysis({
|
||||
chartId,
|
||||
initial,
|
||||
left,
|
||||
isAdmin,
|
||||
canPay,
|
||||
}: {
|
||||
chartId: string;
|
||||
initial: Analysis | null;
|
||||
left: number;
|
||||
isAdmin: boolean;
|
||||
/** The stand-in payment is on (MOCK_PAYMENTS). */
|
||||
canPay: boolean;
|
||||
}) {
|
||||
const [analysis, setAnalysis] = useState<Analysis | null>(initial);
|
||||
const [remaining, setRemaining] = useState(left);
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const [step, setStep] = useState<Step>("offer");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const waiting = analysis?.status === "pending" || analysis?.status === "running";
|
||||
@@ -54,14 +62,13 @@ export function DetailedAnalysis({
|
||||
};
|
||||
}, [waiting, analysis]);
|
||||
|
||||
async function request() {
|
||||
async function start(pay: boolean) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const next = await api<Analysis>(`/charts/${chartId}/analyses`, { method: "POST" });
|
||||
setAnalysis(next);
|
||||
if (next.credits_charged > 0) setRemaining((n) => n - 1);
|
||||
setConfirming(false);
|
||||
if (pay) await api("/payments/mock", { body: { unit: "natal" } });
|
||||
setAnalysis(await api<Analysis>(`/charts/${chartId}/analyses`, { method: "POST" }));
|
||||
setStep("offer");
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
@@ -78,67 +85,97 @@ export function DetailedAnalysis({
|
||||
);
|
||||
}
|
||||
|
||||
if (waiting) {
|
||||
return (
|
||||
<section className="card analysis-card" aria-label="Részletes elemzés" aria-busy="true">
|
||||
<span className="eyebrow">Részletes elemzés</span>
|
||||
<AnalysisLoading
|
||||
title="Készül az elemzésed"
|
||||
text="Most íródik a hat fejezet a képleted alapján. Ez általában 1–3 perc; nyugodtan elhagyhatod az oldalt, az elemzés elkészül és itt vár."
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card analysis-card" aria-labelledby="detailed-title" aria-busy={waiting}>
|
||||
<section className="card analysis-card" aria-labelledby="detailed-title">
|
||||
<span className="eyebrow">Részletes elemzés</span>
|
||||
{waiting ? (
|
||||
<>
|
||||
<h2 id="detailed-title">Készül az elemzésed</h2>
|
||||
<p className="muted" role="status">
|
||||
A mesterséges intelligencia most írja meg a hat fejezetet a képleted alapján. Ez általában 1–2 perc; nyugodtan
|
||||
elhagyhatod az oldalt, az elemzés elkészül és itt vár.
|
||||
</p>
|
||||
<div className="skeleton" aria-hidden="true">
|
||||
<span />
|
||||
<span />
|
||||
<span />
|
||||
<h2 id="detailed-title">Az egész képleted, fejezetekre bontva</h2>
|
||||
<p className="muted">
|
||||
Kb. 1500 szó hat fejezetben: személyiség, érzelmek, gondolkodás, szerelem és kapcsolatok, hivatás, fejlődési út.
|
||||
A végén erősségek, kihívások és útravaló. Csak a képleted pozíciói alapján készül.
|
||||
</p>
|
||||
{analysis?.status === "failed" && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
Az előző kérés nem sikerült{isAdmin ? "" : ", az elemzést visszaadtuk a keretedbe"}. Próbáld újra.
|
||||
</p>
|
||||
)}
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{isAdmin ? (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => start(false)} disabled={busy}>
|
||||
{busy ? "Indítás…" : "Részletes elemzés készítése"}
|
||||
</button>
|
||||
<span className="hint">Adminként ingyenes.</span>
|
||||
</div>
|
||||
) : left > 0 ? (
|
||||
step === "confirm" ? (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => start(false)} disabled={busy}>
|
||||
{busy ? "Indítás…" : "Igen, kérem az elemzést"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setStep("offer")} disabled={busy}>
|
||||
Mégse
|
||||
</button>
|
||||
<span className="hint">Ez felhasznál 1-et a {left} képletelemzésedből.</span>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<h2 id="detailed-title">Az egész képleted, fejezetekre bontva</h2>
|
||||
<p className="muted">
|
||||
Kb. 1500 szó hat fejezetben: személyiség, érzelmek, gondolkodás, szerelem és kapcsolatok, hivatás, fejlődési
|
||||
út. A végén erősségek, kihívások és útravaló. Csak a képleted pozíciói alapján készül.
|
||||
</p>
|
||||
{analysis?.status === "failed" && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
Az előző kérés nem sikerült, az elemzést visszaadtuk a keretedbe. Próbáld újra.
|
||||
</p>
|
||||
)}
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{remaining > 0 ? (
|
||||
confirming ? (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={request} disabled={busy}>
|
||||
{busy ? "Indítás…" : "Igen, kérem az elemzést"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setConfirming(false)} disabled={busy}>
|
||||
Mégse
|
||||
</button>
|
||||
<span className="hint">Ez felhasznál 1-et a {remaining} képletelemzésedből.</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => setConfirming(true)}>
|
||||
Részletes elemzés kérése
|
||||
</button>
|
||||
<span className="hint">Még {remaining} képletelemzésed van.</span>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div className="form-actions">
|
||||
<Link href="/pelda" className="btn">
|
||||
Példa megtekintése
|
||||
</Link>
|
||||
<span className="hint">A részletes elemzés fizetős; a csomagok hamarosan elérhetők.</span>
|
||||
) : (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => setStep("confirm")}>
|
||||
Részletes elemzés kérése
|
||||
</button>
|
||||
<span className="hint">Még {left} képletelemzésed van.</span>
|
||||
</div>
|
||||
)
|
||||
) : canPay ? (
|
||||
step === "pay" ? (
|
||||
<div className="pay-box">
|
||||
<div className="pay-line">
|
||||
<span>Részletes képletelemzés</span>
|
||||
<strong>1 db</strong>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => start(true)} disabled={busy}>
|
||||
{busy ? "Fizetés…" : "Fizetés"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setStep("offer")} disabled={busy}>
|
||||
Mégse
|
||||
</button>
|
||||
</div>
|
||||
<p className="hint">Tesztüzem: a fizetés még nincs bekötve, a gomb nem terhel semmit.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => setStep("pay")}>
|
||||
Részletes elemzés kérése
|
||||
</button>
|
||||
<Link href="/pelda" className="btn btn-ghost">
|
||||
Példa megtekintése
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div className="form-actions">
|
||||
<Link href="/pelda" className="btn">
|
||||
Példa megtekintése
|
||||
</Link>
|
||||
<span className="hint">A részletes elemzés fizetős; a csomagok hamarosan elérhetők.</span>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user