translations :3

This commit is contained in:
k
2026-09-21 16:53:15 +02:00
parent af9b8c17d0
commit 66450303a1
2 changed files with 104 additions and 100 deletions
+53 -51
View File
@@ -5,6 +5,7 @@ import { AdminPanel } from "./AdminPanel.tsx";
import { AccessRequestsPanel } from "./AccessRequests.tsx";
import { Button, CopyButton, FlowerMark, Input, LoadingScreen, Spinner, Switch } from "./ui.tsx";
import { cn } from "../lib/cn.ts";
import { useT } from "../lib/i18n.ts";
type Tab = "accounts" | "access" | "features" | "mail";
@@ -15,20 +16,21 @@ function applyTheme(theme: string) {
root.style.colorScheme = dark ? "dark" : "light";
}
const TABS: { id: Tab; label: string; icon: typeof Users }[] = [
{ id: "accounts", label: "Accounts", icon: Users },
{ id: "access", label: "Access", icon: Inbox },
{ id: "features", label: "Features", icon: SlidersHorizontal },
{ id: "mail", label: "Mail", icon: Mail },
];
export function AdminCenter() {
const { t } = useT();
const [allowed, setAllowed] = useState<boolean | null>(null);
const [tab, setTab] = useState<Tab>("accounts");
const [settings, setSettings] = useState<{ registrationEnabled: boolean; accessRequestEnabled: boolean; ocrEnabled: boolean } | null>(null);
const [error, setError] = useState("");
const [saving, setSaving] = useState(false);
const TABS: { id: Tab; label: string; icon: typeof Users }[] = [
{ id: "accounts", label: t("center.tabAccounts"), icon: Users },
{ id: "access", label: t("center.tabAccess"), icon: Inbox },
{ id: "features", label: t("center.tabFeatures"), icon: SlidersHorizontal },
{ id: "mail", label: t("center.tabMail"), icon: Mail },
];
useEffect(() => {
api.verify()
.then((r) => {
@@ -38,7 +40,7 @@ export function AdminCenter() {
}
setAllowed(true);
applyTheme(r.user.theme);
api.adminGetSettings().then((s) => setSettings(s.settings)).catch((e) => setError(e instanceof Error ? e.message : "Load failed"));
api.adminGetSettings().then((s) => setSettings(s.settings)).catch((e) => setError(e instanceof Error ? e.message : t("admin.loadFailed")));
})
.catch(() => setAllowed(false));
}, []);
@@ -50,7 +52,7 @@ export function AdminCenter() {
const res = await api.adminPatchSettings(patch);
setSettings(res.settings);
} catch (e) {
setError(e instanceof Error ? e.message : "Save failed");
setError(e instanceof Error ? e.message : t("common.saveFailed"));
} finally {
setSaving(false);
}
@@ -65,9 +67,9 @@ export function AdminCenter() {
<div className="grid min-h-full place-items-center p-6">
<div className="w-full max-w-sm rounded-[2rem] border border-stone-200 bg-white p-8 text-center shadow-xl dark:border-zinc-800 dark:bg-zinc-900">
<ShieldAlert size={28} className="mx-auto mb-3 text-red-500" />
<h1 className="text-lg font-bold">Admins only</h1>
<p className="mt-1 text-sm opacity-60">Log in with the admin account to open the Admin Center.</p>
<a href="/" className="mt-4 inline-block rounded-full bg-accent-600 px-5 py-2.5 text-sm font-medium text-white dark:bg-accent-500 dark:text-zinc-950">Back to login</a>
<h1 className="text-lg font-bold">{t("center.locked")}</h1>
<p className="mt-1 text-sm opacity-60">{t("center.lockedSub")}</p>
<a href="/" className="mt-4 inline-block rounded-full bg-accent-600 px-5 py-2.5 text-sm font-medium text-white dark:bg-accent-500 dark:text-zinc-950">{t("common.backToLogin")}</a>
</div>
</div>
);
@@ -77,13 +79,13 @@ export function AdminCenter() {
<div className="min-h-full">
<header className="border-b border-stone-200/70 bg-white/70 backdrop-blur dark:border-zinc-800 dark:bg-zinc-900/70">
<div className="mx-auto flex w-full max-w-4xl items-center gap-3 px-4 py-3">
<a href="/" aria-label="Back to chat" className="rounded-full p-2 transition hover:bg-stone-200/60 dark:hover:bg-zinc-800">
<a href="/" aria-label={t("center.back")} className="rounded-full p-2 transition hover:bg-stone-200/60 dark:hover:bg-zinc-800">
<ArrowLeft size={18} />
</a>
<FlowerMark size={32} dynamic={false} />
<h1 className="flex items-center gap-2 text-lg font-bold tracking-tight">
<LayoutDashboard size={18} className="text-accent-600 dark:text-accent-400" />
Admin Center
{t("center.title")}
</h1>
</div>
<div className="mx-auto w-full max-w-4xl px-4 pb-3">
@@ -126,25 +128,25 @@ export function AdminCenter() {
<section className="space-y-3">
<div className="flex items-center gap-4 rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">Public registration</p>
<p className="text-sm opacity-60">Show the Register button on the login page. Off = admin-created accounts only. Turning it on retires the wishlist below.</p>
<p className="text-sm font-medium">{t("center.regTitle")}</p>
<p className="text-sm opacity-60">{t("center.regDesc")}</p>
</div>
<Switch label="Public registration" checked={settings?.registrationEnabled ?? false} onChange={(v) => toggle({ registrationEnabled: v })} />
<Switch label={t("center.regTitle")} checked={settings?.registrationEnabled ?? false} onChange={(v) => toggle({ registrationEnabled: v })} />
</div>
<div className={cn(
"flex items-center gap-4 rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900",
settings?.registrationEnabled && "opacity-60",
)}>
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">Access requests (wishlist)</p>
<p className="text-sm font-medium">{t("center.accTitle")}</p>
<p className="text-sm opacity-60">
{settings?.registrationEnabled
? "Unavailable while public registration is on — it replaces the wishlist."
: "Show Request access on the login page. Visitors reserve a username and plead their case; you triage them in the Access tab."}
? t("center.accDescOn")
: t("center.accDescOff")}
</p>
</div>
<Switch
label="Access requests"
label={t("center.accTitle")}
checked={settings?.accessRequestEnabled ?? false}
disabled={settings?.registrationEnabled ?? false}
onChange={(v) => toggle({ accessRequestEnabled: v })}
@@ -152,13 +154,13 @@ export function AdminCenter() {
</div>
<div className="flex items-center gap-4 rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<div className="min-w-0 flex-1">
<p className="text-sm font-medium">OCR tool</p>
<p className="text-sm opacity-60">Server-side image transcription for attachments. Requires the tesseract binary.</p>
<p className="text-sm font-medium">{t("center.ocrTitle")}</p>
<p className="text-sm opacity-60">{t("center.ocrDesc")}</p>
</div>
<Switch label="OCR tool" checked={settings?.ocrEnabled ?? false} onChange={(v) => toggle({ ocrEnabled: v })} />
<Switch label={t("center.ocrTitle")} checked={settings?.ocrEnabled ?? false} onChange={(v) => toggle({ ocrEnabled: v })} />
</div>
{saving && <p className="flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> Saving…</p>}
{!settings && !error && <p className="flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> Loading…</p>}
{saving && <p className="flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> {t("common.saving")}</p>}
{!settings && !error && <p className="flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> {t("common.loading")}</p>}
</section>
)}
@@ -181,6 +183,7 @@ type SmtpInfo = {
};
function MailPanel() {
const { t } = useT();
const [smtp, setSmtp] = useState<SmtpInfo | null>(null);
const [error, setError] = useState("");
const [showPass, setShowPass] = useState(false);
@@ -190,7 +193,7 @@ function MailPanel() {
const [result, setResult] = useState<{ ok: boolean; text: string } | null>(null);
useEffect(() => {
api.adminMailStatus().then((r) => setSmtp(r.smtp)).catch((e) => setError(e instanceof Error ? e.message : "Load failed"));
api.adminMailStatus().then((r) => setSmtp(r.smtp)).catch((e) => setError(e instanceof Error ? e.message : t("admin.loadFailed")));
}, []);
async function verify() {
@@ -198,9 +201,9 @@ function MailPanel() {
setResult(null);
try {
await api.adminMailVerify();
setResult({ ok: true, text: "Connection OK — SMTP host reachable, auth accepted." });
setResult({ ok: true, text: t("center.connOk") });
} catch (e) {
setResult({ ok: false, text: e instanceof Error ? e.message : "Verification failed" });
setResult({ ok: false, text: e instanceof Error ? e.message : t("center.verifyFailed") });
} finally {
setVerifying(false);
}
@@ -211,9 +214,9 @@ function MailPanel() {
setResult(null);
try {
const r = await api.adminMailTest(to.trim());
setResult({ ok: true, text: `Test mail sent to ${to.trim()}${r.messageId ? ` (${r.messageId})` : ""}.` });
setResult({ ok: true, text: t("center.testSent", { to: to.trim(), tail: r.messageId ? ` (${r.messageId})` : "" }) });
} catch (e) {
setResult({ ok: false, text: e instanceof Error ? e.message : "Send failed" });
setResult({ ok: false, text: e instanceof Error ? e.message : t("center.mailSendFailed") });
} finally {
setSending(false);
}
@@ -236,40 +239,40 @@ function MailPanel() {
<Mail size={17} />
</span>
<div>
<p className="text-sm font-medium">Key recovery emails</p>
<p className="text-sm font-medium">{t("center.mailTitle")}</p>
<p className="text-sm opacity-60">
{smtp == null ? "Checking…" : smtp.enabled ? `Enabled — sent from ${smtp.from}` : "Disabled — set SMTP_HOST on the server to enable"}
{smtp == null ? t("center.mailChecking") : smtp.enabled ? t("center.mailFrom", { from: smtp.from }) : t("center.mailOff")}
</p>
</div>
<span className={cn(
"ml-auto rounded-full px-3 py-1 text-xs font-medium",
smtp?.enabled ? "bg-emerald-600/10 text-emerald-700 dark:text-emerald-400" : "bg-stone-200/70 dark:bg-zinc-800",
)}>
{smtp?.enabled ? "On" : "Off"}
{smtp?.enabled ? t("center.on") : t("center.off")}
</span>
</div>
{error && <p className="mt-3 text-sm text-red-600 dark:text-red-400" role="alert">{error}</p>}
{!smtp && !error && <p className="mt-3 flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> Loading…</p>}
{!smtp && !error && <p className="mt-3 flex items-center gap-2 text-sm opacity-60"><Spinner size={14} /> {t("common.loading")}</p>}
{smtp && (
<div className="mt-3 divide-y divide-stone-200/70 rounded-2xl border border-stone-200/70 px-4 dark:divide-zinc-800 dark:border-zinc-800">
<Row label="Host">{smtp.host || <span className="opacity-50">(not set)</span>}</Row>
<Row label="Port">{smtp.port} · {smtp.secure ? "implicit TLS (465)" : "STARTTLS (587)"}</Row>
<Row label="User">{smtp.user || <span className="opacity-50">(no auth)</span>}</Row>
<Row label="Password">
<Row label={t("center.smtpHost")}>{smtp.host || <span className="opacity-50">{t("center.notSet")}</span>}</Row>
<Row label={t("center.smtpPort")}>{smtp.port} · {smtp.secure ? t("center.tlsImplicit") : t("center.tlsStarttls")}</Row>
<Row label={t("center.smtpUser")}>{smtp.user || <span className="opacity-50">{t("center.noAuth")}</span>}</Row>
<Row label={t("center.smtpPass")}>
<span className="flex items-center gap-2">
{!smtp.hasPass ? (
<span className="opacity-50">(not set)</span>
<span className="opacity-50">{t("center.notSet")}</span>
) : showPass ? (
<code className="truncate font-mono">{smtp.pass}</code>
) : (
<code className="select-none blur-sm" aria-label="hidden password">••••••••••</code>
<code className="select-none blur-sm" aria-label={t("center.hiddenPass")}>••••••••••</code>
)}
{smtp.hasPass && (
<>
<button
type="button"
onClick={() => setShowPass((v) => !v)}
aria-label={showPass ? "Hide SMTP password" : "Show SMTP password"}
aria-label={showPass ? t("center.hidePass") : t("center.showPass")}
className="rounded-full p-1.5 transition hover:bg-stone-200/60 dark:hover:bg-zinc-800"
>
{showPass ? <EyeOff size={15} /> : <Eye size={15} />}
@@ -279,37 +282,36 @@ function MailPanel() {
)}
</span>
</Row>
<Row label="From"><span className="truncate">{smtp.from}</span></Row>
<Row label="App URL"><span className="truncate">{smtp.appUrl}</span></Row>
<Row label={t("center.smtpFrom")}><span className="truncate">{smtp.from}</span></Row>
<Row label={t("center.smtpAppUrl")}><span className="truncate">{smtp.appUrl}</span></Row>
</div>
)}
<p className="mt-3 text-sm opacity-60">
Credentials live in the server environment (see <code>docs/OPERATIONS.md</code>), read-only here.
Users set their recovery address in profile settings or at account creation.
{t("center.credsNote")}
</p>
</section>
<section className="rounded-3xl border border-stone-200/70 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
<p className="text-sm font-medium">Connectivity test</p>
<p className="mt-0.5 text-sm opacity-60">Verify the connection, then send a real test mail to an address you control.</p>
<p className="text-sm font-medium">{t("center.mailTestTitle")}</p>
<p className="mt-0.5 text-sm opacity-60">{t("center.mailTestDesc")}</p>
<div className="mt-3 flex flex-wrap items-center gap-2">
<Button variant="secondary" size="sm" onClick={verify} disabled={verifying || !smtp?.enabled}>
{verifying ? <Spinner size={14} /> : null}
{verifying ? "Verifying…" : "Verify connection"}
{verifying ? t("center.verifying") : t("center.verifyConn")}
</Button>
</div>
<div className="mt-3 flex flex-col gap-2 sm:flex-row">
<Input
type="email"
placeholder="[email protected]"
aria-label="Test recipient email"
aria-label={t("center.testToAria")}
value={to}
onChange={(e) => setTo(e.target.value)}
className="flex-1"
/>
<Button size="sm" onClick={sendTest} disabled={sending || !smtp?.enabled || !/^[^\s@]{1,64}@[^\s@]{1,253}\.[^\s@]{2,}$/.test(to.trim())}>
{sending ? <Spinner size={14} /> : <Send size={14} />}
{sending ? "Sending…" : "Send test mail"}
{sending ? t("center.sendingMail") : t("center.sendTest")}
</Button>
</div>
{result && (