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
@@ -0,0 +1,174 @@
"use client";
import { useEffect, useId, useState } from "react";
import { api, errorText } from "@/lib/api";
import { CATEGORY_LABELS, STATUS_LABELS } from "@/lib/feedback";
import type { FeedbackCategory, FeedbackMessage } from "@/lib/types";
const MAX_BODY = 2000;
const PLACEHOLDERS: Record<FeedbackCategory, string> = {
bug: "Mi történt, és mit vártál helyette? Melyik oldalon, milyen eszközön?",
idea: "Mi hiányzik, mit csinálnál másképp?",
question: "Miben segíthetünk?",
other: "Amit el szeretnél mondani.",
};
const day = (iso: string) =>
new Date(iso).toLocaleDateString("hu-HU", {
timeZone: "Europe/Budapest",
year: "numeric",
month: "long",
day: "numeric",
});
/** The form, then the user's earlier messages with their state and our replies. */
export function Feedback({
initialCategory,
from,
}: {
initialCategory: FeedbackCategory;
from: string | null;
}) {
const id = useId();
const [category, setCategory] = useState<FeedbackCategory>(initialCategory);
const [body, setBody] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [sent, setSent] = useState(false);
const [messages, setMessages] = useState<FeedbackMessage[] | null>(null);
useEffect(() => {
api<{ messages: FeedbackMessage[] }>("/feedback")
.then((r) => {
setMessages(r.messages);
// The replies are read now.
if (r.messages.some((m) => m.reply_new))
api("/feedback/seen", { method: "POST", body: {} }).catch(() => {});
})
.catch(() => setMessages([]));
}, []);
async function send(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
setSent(false);
try {
const m = await api<FeedbackMessage>("/feedback", {
body: { category, body, page: from },
});
setMessages((all) => [m, ...(all ?? [])]);
setBody("");
setSent(true);
} catch (err) {
setError(errorText(err));
} finally {
setBusy(false);
}
}
return (
<>
<form className="card feedback-form" onSubmit={send}>
<fieldset className="gift-set">
<legend className="label">Miről szól?</legend>
<div className="feedback-kinds">
{(Object.keys(CATEGORY_LABELS) as FeedbackCategory[]).map((c) => (
<label
key={c}
className={
c === category ? "feedback-kind is-on" : "feedback-kind"
}
>
<input
type="radio"
name={`${id}-kind`}
checked={c === category}
onChange={() => setCategory(c)}
/>
{CATEGORY_LABELS[c]}
</label>
))}
</div>
</fieldset>
<div className="field">
<label htmlFor={`${id}-body`}>Üzenet</label>
<textarea
id={`${id}-body`}
className="inp"
rows={6}
maxLength={MAX_BODY}
value={body}
onChange={(e) => setBody(e.target.value)}
placeholder={PLACEHOLDERS[category]}
required
/>
<span className="hint">
{from
? `Az oldal, ahonnan jöttél (${from}), és a böngésződ típusa is velemegy, hogy könnyebb legyen megtalálni a hibát. `
: ""}
{body.length}/{MAX_BODY}
</span>
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{sent && (
<p className="msg msg-ok" role="status">
Köszönjük, megkaptuk! Ha válaszolunk, lent látod.
</p>
)}
<div className="form-actions">
<button
type="submit"
className="btn btn-primary"
disabled={busy || !body.trim()}
>
{busy ? "Küldés…" : "Elküldöm"}
</button>
</div>
</form>
{messages && messages.length > 0 && (
<section className="field" aria-labelledby="my-feedback-title">
<h2 id="my-feedback-title">Korábbi üzeneteid</h2>
<ul className="feedback-list">
{messages.map((m) => (
<li key={m.id} className="card feedback-item">
<div className="feedback-item-head">
<span className="badge">{CATEGORY_LABELS[m.category]}</span>
<span
className={
m.status === "done" ? "badge badge-gold" : "badge"
}
>
{STATUS_LABELS[m.status]}
</span>
<span className="hint">{day(m.created_at)}</span>
</div>
<p className="feedback-body">{m.body}</p>
{m.reply && (
<div
className={
m.reply_new ? "feedback-reply is-new" : "feedback-reply"
}
>
<span className="eyebrow">
A válaszunk{m.replied_at ? ` · ${day(m.replied_at)}` : ""}
{m.reply_new ? " · új" : ""}
</span>
<p>{m.reply}</p>
</div>
)}
</li>
))}
</ul>
</section>
)}
</>
);
}
@@ -0,0 +1,40 @@
import type { Metadata } from "next";
import { requireMe } from "@/lib/server";
import type { FeedbackCategory } from "@/lib/types";
import { Feedback } from "./Feedback";
export const metadata: Metadata = {
title: "Visszajelzés",
robots: { index: false },
};
type Props = { searchParams: Promise<{ tipus?: string; honnan?: string }> };
const CATEGORIES: FeedbackCategory[] = ["bug", "idea", "question", "other"];
/** Feedback to the operator: bugs, ideas, questions, and the replies to them. */
export default async function FeedbackPage({ searchParams }: Props) {
const { tipus, honnan } = await searchParams;
await requireMe("/visszajelzes");
const category = CATEGORIES.find((c) => c === tipus) ?? "bug";
const from =
honnan && honnan.startsWith("/") && !honnan.startsWith("//")
? honnan.slice(0, 300)
: null;
return (
<main className="page" style={{ maxWidth: 760 }}>
<div className="page-head">
<span className="eyebrow">Visszajelzés</span>
<h1>Írj nekünk</h1>
<p className="muted">
Hibát találtál, van egy ötleted, vagy kérdésed van? Írd meg itt:
elolvassuk, és ha válaszolunk, a válaszunkat ezen az oldalon látod.
Amit írsz, csak mi látjuk.
</p>
</div>
<Feedback initialCategory={category} from={from} />
</main>
);
}