Files
sorsfonalak/services/frontend/src/app/admin/ajandekok/AdminGifts.tsx
T
fecoandClaude Opus 5.5 62ae4a438e Feedback in the system: ratings, messages, the recommendation question
- Under the summary, the detailed analyses, the forecast and tarot: "How
  tailored to you did it feel?" (1–5 stars); thumbs under answers. Only
  the owner rates, once (changeable); tags, a comment, and a permission
  to read the text; model and prompt version are kept with it
- /visszajelzes: bug, idea, question, other (the page and the browser go
  with it, 10 a day); the state and the operator's reply show there, a
  dot in the account menu marks a new reply. No e-mail, no Telegram
- One NPS question (0–10) in a bar under the header, after two finished
  contents; closing it counts
- Admin → Visszajelzések: numbers by kind, week, tags, model and prompt,
  buyers and others, NPS; ratings with filters, the text only if allowed;
  messages with state, internal note and reply; a count in the admin menu
- Nothing is public. Deleting an account keeps the stars without a name
  or comment; messages go. Privacy policy (hu, en) updated
- The admin menu no longer shows a vertical scrollbar

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-24 07:01:40 +00:00

219 lines
7.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
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 { useCallback, useEffect, useState } from "react";
import { api, errorText } from "@/lib/api";
import { formatDate } from "@/lib/astro";
import type { AdminGift } from "@/lib/types";
const huf = (n: number) => `${n.toLocaleString("hu-HU")} Ft`;
const STORNO: Record<string, string> = {
pending: "sztornó folyamatban",
done: "sztornózva",
failed: "sztornó hiba",
};
/** The gifts with their payment, invoice and storno, and the refund button. */
export function AdminGifts() {
const [gifts, setGifts] = useState<AdminGift[] | null>(null);
const [q, setQ] = useState("");
const [busy, setBusy] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [done, setDone] = useState<string | null>(null);
const load = useCallback(async (search: string) => {
try {
const r = await api<{ gifts: AdminGift[] }>(
`/admin/gifts${search ? `?q=${encodeURIComponent(search)}` : ""}`,
);
setGifts(r.gifts);
} catch (e) {
setError(errorText(e));
}
}, []);
useEffect(() => {
const t = setTimeout(() => load(q.trim()), 250);
return () => clearTimeout(t);
}, [q, load]);
async function refund(g: AdminGift) {
const late = g.within_withdrawal
? ""
: "\n\nFigyelem: a 14 napos elállási idő már letelt.";
const money = g.checkout?.amount_huf
? ` (${huf(g.checkout.amount_huf)})`
: "";
if (
!window.confirm(
`Visszatéríted a(z) „${g.package.name}” ajándékot${money}? A ${g.code} kód érvénytelen lesz, a Stripe visszautalja az árát, a számla sztornózódik.${late}`,
)
)
return;
setBusy(g.id);
setError(null);
setDone(null);
try {
await api(`/admin/gifts/${g.id}/refund`, { method: "POST", body: {} });
setDone(`Visszatérítve: ${g.code}.`);
} catch (e) {
setError(errorText(e));
} finally {
setBusy(null);
await load(q.trim());
}
}
return (
<section className="card">
<div className="field">
<label htmlFor="gift-search">Keresés</label>
<input
id="gift-search"
className="inp"
value={q}
onChange={(e) => setQ(e.target.value)}
placeholder="Kód, a vásárló vagy a címzett e-mail-címe, a címzett neve"
/>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{done && (
<p className="msg msg-ok" role="status">
{done}
</p>
)}
{gifts === null ? (
<p className="muted">Betöltés…</p>
) : gifts.length === 0 ? (
<p className="muted">Nincs ilyen ajándék.</p>
) : (
<div className="table-wrap">
<table className="promo-table">
<thead>
<tr>
<th>Kód</th>
<th>Csomag</th>
<th>Vásárló → címzett</th>
<th>Fizetve</th>
<th>Állapot</th>
<th>Számla</th>
<th />
</tr>
</thead>
<tbody>
{gifts.map((g) => (
<tr key={g.id}>
<td>
<code className="promo-code">{g.code}</code>
</td>
<td>
{g.package.name ?? g.package.id}
{g.checkout?.amount_huf ? (
<span className="hint">{huf(g.checkout.amount_huf)}</span>
) : null}
{g.checkout && g.checkout.live === false && (
<span className="hint">teszt fizetés</span>
)}
</td>
<td>
{g.buyer_email ?? (
<span className="muted">törölt fiók</span>
)}
<span className="hint">
→ {g.recipient_name ?? "?"}
{g.recipient_email
? ` (${g.recipient_email})`
: " (maga adja át)"}
</span>
</td>
<td className="num">{formatDate(g.paid_at, true)}</td>
<td>
{g.status === "redeemed" ? (
<>
beváltva{" "}
{g.redeemed_at ? formatDate(g.redeemed_at, true) : ""}
{g.redeemed_by && (
<span className="hint">{g.redeemed_by}</span>
)}
</>
) : g.status === "refunded" ? (
<>
{g.refund_pending ? (
<span className="msg-error">
visszatérítés félbemaradt
</span>
) : (
"visszatérítve"
)}{" "}
{g.refunded_at ? formatDate(g.refunded_at, true) : ""}
{g.refund_pending && g.refund_error && (
<span className="hint">{g.refund_error}</span>
)}
</>
) : (
<>
<span className="promo-open">beváltatlan</span>
<span className="hint">
{g.within_withdrawal
? "14 napon belül"
: "14 nap letelt"}
</span>
</>
)}
</td>
<td>
{g.invoice ? (
<>
{g.invoice.number ??
(g.invoice.status === "pending"
? "kiállítás alatt"
: g.invoice.status)}
{g.storno && (
<span
className={
g.storno.status === "failed"
? "hint msg-error"
: "hint"
}
>
{STORNO[g.storno.status] ?? g.storno.status}
{g.storno.number ? `: ${g.storno.number}` : ""}
{g.storno.error ? ` – ${g.storno.error}` : ""}
</span>
)}
</>
) : (
<span className="muted">–</span>
)}
</td>
<td>
{(g.status === "open" || g.refund_pending) && (
<button
type="button"
className="btn btn-sm"
onClick={() => refund(g)}
disabled={busy !== null}
>
{busy === g.id
? "Folyamatban…"
: g.status === "refunded"
? "Újrapróbálás"
: "Visszatérítés"}
</button>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</section>
);
}