Forum: reports for moderators and private messages by request
Any logged-in user can report a post, or a private message received; a possible crisis shows the helplines at once. Moderators get the open reports (crisis first) with what was reported, remove or close them, and every step goes to the log; the operator gets a Telegram notice of each new report (kind and link only). Private conversations start with a request and a short introduction (from the Kereső rank, a few a day); the recipient accepts, declines silently or blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { REPORT_KINDS, type ReportKind } from "@/lib/forum";
|
||||
|
||||
/** What to do when someone may be in danger: shown right after a crisis report. */
|
||||
export function CrisisHelp() {
|
||||
return (
|
||||
<p className="frep-crisis" role="note">
|
||||
Ha azonnali veszélyt látsz, hívd a <strong>112</strong>-t. A lelki elsősegély-szolgálat ingyenes, éjjel-nappal
|
||||
hívható száma: <strong>116-123</strong>.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Jelentés" on a post or a private message: what the problem is, an
|
||||
* optional note, and a thank-you (with the helpline for a crisis report).
|
||||
*/
|
||||
export function ReportButton({ path, className = "fp-tool" }: { path: string; className?: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [kind, setKind] = useState<ReportKind | "">("");
|
||||
const [note, setNote] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [done, setDone] = useState<{ crisis: boolean } | null>(null);
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!kind) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await api<{ crisis: boolean }>(path, { body: { kind, note } });
|
||||
setDone(res);
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (done) {
|
||||
return (
|
||||
<div className="frep" role="status">
|
||||
<p>Köszönjük, a moderátorok megnézik.</p>
|
||||
{done.crisis && <CrisisHelp />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!open) {
|
||||
return (
|
||||
<button type="button" className={className} onClick={() => setOpen(true)}>
|
||||
Jelentés
|
||||
</button>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<form className="frep" onSubmit={submit}>
|
||||
<fieldset className="fnew-set">
|
||||
<legend>Mi a gond?</legend>
|
||||
{REPORT_KINDS.map((k) => (
|
||||
<label key={k.kind} className="frep-kind">
|
||||
<input type="radio" name="report-kind" checked={kind === k.kind} onChange={() => setKind(k.kind)} />
|
||||
<span>{k.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
{kind === "crisis" && <CrisisHelp />}
|
||||
<label className="sr-only" htmlFor={`${path}-note`}>
|
||||
Megjegyzés
|
||||
</label>
|
||||
<textarea
|
||||
id={`${path}-note`}
|
||||
className="fc-text"
|
||||
rows={2}
|
||||
maxLength={500}
|
||||
value={note}
|
||||
onChange={(e) => setNote(e.target.value)}
|
||||
placeholder={kind === "other" ? "Írd le röviden, mi a gond." : "Megjegyzés (nem kötelező)"}
|
||||
/>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="fc-actions">
|
||||
<button type="button" className="btn btn-ghost btn-sm" onClick={() => setOpen(false)}>
|
||||
Mégse
|
||||
</button>
|
||||
<button type="submit" className="btn btn-primary btn-sm" disabled={busy || !kind}>
|
||||
{busy ? "Küldés…" : "Jelentés küldése"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user