Packages: from one analysis to unlimited, admin can give them
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:
@@ -2,9 +2,10 @@
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { huf, usePackages } from "@/components/PackageCards";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ROLE_LABELS, formatDate } from "@/lib/astro";
|
||||
import type { AdminUser, Role } from "@/lib/types";
|
||||
import type { AdminUser, Package, Role } from "@/lib/types";
|
||||
|
||||
const EDITABLE_ROLES: Role[] = ["user", "creator", "admin"];
|
||||
const UNITS: { value: "natal" | "synastry"; label: string }[] = [
|
||||
@@ -16,6 +17,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [users, setUsers] = useState<AdminUser[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const packages = usePackages() ?? [];
|
||||
|
||||
const load = useCallback(async (q: string) => {
|
||||
try {
|
||||
@@ -62,6 +64,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
|
||||
<th scope="col">Felhasználó</th>
|
||||
<th scope="col">Szerepkörök</th>
|
||||
<th scope="col">Részletes elemzések</th>
|
||||
<th scope="col">Csomag</th>
|
||||
<th scope="col">Képletek</th>
|
||||
<th scope="col">Regisztrált</th>
|
||||
<th scope="col">Utoljára belépett</th>
|
||||
@@ -73,6 +76,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
|
||||
key={u.id}
|
||||
user={u}
|
||||
isSelf={u.id === selfId}
|
||||
packages={packages}
|
||||
onChange={(next) => setUsers((list) => list?.map((x) => (x.id === next.id ? next : x)) ?? null)}
|
||||
/>
|
||||
))}
|
||||
@@ -84,7 +88,17 @@ export function AdminUsers({ selfId }: { selfId: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
function UserRow({ user, isSelf, onChange }: { user: AdminUser; isSelf: boolean; onChange: (u: AdminUser) => void }) {
|
||||
function UserRow({
|
||||
user,
|
||||
isSelf,
|
||||
packages,
|
||||
onChange,
|
||||
}: {
|
||||
user: AdminUser;
|
||||
isSelf: boolean;
|
||||
packages: Package[];
|
||||
onChange: (u: AdminUser) => void;
|
||||
}) {
|
||||
const [status, setStatus] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [delta, setDelta] = useState("");
|
||||
@@ -200,9 +214,84 @@ function UserRow({ user, isSelf, onChange }: { user: AdminUser; isSelf: boolean;
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<PackageGrant user={user} packages={packages} onChange={onChange} />
|
||||
</td>
|
||||
<td className="num">{user.charts}</td>
|
||||
<td className="num">{formatDate(user.created_at)}</td>
|
||||
<td className="num">{formatDate(user.last_login_at, true)}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
/** Gives the user a package from the catalog (a gift: nothing is paid). */
|
||||
function PackageGrant({
|
||||
user,
|
||||
packages,
|
||||
onChange,
|
||||
}: {
|
||||
user: AdminUser;
|
||||
packages: Package[];
|
||||
onChange: (u: AdminUser) => void;
|
||||
}) {
|
||||
const [id, setId] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [status, setStatus] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
|
||||
async function give(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const pkg = packages.find((p) => p.id === id);
|
||||
if (!pkg) return;
|
||||
setBusy(true);
|
||||
setStatus(null);
|
||||
try {
|
||||
const res = await api<{ analyses_left: AdminUser["analyses_left"]; unlimited_until: string | null }>(
|
||||
`/admin/users/${user.id}/packages`,
|
||||
{ body: { package: pkg.id, note: "admin ajándék" } },
|
||||
);
|
||||
onChange({ ...user, analyses_left: res.analyses_left, unlimited_until: res.unlimited_until });
|
||||
setStatus({ ok: true, text: `${pkg.name} kiosztva` });
|
||||
setId("");
|
||||
} catch (err) {
|
||||
setStatus({ ok: false, text: errorText(err) });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={give} className="field" style={{ gap: 6 }}>
|
||||
{user.unlimited_until && (
|
||||
<span className="badge badge-gold">Korlátlan {formatDate(user.unlimited_until).replace(/\.$/, "")}-ig</span>
|
||||
)}
|
||||
<div className="row" style={{ gap: 6, flexWrap: "nowrap" }}>
|
||||
<label className="sr-only" htmlFor={`pkg-${user.id}`}>
|
||||
Kiosztandó csomag
|
||||
</label>
|
||||
<select
|
||||
id={`pkg-${user.id}`}
|
||||
className="inp"
|
||||
style={{ width: 190, minHeight: 36 }}
|
||||
value={id}
|
||||
onChange={(e) => setId(e.target.value)}
|
||||
disabled={busy || packages.length === 0}
|
||||
>
|
||||
<option value="">Válassz csomagot…</option>
|
||||
{packages.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.name} ({huf(p.price_huf)})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button type="submit" className="btn btn-sm" disabled={busy || !id}>
|
||||
{busy ? "…" : "Kiosztás"}
|
||||
</button>
|
||||
</div>
|
||||
{status && (
|
||||
<span className={status.ok ? "msg msg-ok" : "msg msg-error"} role="status">
|
||||
{status.text}
|
||||
</span>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user