- 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
684 lines
21 KiB
TypeScript
684 lines
21 KiB
TypeScript
"use client";
|
||
|
||
import { useCallback, useEffect, useState } from "react";
|
||
|
||
import { api, errorText } from "@/lib/api";
|
||
import { formatDate } from "@/lib/astro";
|
||
import { CATEGORY_LABELS, KIND_LABELS, TAG_LABELS } from "@/lib/feedback";
|
||
import type {
|
||
AdminFeedbackMessage,
|
||
AdminRating,
|
||
FeedbackStatus,
|
||
FeedbackSummary,
|
||
} from "@/lib/types";
|
||
|
||
type Tab = "summary" | "ratings" | "messages";
|
||
|
||
const avg = (n: number) =>
|
||
n.toLocaleString("hu-HU", {
|
||
maximumFractionDigits: 2,
|
||
minimumFractionDigits: 1,
|
||
});
|
||
const pct = (n: number) => `${Math.round(n * 100)}%`;
|
||
const stars = (n: number) => "★".repeat(n) + "☆".repeat(5 - n);
|
||
|
||
const ADMIN_STATUS: Record<FeedbackStatus, string> = {
|
||
new: "új",
|
||
in_progress: "folyamatban",
|
||
done: "megoldva",
|
||
dismissed: "elvetve",
|
||
};
|
||
|
||
/** Admin → Visszajelzések: the numbers, the ratings, the messages. */
|
||
export function AdminFeedback() {
|
||
const [tab, setTab] = useState<Tab>("summary");
|
||
return (
|
||
<>
|
||
<div className="tabs-row" role="tablist" aria-label="Visszajelzések">
|
||
{(
|
||
[
|
||
["summary", "Áttekintés"],
|
||
["ratings", "Értékelések"],
|
||
["messages", "Üzenetek"],
|
||
] as [Tab, string][]
|
||
).map(([t, label]) => (
|
||
<button
|
||
key={t}
|
||
type="button"
|
||
role="tab"
|
||
aria-selected={tab === t}
|
||
className={tab === t ? "btn btn-sm btn-primary" : "btn btn-sm"}
|
||
onClick={() => setTab(t)}
|
||
>
|
||
{label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
{tab === "summary" && <Summary />}
|
||
{tab === "ratings" && <Ratings />}
|
||
{tab === "messages" && <Messages />}
|
||
</>
|
||
);
|
||
}
|
||
|
||
function Summary() {
|
||
const [days, setDays] = useState(90);
|
||
const [data, setData] = useState<FeedbackSummary | null>(null);
|
||
const [error, setError] = useState<string | null>(null);
|
||
useEffect(() => {
|
||
api<FeedbackSummary>(`/admin/feedback/summary?days=${days}`)
|
||
.then(setData)
|
||
.catch((e) => setError(errorText(e)));
|
||
}, [days]);
|
||
if (error) return <p className="msg msg-error">{error}</p>;
|
||
if (!data) return <p className="muted">Betöltés…</p>;
|
||
const total = data.by_kind.reduce((n, k) => n + k.count, 0);
|
||
return (
|
||
<div className="field" style={{ gap: 16 }}>
|
||
<div className="row">
|
||
<label htmlFor="fb-days" className="label">
|
||
Időszak
|
||
</label>
|
||
<select
|
||
id="fb-days"
|
||
className="inp"
|
||
style={{ maxWidth: 200 }}
|
||
value={days}
|
||
onChange={(e) => setDays(Number(e.target.value))}
|
||
>
|
||
<option value={7}>az utolsó 7 nap</option>
|
||
<option value={30}>az utolsó 30 nap</option>
|
||
<option value={90}>az utolsó 90 nap</option>
|
||
<option value={3650}>mind</option>
|
||
</select>
|
||
</div>
|
||
|
||
<section className="card">
|
||
<h2>Tartalomfajtánként</h2>
|
||
{total === 0 ? (
|
||
<p className="muted">Még nincs értékelés ebben az időszakban.</p>
|
||
) : (
|
||
<div className="table-wrap">
|
||
<table className="promo-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Fajta</th>
|
||
<th>Értékelés</th>
|
||
<th>Átlag</th>
|
||
<th>Elégedett (4–5)</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{data.by_kind.map((k) => (
|
||
<tr key={k.kind}>
|
||
<td>{KIND_LABELS[k.kind] ?? k.kind}</td>
|
||
<td className="num">{k.count}</td>
|
||
<td className="num">
|
||
{k.kind === "question" ? "–" : avg(k.average)}
|
||
</td>
|
||
<td className="num">{pct(k.satisfied_share)}</td>
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
)}
|
||
{data.buyers.length > 0 && (
|
||
<p className="hint">
|
||
{data.buyers
|
||
.map(
|
||
(b) =>
|
||
`${b.buyer ? "Vásárlók" : "Nem vásárlók"}: ${b.count} értékelés, átlag ${avg(b.average)}`,
|
||
)
|
||
.join(" · ")}
|
||
</p>
|
||
)}
|
||
<p className="hint">
|
||
A kérdésekre adott válaszoknál az „igen, hasznos” 5, a „nem” 1
|
||
csillagnak számít.
|
||
</p>
|
||
</section>
|
||
|
||
{data.weeks.length > 0 && (
|
||
<section className="card">
|
||
<h2>Hetente</h2>
|
||
<ul className="fb-weeks">
|
||
{data.weeks.map((w) => (
|
||
<li key={w.week}>
|
||
<span className="num">{w.week}</span>
|
||
<span
|
||
className="fb-bar"
|
||
style={{ width: `${(w.average / 5) * 100}%` }}
|
||
aria-hidden="true"
|
||
/>
|
||
<span className="num">
|
||
{avg(w.average)} ({w.count})
|
||
</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
)}
|
||
|
||
{data.tags.length > 0 && (
|
||
<section className="card">
|
||
<h2>Címkék</h2>
|
||
<div className="rate-tags">
|
||
{data.tags.map((t) => (
|
||
<span key={t.tag} className="badge">
|
||
{TAG_LABELS[t.tag] ?? t.tag}: {t.count}
|
||
</span>
|
||
))}
|
||
</div>
|
||
</section>
|
||
)}
|
||
|
||
{data.by_model.length > 0 && (
|
||
<section className="card">
|
||
<h2>Modellenként és prompt-verziónként</h2>
|
||
<div className="table-wrap">
|
||
<table className="promo-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Fajta</th>
|
||
<th>Modell</th>
|
||
<th>Prompt</th>
|
||
<th>Értékelés</th>
|
||
<th>Átlag</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{data.by_model.map((m) => (
|
||
<tr key={`${m.kind}-${m.model}-${m.prompt_version}`}>
|
||
<td>{KIND_LABELS[m.kind] ?? m.kind}</td>
|
||
<td>
|
||
<code>{m.model}</code>
|
||
</td>
|
||
<td>
|
||
<code>{m.prompt_version}</code>
|
||
</td>
|
||
<td className="num">{m.count}</td>
|
||
<td className="num">{avg(m.average)}</td>
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
)}
|
||
|
||
<section className="card">
|
||
<h2>Ajánlanád? (NPS)</h2>
|
||
{data.nps.answered === 0 ? (
|
||
<p className="muted">
|
||
Még senki nem válaszolt.
|
||
{data.nps.closed
|
||
? ` ${data.nps.closed} felhasználó bezárta a kérdést.`
|
||
: ""}
|
||
</p>
|
||
) : (
|
||
<>
|
||
<p>
|
||
<strong className="fb-nps">
|
||
{Math.round(data.nps.score ?? 0)}
|
||
</strong>{" "}
|
||
<span className="muted">
|
||
({data.nps.answered} válasz: {data.nps.promoters} ajánlaná
|
||
(9–10), {data.nps.passives} semleges (7–8),{" "}
|
||
{data.nps.detractors} nem ajánlaná (0–6); {data.nps.closed}{" "}
|
||
bezárta)
|
||
</span>
|
||
</p>
|
||
<p className="hint">
|
||
Az NPS az ajánlók és a nem ajánlók arányának különbsége, −100 és
|
||
100 között.
|
||
</p>
|
||
{data.nps.comments.length > 0 && (
|
||
<ul className="fb-comments">
|
||
{data.nps.comments.map((c, i) => (
|
||
<li key={i}>
|
||
<span className="badge">{c.score}</span> {c.comment}{" "}
|
||
<span className="hint">{formatDate(c.created_at)}</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</>
|
||
)}
|
||
</section>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Ratings() {
|
||
const [kind, setKind] = useState("");
|
||
const [onlyLow, setOnlyLow] = useState(false);
|
||
const [withComment, setWithComment] = useState(false);
|
||
const [unreviewed, setUnreviewed] = useState(false);
|
||
const [offset, setOffset] = useState(0);
|
||
const [data, setData] = useState<{
|
||
ratings: AdminRating[];
|
||
total: number;
|
||
limit: number;
|
||
} | null>(null);
|
||
const [error, setError] = useState<string | null>(null);
|
||
const [opened, setOpened] = useState<Record<string, unknown>>({});
|
||
|
||
const load = useCallback(async () => {
|
||
const q = new URLSearchParams();
|
||
if (kind) q.set("kind", kind);
|
||
if (onlyLow) q.set("max_stars", "2");
|
||
if (withComment) q.set("with_comment", "true");
|
||
if (unreviewed) q.set("unreviewed", "true");
|
||
q.set("offset", String(offset));
|
||
try {
|
||
setData(await api(`/admin/ratings?${q}`));
|
||
} catch (e) {
|
||
setError(errorText(e));
|
||
}
|
||
}, [kind, onlyLow, withComment, unreviewed, offset]);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
}, [load]);
|
||
|
||
async function reviewed(ids?: string[]) {
|
||
try {
|
||
await api("/admin/ratings/reviewed", { body: ids ? { ids } : {} });
|
||
await load();
|
||
} catch (e) {
|
||
setError(errorText(e));
|
||
}
|
||
}
|
||
|
||
async function open(r: AdminRating) {
|
||
try {
|
||
const content = await api(`/admin/ratings/${r.id}/content`);
|
||
setOpened((all) => ({ ...all, [r.id]: content }));
|
||
} catch (e) {
|
||
setError(errorText(e));
|
||
}
|
||
}
|
||
|
||
return (
|
||
<section className="card">
|
||
<div className="row">
|
||
<select
|
||
className="inp"
|
||
style={{ maxWidth: 220 }}
|
||
value={kind}
|
||
onChange={(e) => (setOffset(0), setKind(e.target.value))}
|
||
aria-label="Fajta"
|
||
>
|
||
<option value="">Minden fajta</option>
|
||
{Object.entries(KIND_LABELS).map(([k, label]) => (
|
||
<option key={k} value={k}>
|
||
{label}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<label className="check">
|
||
<input
|
||
type="checkbox"
|
||
checked={onlyLow}
|
||
onChange={(e) => (setOffset(0), setOnlyLow(e.target.checked))}
|
||
/>
|
||
Csak 1–2 csillag
|
||
</label>
|
||
<label className="check">
|
||
<input
|
||
type="checkbox"
|
||
checked={withComment}
|
||
onChange={(e) => (setOffset(0), setWithComment(e.target.checked))}
|
||
/>
|
||
Csak megjegyzéssel
|
||
</label>
|
||
<label className="check">
|
||
<input
|
||
type="checkbox"
|
||
checked={unreviewed}
|
||
onChange={(e) => (setOffset(0), setUnreviewed(e.target.checked))}
|
||
/>
|
||
Csak amit még nem láttam
|
||
</label>
|
||
<button type="button" className="btn btn-sm" onClick={() => reviewed()}>
|
||
Mind láttam
|
||
</button>
|
||
</div>
|
||
{error && <p className="msg msg-error">{error}</p>}
|
||
{!data ? (
|
||
<p className="muted">Betöltés…</p>
|
||
) : data.ratings.length === 0 ? (
|
||
<p className="muted">Nincs ilyen értékelés.</p>
|
||
) : (
|
||
<>
|
||
<ul className="fb-ratings">
|
||
{data.ratings.map((r) => (
|
||
<li
|
||
key={r.id}
|
||
className={r.reviewed ? "fb-rating" : "fb-rating is-new"}
|
||
>
|
||
<div className="fb-rating-head">
|
||
<span
|
||
className={r.stars <= 2 ? "fb-stars is-low" : "fb-stars"}
|
||
aria-label={`${r.stars} csillag`}
|
||
>
|
||
{r.kind === "question"
|
||
? r.stars >= 4
|
||
? "👍"
|
||
: "👎"
|
||
: stars(r.stars)}
|
||
</span>
|
||
<strong>{KIND_LABELS[r.kind] ?? r.kind}</strong>
|
||
<span className="hint">{formatDate(r.updated_at, true)}</span>
|
||
{r.buyer && <span className="badge badge-gold">vásárló</span>}
|
||
<span className="hint">
|
||
{r.user ? r.user.email : "törölt fiók"} ·{" "}
|
||
<code>{r.model}</code> · <code>{r.prompt_version}</code>
|
||
</span>
|
||
</div>
|
||
{r.tags.length > 0 && (
|
||
<div className="rate-tags">
|
||
{r.tags.map((t) => (
|
||
<span key={t} className="badge">
|
||
{TAG_LABELS[t] ?? t}
|
||
</span>
|
||
))}
|
||
</div>
|
||
)}
|
||
{r.comment && <p className="feedback-body">{r.comment}</p>}
|
||
<div className="form-actions">
|
||
{r.readable ? (
|
||
opened[r.id] ? null : (
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm"
|
||
onClick={() => open(r)}
|
||
>
|
||
Szöveg megnyitása
|
||
</button>
|
||
)
|
||
) : (
|
||
<span className="hint">
|
||
A szöveget nem engedte megnézni.
|
||
</span>
|
||
)}
|
||
{!r.reviewed && (
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm btn-ghost"
|
||
onClick={() => reviewed([r.id])}
|
||
>
|
||
Láttam
|
||
</button>
|
||
)}
|
||
</div>
|
||
{opened[r.id] !== undefined && (
|
||
<div className="fb-content">
|
||
<ContentDump value={opened[r.id]} />
|
||
</div>
|
||
)}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
{data.total > data.limit && (
|
||
<div className="pager">
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm"
|
||
disabled={offset === 0}
|
||
onClick={() => setOffset(Math.max(0, offset - data.limit))}
|
||
>
|
||
Előző
|
||
</button>
|
||
<span className="num">
|
||
{offset + 1}–{Math.min(offset + data.limit, data.total)} /{" "}
|
||
{data.total}
|
||
</span>
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm"
|
||
disabled={offset + data.limit >= data.total}
|
||
onClick={() => setOffset(offset + data.limit)}
|
||
>
|
||
Következő
|
||
</button>
|
||
</div>
|
||
)}
|
||
</>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
/** Any analysis content as headings and paragraphs (every kind has its own shape). */
|
||
function ContentDump({ value, label }: { value: unknown; label?: string }) {
|
||
if (value === null || value === undefined || value === "") return null;
|
||
if (
|
||
typeof value === "string" ||
|
||
typeof value === "number" ||
|
||
typeof value === "boolean"
|
||
) {
|
||
return (
|
||
<p>
|
||
{label && <span className="hint">{label}: </span>}
|
||
{String(value)}
|
||
</p>
|
||
);
|
||
}
|
||
if (Array.isArray(value)) {
|
||
return (
|
||
<div className="fb-dump">
|
||
{label && <p className="hint">{label}</p>}
|
||
{value.map((v, i) => (
|
||
<ContentDump key={i} value={v} />
|
||
))}
|
||
</div>
|
||
);
|
||
}
|
||
const entries = Object.entries(value as Record<string, unknown>);
|
||
const title = entries.find(
|
||
([k, v]) => (k === "title" || k === "heading") && typeof v === "string",
|
||
);
|
||
return (
|
||
<div className="fb-dump">
|
||
{label && <p className="hint">{label}</p>}
|
||
{title && <h4>{String(title[1])}</h4>}
|
||
{entries
|
||
.filter(([k]) => !title || k !== title[0])
|
||
.map(([k, v]) => (
|
||
<ContentDump key={k} value={v} label={k} />
|
||
))}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Messages() {
|
||
const [status, setStatus] = useState("open");
|
||
const [messages, setMessages] = useState<AdminFeedbackMessage[] | null>(null);
|
||
const [error, setError] = useState<string | null>(null);
|
||
|
||
const load = useCallback(async () => {
|
||
try {
|
||
const r = await api<{ messages: AdminFeedbackMessage[] }>(
|
||
`/admin/feedback?status=${status}`,
|
||
);
|
||
setMessages(r.messages);
|
||
} catch (e) {
|
||
setError(errorText(e));
|
||
}
|
||
}, [status]);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
}, [load]);
|
||
|
||
return (
|
||
<section className="card">
|
||
<div className="row">
|
||
<label htmlFor="fb-status" className="label">
|
||
Állapot
|
||
</label>
|
||
<select
|
||
id="fb-status"
|
||
className="inp"
|
||
style={{ maxWidth: 220 }}
|
||
value={status}
|
||
onChange={(e) => setStatus(e.target.value)}
|
||
>
|
||
<option value="open">nyitott (új és folyamatban)</option>
|
||
<option value="new">új</option>
|
||
<option value="in_progress">folyamatban</option>
|
||
<option value="done">megoldva</option>
|
||
<option value="dismissed">elvetve</option>
|
||
<option value="all">mind</option>
|
||
</select>
|
||
</div>
|
||
{error && <p className="msg msg-error">{error}</p>}
|
||
{!messages ? (
|
||
<p className="muted">Betöltés…</p>
|
||
) : messages.length === 0 ? (
|
||
<p className="muted">Nincs ilyen üzenet.</p>
|
||
) : (
|
||
<ul className="feedback-list">
|
||
{messages.map((m) => (
|
||
<MessageItem key={m.id} message={m} onSaved={load} />
|
||
))}
|
||
</ul>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function MessageItem({
|
||
message: m,
|
||
onSaved,
|
||
}: {
|
||
message: AdminFeedbackMessage;
|
||
onSaved: () => Promise<void>;
|
||
}) {
|
||
const [note, setNote] = useState(m.admin_note ?? "");
|
||
const [reply, setReply] = useState(m.reply ?? "");
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState<string | null>(null);
|
||
|
||
async function save(status?: FeedbackStatus) {
|
||
setBusy(true);
|
||
setError(null);
|
||
try {
|
||
await api(`/admin/feedback/${m.id}`, {
|
||
method: "PATCH",
|
||
body: { ...(status ? { status } : {}), admin_note: note, reply },
|
||
});
|
||
await onSaved();
|
||
} catch (e) {
|
||
setError(errorText(e));
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}
|
||
|
||
return (
|
||
<li
|
||
className={
|
||
m.status === "new" ? "card feedback-item is-new" : "card feedback-item"
|
||
}
|
||
>
|
||
<div className="feedback-item-head">
|
||
<span className="badge">{CATEGORY_LABELS[m.category]}</span>
|
||
<span className={m.status === "new" ? "badge badge-gold" : "badge"}>
|
||
{ADMIN_STATUS[m.status]}
|
||
</span>
|
||
<span className="hint">{formatDate(m.created_at, true)}</span>
|
||
<span className="hint">
|
||
{m.user.name ? `${m.user.name} · ` : ""}
|
||
{m.user.email}
|
||
{m.user.buyer ? " · vásárló" : ""}
|
||
</span>
|
||
</div>
|
||
<p className="feedback-body">{m.body}</p>
|
||
{(m.page || m.user_agent) && (
|
||
<p className="hint">
|
||
{m.page && (
|
||
<>
|
||
Oldal: <code>{m.page}</code>{" "}
|
||
</>
|
||
)}
|
||
{m.user_agent && <>· {m.user_agent}</>}
|
||
</p>
|
||
)}
|
||
<div className="grid-2">
|
||
<div className="field">
|
||
<label htmlFor={`note-${m.id}`}>Belső jegyzet (csak te látod)</label>
|
||
<textarea
|
||
id={`note-${m.id}`}
|
||
className="inp"
|
||
rows={2}
|
||
value={note}
|
||
onChange={(e) => setNote(e.target.value)}
|
||
/>
|
||
</div>
|
||
<div className="field">
|
||
<label htmlFor={`reply-${m.id}`}>
|
||
Válasz (a felhasználó a Visszajelzés oldalon látja)
|
||
</label>
|
||
<textarea
|
||
id={`reply-${m.id}`}
|
||
className="inp"
|
||
rows={2}
|
||
value={reply}
|
||
onChange={(e) => setReply(e.target.value)}
|
||
/>
|
||
{m.replied_at && (
|
||
<span className="hint">
|
||
Elküldve: {formatDate(m.replied_at, true)} ·{" "}
|
||
{m.reply_seen ? "elolvasta" : "még nem olvasta"}
|
||
</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
{error && <p className="msg msg-error">{error}</p>}
|
||
<div className="form-actions">
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm btn-primary"
|
||
disabled={busy}
|
||
onClick={() => save()}
|
||
>
|
||
Mentés
|
||
</button>
|
||
{m.status !== "in_progress" && (
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm"
|
||
disabled={busy}
|
||
onClick={() => save("in_progress")}
|
||
>
|
||
Folyamatban
|
||
</button>
|
||
)}
|
||
{m.status !== "done" && (
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm"
|
||
disabled={busy}
|
||
onClick={() => save("done")}
|
||
>
|
||
Megoldva
|
||
</button>
|
||
)}
|
||
{m.status !== "dismissed" && (
|
||
<button
|
||
type="button"
|
||
className="btn btn-sm btn-ghost"
|
||
disabled={busy}
|
||
onClick={() => save("dismissed")}
|
||
>
|
||
Elvetés
|
||
</button>
|
||
)}
|
||
</div>
|
||
</li>
|
||
);
|
||
}
|