Files
sorsfonalak/services/frontend/src/components/PackageCards.tsx
T
fecoandClaude Opus 5.5 6d2ad4aa0c
CI / test (push) Successful in 53s
CI / build (push) Successful in 6m41s
CI / deploy (push) Skipped
Drop the unlimited package, new prices, AI quality note
- The unlimited package is gone (easy to resell, e.g. by an astrologer):
  catalog, fair-use cap, UNLIMITED_DAILY_LIMIT, /v1/me unlimited_until,
  admin badge. Migration 0014 removes the 'unlimited' entitlements; old
  orders of it are skipped in the header.
- New prices: single 2 000 Ft, couple 4 500, family 8 000, +1 synastry
  2 500, +5 persons 1 500 (list prices 2 000 / 2 500 / 300).
- Login page, packages page and the analysis offer say the analyses are
  written by top AI models, close to a professional astrologer's written
  reading, for a fraction of the price (the packages page names the model).

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

169 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { api, errorText } from "@/lib/api";
import type { Package } from "@/lib/types";
export const huf = (n: number) => `${n.toLocaleString("hu-HU")} Ft`;
/** What a package contains, as short lines. */
export function contents(p: Package): string[] {
const lines: string[] = [];
if (p.natal) lines.push(`${p.natal} részletes képletelemzés`);
if (p.synastry) lines.push(`${p.synastry} kapcsolati elemzés`);
if (p.persons) lines.push(`${p.persons} személy felvétele`);
return lines;
}
/**
* Package cards with a buy button. Bigger packages show what they save and
* how little more they cost than the previous one. Until Stripe is connected
* the payment is a stand-in (MOCK_PAYMENTS) that grants the package at once.
*/
export function PackageCards({
packages,
ids,
canPay,
compact = false,
onBought,
}: {
packages: Package[];
/** Which packages, in this order (default: the main ladder). */
ids?: string[];
canPay: boolean;
compact?: boolean;
/** After a purchase (default: reload the page data). */
onBought?: (p: Package) => Promise<void> | void;
}) {
const router = useRouter();
const [busy, setBusy] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [done, setDone] = useState<string | null>(null);
const shown = ids
? ids.map((id) => packages.find((p) => p.id === id)).filter((p): p is Package => p !== undefined)
: packages.filter((p) => p.tier === "main");
async function buy(p: Package) {
setBusy(p.id);
setError(null);
setDone(null);
try {
await api("/payments/mock", { body: { package: p.id } });
if (onBought) await onBought(p);
else {
setDone(p.name);
router.refresh();
}
} catch (e) {
setError(errorText(e));
} finally {
setBusy(null);
}
}
return (
<div className="field" style={{ gap: 12 }}>
<div className={compact ? "pkg-grid pkg-grid-compact" : "pkg-grid"}>
{shown.map((p, i) => {
const prev = i > 0 ? shown[i - 1] : null;
const step = prev && p.tier === "main" && prev.tier === "main" ? p.price_huf - prev.price_huf : null;
return (
<article key={p.id} className={p.badge ? "pkg pkg-featured" : "pkg"} aria-labelledby={`pkg-${p.id}`}>
<div className="pkg-tags">
{p.badge && <span className="pkg-badge">{p.badge}</span>}
{p.savings_percent ? <span className="pkg-save">−{p.savings_percent}%</span> : null}
</div>
<h3 id={`pkg-${p.id}`} className="pkg-name">
{p.name}
</h3>
{!compact && <p className="muted pkg-tagline">{p.tagline}</p>}
<div className="pkg-price">
<strong>{huf(p.price_huf)}</strong>
{p.list_price_huf > p.price_huf && (
<s className="hint" aria-label={`Külön megvéve ${huf(p.list_price_huf)}`}>
{huf(p.list_price_huf)}
</s>
)}
</div>
<ul className="pkg-list">
{contents(p).map((line) => (
<li key={line}>{line}</li>
))}
</ul>
<p className="hint pkg-per">
{p.per_analysis_huf ? `Elemzésenként ${huf(p.per_analysis_huf)}` : " "}
</p>
{step !== null && step > 0 && prev && (
<p className="pkg-step">
Csak +{huf(step)} a(z) {prev.name} csomaghoz képest
</p>
)}
{canPay ? (
<button
type="button"
className={p.badge ? "btn btn-primary" : "btn"}
onClick={() => buy(p)}
disabled={busy !== null}
>
{busy === p.id ? "Fizetés…" : "Megveszem"}
</button>
) : (
<button type="button" className="btn" disabled>
Hamarosan
</button>
)}
</article>
);
})}
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{done && (
<p className="msg msg-ok" role="status">
A(z) {done} csomag jóváírva.
</p>
)}
{canPay && <p className="hint">Tesztüzem: a fizetés még nincs bekötve, a gomb nem terhel semmit.</p>}
</div>
);
}
/** Loads the catalog in the browser (for choosers inside other components). */
export function usePackages(): Package[] | null {
const [packages, setPackages] = useState<Package[] | null>(null);
useEffect(() => {
api<{ packages: Package[] }>("/packages")
.then((d) => setPackages(d.packages))
.catch(() => setPackages([]));
}, []);
return packages;
}
/** A few packages to choose from, loaded on demand, with a link to all of them. */
export function PackageChooser({
ids,
canPay,
onBought,
}: {
ids: string[];
canPay: boolean;
onBought?: (p: Package) => Promise<void> | void;
}) {
const packages = usePackages();
if (packages === null) return <p className="muted">Csomagok betöltése…</p>;
return (
<div className="field" style={{ gap: 8 }}>
<PackageCards packages={packages} ids={ids} canPay={canPay} compact onBought={onBought} />
<Link href="/csomagok" className="hint">
Összes csomag és a részletek →
</Link>
</div>
);
}