Packages: from one analysis to unlimited, admin can give them
CI / test (push) Successful in 47s
CI / build (push) Successful in 4m19s
CI / deploy (push) Skipped

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
This commit is contained in:
feco
2026-11-17 16:19:20 +00:00
co-authored by Claude Opus 5.5
parent 0bd5c39080
commit e004ea696b
29 changed files with 1019 additions and 164 deletions
@@ -1,64 +1,8 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { PackageChooser } from "./PackageCards";
import { api, errorText } from "@/lib/api";
/**
* Person packages: a few more persons, or any number. Until Stripe is
* connected the payment is a stand-in (MOCK_PAYMENTS) that grants it at once.
*/
export function PersonPacks({ packSize, canPay }: { packSize: number; canPay: boolean }) {
const router = useRouter();
const [busy, setBusy] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
async function buy(pkg: "persons" | "persons_unlimited") {
setBusy(pkg);
setError(null);
try {
await api("/payments/mock", { body: { package: pkg } });
router.refresh();
} catch (e) {
setError(errorText(e));
} finally {
setBusy(null);
}
}
if (!canPay) {
return <p className="hint">További személyekhez csomag kell; a csomagok hamarosan elérhetők.</p>;
}
return (
<div className="field" style={{ gap: 12 }}>
<div className="packs">
<div className="pack">
<strong>+{packSize} személy</strong>
<span className="muted">Még {packSize} ember képlete és elemzése.</span>
<button type="button" className="btn btn-primary btn-sm" onClick={() => buy("persons")} disabled={busy !== null}>
{busy === "persons" ? "Fizetés…" : "Fizetés"}
</button>
</div>
<div className="pack">
<strong>Korlátlan</strong>
<span className="muted">Bárkit felvehetsz, nincs felső határ.</span>
<button
type="button"
className="btn btn-primary btn-sm"
onClick={() => buy("persons_unlimited")}
disabled={busy !== null}
>
{busy === "persons_unlimited" ? "Fizetés…" : "Fizetés"}
</button>
</div>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<p className="hint">Tesztüzem: a fizetés még nincs bekötve, a gomb nem terhel semmit.</p>
</div>
);
/** Packages that give more persons: a few more, the family package, or unlimited. */
export function PersonPacks({ canPay }: { canPay: boolean }) {
return <PackageChooser ids={["addon_persons", "family", "unlimited"]} canPay={canPay} />;
}