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
This commit is contained in:
feco
2026-11-24 07:01:40 +00:00
co-authored by Claude Opus 5.5
parent 3e4653fdb2
commit 62ae4a438e
34 changed files with 3097 additions and 99 deletions
@@ -2,11 +2,14 @@ import Link from "next/link";
import type { Role } from "@/lib/types";
import { FeedbackCount } from "./FeedbackCount";
const PAGES = [
{ href: "/admin", label: "Felhasználók" },
{ href: "/admin/meghivok", label: "Meghívók" },
{ href: "/admin/promokodok", label: "Promókódok" },
{ href: "/admin/ajandekok", label: "Ajándékok" },
{ href: "/admin/visszajelzesek", label: "Visszajelzések", count: true },
{ href: "/admin/hires-emberek", label: "Híres emberek", creator: true },
{ href: "/admin/promptok", label: "Promptok" },
{ href: "/admin/modellek", label: "Modellek" },
@@ -26,6 +29,7 @@ export function AdminNav({ current, roles }: { current: string; roles?: Role[] }
{PAGES.filter((p) => admin || ("creator" in p && p.creator)).map((p) => (
<Link key={p.href} href={p.href} aria-current={p.href === current ? "page" : undefined}>
{p.label}
{"count" in p && p.count && <FeedbackCount />}
</Link>
))}
</nav>
@@ -8,6 +8,8 @@ import type { PayMethod, Question, UnitBalance } from "@/lib/types";
import { AnalysisLoading } from "./AnalysisLoading";
import { PackageChooser } from "./PackageCards";
import { RateContent } from "./RateContent";
import { ReportLink } from "./ReportLink";
import { RegenerateButton } from "./RegenerateButton";
import { RetryNotice } from "./RetryNotice";
import { Paragraphs } from "./Rich";
@@ -174,6 +176,7 @@ export function AnalysisQuestions({
<RegenerateButton<Question> url={`/admin/questions/${q.id}/regenerate`} onStarted={replace} />
)}
<Paragraphs text={q.answer} />
<RateContent questionId={q.id} thumbs />
</div>
) : q.status === "failed" ? (
<div className="qa-answer">
@@ -183,7 +186,7 @@ export function AnalysisQuestions({
<p className="msg msg-error" role="alert">
Erre többszöri próbálkozás után sem sikerült válaszolni
{q.credits_charged > 0 ? ". A kérdést visszaadtuk, így ingyen újra felteheted" : ""}. Kérdezz újra egy
kicsit később.
kicsit később. Ha újra nem sikerül: <ReportLink />.
</p>
{isAdmin && q.error && <p className="hint">Hiba: {q.error}</p>}
</div>
@@ -6,6 +6,7 @@ import { api } from "@/lib/api";
import type { Analysis } from "@/lib/types";
import { AnalysisLoading } from "./AnalysisLoading";
import { RateContent } from "./RateContent";
import { RegenerateButton } from "./RegenerateButton";
import { RetryNotice } from "./RetryNotice";
import { Rich } from "./Rich";
@@ -90,6 +91,7 @@ export function ChartSummary({
<p className="summary-text" lang={summary?.language}>
<Rich text={content.summary ?? ""} />
</p>
{summary && <RateContent analysisId={summary.id} />}
<ShareChart
chartId={chartId}
rewardGranted={shareRewardGranted}
@@ -10,6 +10,8 @@ import { AI_SHORT } from "./AiNote";
import { AnalysisLoading } from "./AnalysisLoading";
import { PackageChooser } from "./PackageCards";
import { QuestionsDock } from "./QuestionsDock";
import { RateContent } from "./RateContent";
import { ReportLink } from "./ReportLink";
import { RegenerateButton } from "./RegenerateButton";
import { RetryNotice } from "./RetryNotice";
import { AnalysisView } from "./AnalysisView";
@@ -156,6 +158,7 @@ export function DetailedAnalysis({
)}
{note && <p className="hint">{note}</p>}
<AnalysisView content={analysis.content} kind={target.kind} language={analysis.language} />
<RateContent analysisId={analysis.id} />
{questionsLeft !== undefined && (
<QuestionsDock
analysisId={analysis.id}
@@ -200,7 +203,8 @@ export function DetailedAnalysis({
Az elemzés többszöri próbálkozás után sem készült el.
{analysis.credits_charged === 0
? " Próbáld újra."
: " A felhasznált egységet visszaadtuk, így ingyen újra kérheted."}
: " A felhasznált egységet visszaadtuk, így ingyen újra kérheted."}{" "}
Ha újra nem sikerül: <ReportLink />.
</p>
{isAdmin && analysis.error && <p className="hint">Hiba: {analysis.error}</p>}
</div>
@@ -0,0 +1,21 @@
"use client";
import { useEffect, useState } from "react";
import { api } from "@/lib/api";
/** How much new feedback there is (the admin menu): messages and ratings to look at. */
export function FeedbackCount() {
const [count, setCount] = useState(0);
useEffect(() => {
api<{ total: number }>("/admin/feedback/count")
.then((r) => setCount(r.total))
.catch(() => {});
}, []);
if (count === 0) return null;
return (
<span className="admin-nav-count" aria-label={`${count} új`}>
{count}
</span>
);
}
@@ -0,0 +1,130 @@
"use client";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
/**
* "Would you recommend us?" (0–10), once, as a bar under the header (no
* pop-up, no e-mail). Closing it counts: it does not come again.
*/
export function NpsBanner() {
const [shown, setShown] = useState(true);
const [score, setScore] = useState<number | null>(null);
const [comment, setComment] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [thanks, setThanks] = useState(false);
async function send(value: number | null, withComment: boolean) {
setBusy(true);
setError(null);
try {
await api("/nps", {
body: {
score: value,
comment: withComment ? comment.trim() || null : null,
},
});
if (value === null) setShown(false);
else if (withComment) setThanks(true);
} catch (e) {
setError(errorText(e));
} finally {
setBusy(false);
}
}
if (!shown) return null;
if (thanks) {
return (
<aside className="nps" aria-label="Köszönjük">
<p className="nps-thanks">
Köszönjük, hogy segítesz jobbá tenni a Sorsfonalakat!
</p>
<button
type="button"
className="btn btn-ghost btn-sm"
onClick={() => setShown(false)}
>
Bezárás
</button>
</aside>
);
}
return (
<aside className="nps" aria-labelledby="nps-question">
<div className="nps-main">
<p id="nps-question" className="nps-question">
Mennyire ajánlanád a Sorsfonalakat egy barátodnak?
</p>
{score === null ? (
<div className="nps-scale-wrap">
<div
className="nps-scale"
role="group"
aria-labelledby="nps-question"
>
{Array.from({ length: 11 }, (_, n) => (
<button
key={n}
type="button"
className="nps-score"
disabled={busy}
onClick={async () => {
setScore(n);
await send(n, false);
}}
>
{n}
</button>
))}
</div>
<span className="nps-ends hint" aria-hidden="true">
<span>egyáltalán nem</span>
<span>nagyon</span>
</span>
</div>
) : (
<form
className="nps-comment"
onSubmit={(e) => {
e.preventDefault();
send(score, true);
}}
>
<label htmlFor="nps-why" className="hint">
Köszönjük! Mi a legfontosabb oka? (nem kötelező)
</label>
<div className="redeem-row">
<input
id="nps-why"
className="inp"
maxLength={1000}
value={comment}
onChange={(e) => setComment(e.target.value)}
/>
<button
type="submit"
className="btn btn-primary btn-sm"
disabled={busy}
>
Elküldöm
</button>
</div>
</form>
)}
{error && <p className="msg msg-error">{error}</p>}
</div>
<button
type="button"
className="nps-close"
aria-label="Bezárás"
disabled={busy}
onClick={() => (score === null ? send(null, false) : setShown(false))}
>
×
</button>
</aside>
);
}
@@ -0,0 +1,215 @@
"use client";
import { useEffect, useId, useState } from "react";
import { api, errorText } from "@/lib/api";
import { HIGH_TAGS, LOW_TAGS, TAG_LABELS } from "@/lib/feedback";
import type { Rating } from "@/lib/types";
const MAX_COMMENT = 1000;
/**
* "Mennyire érezted magadra szabottnak?": the user rates what they got (an
* analysis: 1–5 stars; an answer: thumbs). A click saves it at once; tags, a
* comment and the permission to read the text can follow. Only the
* operator sees it, nothing is public.
*/
export function RateContent({
analysisId,
questionId,
thumbs = false,
}: {
analysisId?: string;
questionId?: string;
/** Thumbs up/down instead of stars (answers to questions). */
thumbs?: boolean;
}) {
const id = useId();
const [rating, setRating] = useState<Rating | null>(null);
const [open, setOpen] = useState(false);
const [tags, setTags] = useState<string[]>([]);
const [comment, setComment] = useState("");
const [mayRead, setMayRead] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [saved, setSaved] = useState(false);
const target = analysisId
? { analysis_id: analysisId }
: { question_id: questionId };
useEffect(() => {
const query = analysisId
? `analysis_ids=${analysisId}`
: `question_ids=${questionId}`;
api<{ ratings: Rating[] }>(`/ratings?${query}`)
.then((r) => {
const mine = r.ratings[0];
if (!mine) return;
setRating(mine);
setTags(mine.tags);
setComment(mine.comment ?? "");
setMayRead(mine.may_read);
})
.catch(() => {});
}, [analysisId, questionId]);
async function save(stars: number, details: boolean) {
setBusy(true);
setError(null);
setSaved(false);
try {
const shown = stars >= 4 ? HIGH_TAGS : LOW_TAGS;
const next = await api<Rating>("/ratings", {
method: "PUT",
body: {
...target,
stars,
// Tags of the other side do not fit a changed rating.
tags: tags.filter((t) => shown.includes(t)),
comment: comment.trim() || null,
may_read: mayRead,
},
});
setRating(next);
setTags(next.tags);
if (details) {
setSaved(true);
setOpen(false);
} else {
setOpen(true);
}
} catch (e) {
setError(errorText(e));
} finally {
setBusy(false);
}
}
const stars = rating?.stars ?? 0;
const offered = stars >= 4 ? HIGH_TAGS : LOW_TAGS;
const toggle = (tag: string) =>
setTags((all) =>
all.includes(tag) ? all.filter((t) => t !== tag) : [...all, tag],
);
return (
<div className={thumbs ? "rate rate-thumbs" : "rate"}>
<div className="rate-row">
<span className="rate-question" id={`${id}-q`}>
{thumbs
? "Hasznos volt a válasz?"
: "Mennyire érezted magadra szabottnak?"}
</span>
<div className="rate-buttons" role="group" aria-labelledby={`${id}-q`}>
{thumbs
? [
{ value: 5, label: "Igen", icon: "👍" },
{ value: 1, label: "Nem", icon: "👎" },
].map((b) => (
<button
key={b.value}
type="button"
className={
stars === b.value ? "rate-thumb is-on" : "rate-thumb"
}
aria-pressed={stars === b.value}
aria-label={b.label}
disabled={busy}
onClick={() => save(b.value, false)}
>
<span aria-hidden="true">{b.icon}</span>
</button>
))
: [1, 2, 3, 4, 5].map((n) => (
<button
key={n}
type="button"
className={n <= stars ? "rate-star is-on" : "rate-star"}
aria-pressed={n === stars}
aria-label={`${n} csillag`}
disabled={busy}
onClick={() => save(n, false)}
>
<span aria-hidden="true">★</span>
</button>
))}
</div>
{rating && !open && (
<button
type="button"
className="btn btn-ghost btn-sm"
onClick={() => setOpen(true)}
>
{rating.comment || rating.tags.length
? "Módosítom"
: "Hozzáfűzök valamit"}
</button>
)}
</div>
{open && rating && (
<div className="rate-details">
<p className="hint">
Köszönjük! Ha szeretnéd, mondd el bővebben is (nem kötelező):
</p>
<div className="rate-tags">
{offered.map((tag) => (
<button
key={tag}
type="button"
className={tags.includes(tag) ? "rate-tag is-on" : "rate-tag"}
aria-pressed={tags.includes(tag)}
onClick={() => toggle(tag)}
>
{TAG_LABELS[tag]}
</button>
))}
</div>
<label htmlFor={`${id}-comment`} className="sr-only">
Megjegyzés
</label>
<textarea
id={`${id}-comment`}
className="inp"
rows={2}
maxLength={MAX_COMMENT}
value={comment}
onChange={(e) => setComment(e.target.value)}
placeholder="Mi tetszett, mi nem? Mi hiányzott?"
/>
<label className="check">
<input
type="checkbox"
checked={mayRead}
onChange={(e) => setMayRead(e.target.checked)}
/>
Megnézhetitek{" "}
{thumbs ? "a kérdést és a választ" : "az elemzés szövegét"}, hogy
javíthassatok rajta.
</label>
<div className="form-actions">
<button
type="button"
className="btn btn-primary btn-sm"
disabled={busy}
onClick={() => save(stars, true)}
>
{busy ? "Mentés…" : "Elküldöm"}
</button>
<button
type="button"
className="btn btn-ghost btn-sm"
onClick={() => setOpen(false)}
>
Most nem
</button>
</div>
</div>
)}
<div aria-live="polite">
{error && <p className="msg msg-error">{error}</p>}
{saved && <p className="hint">Köszönjük a visszajelzést!</p>}
</div>
</div>
);
}
@@ -0,0 +1,20 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
/** "Hiba jelzése": the feedback page, with this page as where it happened. */
export function ReportLink({
children = "Hiba jelzése",
}: {
children?: React.ReactNode;
}) {
const pathname = usePathname();
return (
<Link
href={`/visszajelzes?tipus=bug&honnan=${encodeURIComponent(pathname)}`}
>
{children}
</Link>
);
}
@@ -146,7 +146,11 @@ export function SiteHeader({ me }: { me: Me }) {
<NavLinks links={links} />
<div className="who">
<PackageBadge me={me} />
<UserMenu name={me.user.display_name || me.user.email} invoices={me.invoice_count > 0} />
<UserMenu
name={me.user.display_name || me.user.email}
invoices={me.invoice_count > 0}
replies={me.feedback_replies_unseen ?? 0}
/>
</div>
<MobileMenu className="mobile-menu-app" sections={[{ links }]} />
</header>
+11 -3
View File
@@ -8,10 +8,10 @@ import { LogoutButton } from "./LogoutButton";
/**
* The account menu under the user's name (top right): profile, invoices,
* redeeming a code, giving a gift, logging out. Closes on a click outside, Escape, or
* redeeming a code, giving a gift, feedback (a dot: a new reply), logging out. Closes on a click outside, Escape, or
* moving to another page.
*/
export function UserMenu({ name, invoices }: { name: string; invoices: boolean }) {
export function UserMenu({ name, invoices, replies = 0 }: { name: string; invoices: boolean; replies?: number }) {
const [open, setOpen] = useState(false);
const box = useRef<HTMLDivElement>(null);
const button = useRef<HTMLButtonElement>(null);
@@ -40,6 +40,8 @@ export function UserMenu({ name, invoices }: { name: string; invoices: boolean }
...(invoices ? [{ href: "/szamlak", label: "Számláim" }] : []),
{ href: "/bevaltas", label: "Kód beváltása" },
{ href: "/ajandek", label: "Ajándékozás" },
// Where the user is goes with the message (for a bug).
{ href: `/visszajelzes?honnan=${encodeURIComponent(pathname)}`, match: "/visszajelzes", label: "Visszajelzés", dot: replies > 0 },
];
return (
@@ -58,6 +60,7 @@ export function UserMenu({ name, invoices }: { name: string; invoices: boolean }
<path d="M4 20c1.5-4 4.5-6 8-6s6.5 2 8 6" />
</svg>
<span className="who-name-text">{name}</span>
{replies > 0 && <span className="menu-dot" aria-label="új válasz a visszajelzésedre" />}
<svg viewBox="0 0 24 24" aria-hidden="true" className="who-chevron">
<path d="M6 9l6 6 6-6" />
</svg>
@@ -70,9 +73,14 @@ export function UserMenu({ name, invoices }: { name: string; invoices: boolean }
href={item.href}
role="menuitem"
className="user-menu-item"
aria-current={pathname.startsWith(item.href) ? "page" : undefined}
aria-current={pathname.startsWith("match" in item && item.match ? item.match : item.href) ? "page" : undefined}
>
{item.label}
{"dot" in item && item.dot && (
<span className="menu-dot" aria-label="új válasz">
{" "}
</span>
)}
</Link>
))}
<LogoutButton className="user-menu-item user-menu-logout" role="menuitem" />
@@ -8,6 +8,8 @@ import type { TarotReading } from "@/lib/tarot";
import { AnalysisLoading } from "../AnalysisLoading";
import { RegenerateButton } from "../RegenerateButton";
import { RetryNotice } from "../RetryNotice";
import { RateContent } from "../RateContent";
import { ReportLink } from "../ReportLink";
import { TarotResult } from "./TarotResult";
const POLL_MS = 3000;
@@ -74,6 +76,7 @@ export function TarotLive({
<>
{regenerate}
<TarotResult cards={reading.cards} question={reading.question} content={reading.content} />
<RateContent analysisId={reading.id} />
</>
);
}
@@ -84,7 +87,7 @@ export function TarotLive({
<p className="msg msg-error" role="alert">
A jóslást többszöri próbálkozás után sem sikerült megírni
{reading.credits_charged > 0 ? ". A jóslást visszaadtuk, így ingyen újra húzhatsz" : ""}. Próbáld újra egy kicsit
később.
később. Ha újra nem sikerül: <ReportLink />.
</p>
{isAdmin && reading.error && <p className="hint">Hiba: {reading.error}</p>}
</div>