Merge branch 'feat/search-pagination-settings-tabs'
This commit is contained in:
@@ -5,6 +5,27 @@ versions follow [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.3.0] - 2026-10-28
|
||||
|
||||
### Added
|
||||
|
||||
- **Search and pages on every list.** Installs (searchable by church, address or version, with a
|
||||
health filter: critical, warnings, healthy, behind latest), Customers (name, contact, email,
|
||||
phone or site) and Alerts (message or install) each have a search box. Lists show 25 at a time
|
||||
with previous/next. The minute-by-minute refresh on Installs keeps you on the page you're on.
|
||||
An install's History shows 20 at a time.
|
||||
|
||||
### Changed
|
||||
|
||||
- **Settings is split into tabs**: Releases and alerts, Email, Login and security, and Audit log.
|
||||
The open tab is kept in the address (`/settings#email`), so a reload or a link lands on it. The
|
||||
audit log has a search box and shows 30 entries at a time.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Sign out** stayed at the bottom of the page on long pages, so it scrolled out of view. The
|
||||
side navigation now stays fixed to the window height.
|
||||
|
||||
## [1.2.0] - 2026-10-28
|
||||
|
||||
### Added
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-backend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-backend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/adapter-pg": "^7.10.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-backend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"private": true,
|
||||
"description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats",
|
||||
"main": "src/index.js",
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "events-hub-frontend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"dependencies": {
|
||||
"lucide-react": "^0.536.0",
|
||||
"next": "^15.5.24",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "events-hub-frontend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -p 3200",
|
||||
|
||||
@@ -1,29 +1,35 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import type { InstallEvent } from "@/lib/types";
|
||||
import { Badge, Loading, PageTitle } from "@/components/ui";
|
||||
import { Badge, Loading, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
|
||||
/** Open alerts, and the history of everything that happened to installs. */
|
||||
export default function AlertsPage() {
|
||||
const [openOnly, setOpenOnly] = useState(true);
|
||||
const [events, setEvents] = useState<InstallEvent[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
setEvents(null);
|
||||
api<InstallEvent[]>(`/api/admin/events${openOnly ? "?open=true" : ""}`).then(setEvents).catch(e => setError(errorText(e)));
|
||||
}, [openOnly]);
|
||||
|
||||
const shown = useMemo(() => (events || []).filter(e => matches(query, e.message, e.level, e.install?.name, e.install?.url)), [events, query]);
|
||||
const paged = usePaged(shown, `${query}|${openOnly}`);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageTitle title="Alerts" subtitle="Checked every 5 minutes. New warnings and critical alerts are emailed once (Settings → Alert email)." />
|
||||
<div className="mb-4 flex gap-2">
|
||||
<PageTitle title="Alerts" subtitle="Checked every 5 minutes. New warnings and critical alerts are emailed once (Settings → Releases and alerts → Alert email)." />
|
||||
<div className="mb-4 flex flex-wrap gap-2">
|
||||
<button className={openOnly ? "btn-primary" : "btn-secondary"} onClick={() => setOpenOnly(true)}>Open</button>
|
||||
<button className={!openOnly ? "btn-primary" : "btn-secondary"} onClick={() => setOpenOnly(false)}>Everything</button>
|
||||
<SearchInput className="w-full sm:ml-auto sm:w-72" value={query} onChange={setQuery} placeholder="Search alerts or install" />
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-700">{error}</p>}
|
||||
{!events ? <Loading /> : events.length === 0 ? <p className="text-sm text-slate-500">{openOnly ? "No open alerts. 🎉" : "Nothing yet."}</p> : (
|
||||
@@ -31,7 +37,8 @@ export default function AlertsPage() {
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500"><tr><th className="p-3">When</th><th className="p-3">Install</th><th className="p-3">What</th><th className="p-3">State</th></tr></thead>
|
||||
<tbody>
|
||||
{events.map(e => (
|
||||
{paged.rows.length === 0 && <tr><td colSpan={4} className="p-3 text-slate-500">No alerts match.</td></tr>}
|
||||
{paged.rows.map(e => (
|
||||
<tr key={e.id} className="border-t align-top">
|
||||
<td className="p-3 whitespace-nowrap text-xs text-slate-500">{fmtDate(e.createdAt)}</td>
|
||||
<td className="p-3">{e.install ? <Link href={`/installs/${e.install.id}`} className="text-indigo-700 hover:underline">{e.install.name}</Link> : "—"}</td>
|
||||
@@ -41,6 +48,7 @@ export default function AlertsPage() {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<Pager {...paged} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Plus } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import type { Customer } from "@/lib/types";
|
||||
import { Badge, Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { Badge, Loading, Message, PageTitle, Pager, SearchInput } from "@/components/ui";
|
||||
|
||||
export default function CustomersPage() {
|
||||
const router = useRouter();
|
||||
@@ -16,6 +17,10 @@ export default function CustomersPage() {
|
||||
const [form, setForm] = useState({ name: "", contactName: "", email: "", phone: "" });
|
||||
const [msg, setMsg] = useState<{ type: "ok" | "err"; text: string } | null>(null);
|
||||
|
||||
const [query, setQuery] = useState("");
|
||||
const shown = useMemo(() => (list || []).filter(c => matches(query, c.name, c.contactName, c.email, c.phone, ...c.installs.map(i => i.url))), [list, query]);
|
||||
const paged = usePaged(shown, query);
|
||||
|
||||
const load = useCallback(() => api<Customer[]>("/api/admin/customers").then(setList).catch(e => setMsg({ type: "err", text: errorText(e) })), []);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
|
||||
@@ -41,11 +46,14 @@ export default function CustomersPage() {
|
||||
)}
|
||||
<Message msg={msg} />
|
||||
{!list ? <Loading /> : list.length === 0 ? <p className="text-sm text-slate-500">No customers yet.</p> : (
|
||||
<>
|
||||
<SearchInput className="mb-3 w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search name, contact or site" />
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500"><tr><th className="p-3">Customer</th><th className="p-3">Licences</th><th className="p-3">Site</th></tr></thead>
|
||||
<tbody>
|
||||
{list.map(c => (
|
||||
{paged.rows.length === 0 && <tr><td colSpan={3} className="p-3 text-slate-500">No customers match.</td></tr>}
|
||||
{paged.rows.map(c => (
|
||||
<tr key={c.id} className="border-t hover:bg-slate-50">
|
||||
<td className="p-3"><Link href={`/customers/${c.id}`} className="font-medium text-indigo-700 hover:underline">{c.name}</Link><div className="text-xs text-slate-500">{[c.contactName, c.email].filter(Boolean).join(" · ")}</div></td>
|
||||
<td className="p-3">{c.licences.length ? c.licences.map(l => <span key={l.id} className="mr-1"><Badge value={l.status} /></span>) : <span className="text-xs text-slate-400">none</span>}</td>
|
||||
@@ -54,7 +62,9 @@ export default function CustomersPage() {
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<Pager {...paged} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -6,8 +6,9 @@ import { useParams } from "next/navigation";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, bytes, fmtDate, rand } from "@/lib/format";
|
||||
import { usePaged } from "@/lib/paging";
|
||||
import type { Health, InstallEvent, InstallSummary, Licence, Stats } from "@/lib/types";
|
||||
import { Badge, Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { Badge, Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
|
||||
type Detail = {
|
||||
id: string; name: string; url: string; version: string | null; protocolVersion: number; timezone: string | null; notes: string | null;
|
||||
@@ -21,7 +22,9 @@ type Detail = {
|
||||
heartbeats: { receivedAt: string; version: string | null; stats: Stats | null }[];
|
||||
};
|
||||
|
||||
const Row = ({ k, v }: { k: string; v: React.ReactNode }) => (
|
||||
const NO_EVENTS: InstallEvent[] = [];
|
||||
|
||||
const Row =({ k, v }: { k: string; v: React.ReactNode }) => (
|
||||
<div className="flex justify-between gap-4 border-b border-slate-100 py-1.5 text-sm last:border-0"><span className="text-slate-500">{k}</span><span className="text-right">{v}</span></div>
|
||||
);
|
||||
|
||||
@@ -34,6 +37,7 @@ export default function InstallPage() {
|
||||
|
||||
const load = useCallback(() => api<Detail>(`/api/admin/installs/${id}`).then(x => { setD(x); setNotes(x.notes || ""); }).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]);
|
||||
useEffect(() => { load(); }, [load]);
|
||||
const history = usePaged(d?.events || NO_EVENTS, id, 20);
|
||||
|
||||
if (!d) return msg ? <Message msg={msg} /> : <Loading />;
|
||||
const h = d.health || {};
|
||||
@@ -134,8 +138,9 @@ export default function InstallPage() {
|
||||
<div className="card mt-6">
|
||||
<h2 className="mb-3 font-semibold">History</h2>
|
||||
{d.events.length === 0 ? <p className="text-sm text-slate-500">Nothing yet.</p> : (
|
||||
<>
|
||||
<ul className="space-y-2 text-sm">
|
||||
{d.events.map(e => (
|
||||
{history.rows.map(e => (
|
||||
<li key={e.id} className="flex flex-wrap items-center gap-2">
|
||||
<span className="w-40 shrink-0 text-xs text-slate-500">{fmtDate(e.createdAt)}</span>
|
||||
<Badge value={e.level} />
|
||||
@@ -144,6 +149,8 @@ export default function InstallPage() {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div className="-mx-5 -mb-5 mt-3"><Pager {...history} /></div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -33,7 +33,8 @@ export default function HubLayout({ children }: { children: React.ReactNode }) {
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen">
|
||||
<aside className="hidden w-56 shrink-0 border-r border-slate-200 bg-white p-4 md:flex md:flex-col">
|
||||
{/* Pinned to the window, so Sign out stays in view however long the page is. */}
|
||||
<aside className="sticky top-0 hidden h-screen w-56 shrink-0 overflow-y-auto border-r border-slate-200 bg-white p-4 md:flex md:flex-col">
|
||||
<div className="mb-6 px-2">
|
||||
<Logo />
|
||||
<div className="mt-1 pl-[2.625rem] text-xs text-slate-500">{me.name}</div>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import type { InstallSummary } from "@/lib/types";
|
||||
import { Badge, Loading, PageTitle, Stat } from "@/components/ui";
|
||||
import { Badge, Loading, PageTitle, Pager, SearchInput, Stat } from "@/components/ui";
|
||||
|
||||
type Dashboard = {
|
||||
latestVersion: string | null;
|
||||
@@ -13,10 +14,21 @@ type Dashboard = {
|
||||
installs: InstallSummary[];
|
||||
};
|
||||
|
||||
type Health = "all" | InstallSummary["status"] | "behind";
|
||||
const HEALTH: { key: Health; label: string }[] = [
|
||||
{ key: "all", label: "All health" },
|
||||
{ key: "critical", label: "Critical" },
|
||||
{ key: "warning", label: "Warnings" },
|
||||
{ key: "ok", label: "Healthy" },
|
||||
{ key: "behind", label: "Behind latest" },
|
||||
];
|
||||
|
||||
/** Every install at a glance: health, version, licence, last heartbeat. */
|
||||
export default function OverviewPage() {
|
||||
const [data, setData] = useState<Dashboard | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState("");
|
||||
const [health, setHealth] = useState<Health>("all");
|
||||
|
||||
useEffect(() => {
|
||||
const load = () => api<Dashboard>("/api/admin/dashboard").then(d => { setData(d); setError(null); }).catch(e => setError(errorText(e)));
|
||||
@@ -25,6 +37,12 @@ export default function OverviewPage() {
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
|
||||
const shown = useMemo(() => (data?.installs || []).filter(i =>
|
||||
(health === "all" || (health === "behind" ? i.behind : i.status === health))
|
||||
&& matches(query, i.customer?.name, i.name, i.url, i.version),
|
||||
), [data, query, health]);
|
||||
const paged = usePaged(shown, `${query}|${health}`);
|
||||
|
||||
if (error) return <p className="text-sm text-red-700">{error}</p>;
|
||||
if (!data) return <Loading />;
|
||||
const c = data.counts;
|
||||
@@ -45,32 +63,42 @@ export default function OverviewPage() {
|
||||
No installs yet. Add a <Link href="/customers" className="text-indigo-600 hover:underline">customer</Link>, generate a licence, and enter its key in the church's Cross Events setup.
|
||||
</div>
|
||||
) : (
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500">
|
||||
<tr><th className="p-3">Install</th><th className="p-3">Health</th><th className="p-3">Version</th><th className="p-3">Licence</th><th className="p-3">Last heartbeat</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.installs.map(i => (
|
||||
<tr key={i.id} className="border-t align-top hover:bg-slate-50">
|
||||
<td className="p-3">
|
||||
<Link href={`/installs/${i.id}`} className="font-medium text-indigo-700 hover:underline">{i.customer?.name || i.name}</Link>
|
||||
<div className="text-xs text-slate-500">{i.url}</div>
|
||||
</td>
|
||||
<td className="p-3">
|
||||
<Badge value={i.status} />
|
||||
{i.problems.filter(p => p.level !== "info").map(p => <div key={p.type} className="mt-1 text-xs text-slate-600">{p.message}</div>)}
|
||||
</td>
|
||||
<td className="p-3 whitespace-nowrap">{i.version || "—"}{i.behind && <span className="ml-1 text-xs text-amber-700">(behind)</span>}</td>
|
||||
<td className="p-3 whitespace-nowrap">
|
||||
{i.licence ? <><Badge value={i.licence.status} />{i.licence.expiresAt && <div className="mt-1 text-xs text-slate-500">to {fmtDate(i.licence.expiresAt, false)}</div>}</> : <span className="text-xs text-slate-400">none</span>}
|
||||
</td>
|
||||
<td className="p-3 whitespace-nowrap" title={fmtDate(i.lastHeartbeatAt)}>{ago(i.lastHeartbeatAt)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<>
|
||||
<div className="mb-3 flex flex-wrap gap-2">
|
||||
<SearchInput className="w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search church, address or version" />
|
||||
<select className="input w-auto" aria-label="Health" value={health} onChange={e => setHealth(e.target.value as Health)}>
|
||||
{HEALTH.map(h => <option key={h.key} value={h.key}>{h.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500">
|
||||
<tr><th className="p-3">Install</th><th className="p-3">Health</th><th className="p-3">Version</th><th className="p-3">Licence</th><th className="p-3">Last heartbeat</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{paged.rows.length === 0 && <tr><td colSpan={5} className="p-3 text-slate-500">No installs match.</td></tr>}
|
||||
{paged.rows.map(i => (
|
||||
<tr key={i.id} className="border-t align-top hover:bg-slate-50">
|
||||
<td className="p-3">
|
||||
<Link href={`/installs/${i.id}`} className="font-medium text-indigo-700 hover:underline">{i.customer?.name || i.name}</Link>
|
||||
<div className="text-xs text-slate-500">{i.url}</div>
|
||||
</td>
|
||||
<td className="p-3">
|
||||
<Badge value={i.status} />
|
||||
{i.problems.filter(p => p.level !== "info").map(p => <div key={p.type} className="mt-1 text-xs text-slate-600">{p.message}</div>)}
|
||||
</td>
|
||||
<td className="p-3 whitespace-nowrap">{i.version || "—"}{i.behind && <span className="ml-1 text-xs text-amber-700">(behind)</span>}</td>
|
||||
<td className="p-3 whitespace-nowrap">
|
||||
{i.licence ? <><Badge value={i.licence.status} />{i.licence.expiresAt && <div className="mt-1 text-xs text-slate-500">to {fmtDate(i.licence.expiresAt, false)}</div>}</> : <span className="text-xs text-slate-400">none</span>}
|
||||
</td>
|
||||
<td className="p-3 whitespace-nowrap" title={fmtDate(i.lastHeartbeatAt)}>{ago(i.lastHeartbeatAt)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<Pager {...paged} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { api, errorText, setToken } from "@/lib/api";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
import { Loading, Message, PageTitle } from "@/components/ui";
|
||||
import { matches, usePaged } from "@/lib/paging";
|
||||
import { Loading, Message, PageTitle, Pager, SearchInput, Tabs } from "@/components/ui";
|
||||
|
||||
type Settings = Record<string, string>;
|
||||
type AuditRow = { id: string; action: string; target: string | null; metadata: unknown; createdAt: string; actor: { name: string } | null };
|
||||
@@ -19,11 +20,21 @@ const FIELDS: { key: string; label: string; hint: string; type?: string }[] = [
|
||||
{ key: "licence_expiry_warning_days", label: "Warn about licence expiry (days before)", hint: "Default 14.", type: "number" },
|
||||
];
|
||||
|
||||
type Tab = "alerts" | "email" | "security" | "audit";
|
||||
const TABS: { key: Tab; label: string }[] = [
|
||||
{ key: "alerts", label: "Releases and alerts" },
|
||||
{ key: "email", label: "Email" },
|
||||
{ key: "security", label: "Login and security" },
|
||||
{ key: "audit", label: "Audit log" },
|
||||
];
|
||||
|
||||
export default function SettingsPage() {
|
||||
const [tab, setTab] = useState<Tab>("alerts");
|
||||
const [settings, setSettings] = useState<Settings | null>(null);
|
||||
const [publicKey, setPublicKey] = useState("");
|
||||
const [smtp, setSmtp] = useState(false);
|
||||
const [audit, setAudit] = useState<AuditRow[]>([]);
|
||||
const [auditQuery, setAuditQuery] = useState("");
|
||||
const [pw, setPw] = useState({ currentPassword: "", newPassword: "" });
|
||||
const [msg, setMsg] = useState<Msg>(null);
|
||||
const [smtpPass, setSmtpPass] = useState({ value: "", clear: false });
|
||||
@@ -33,10 +44,22 @@ export default function SettingsPage() {
|
||||
useEffect(() => {
|
||||
api<{ settings: Settings; publicKey: string; smtp: boolean }>("/api/admin/settings").then(r => { setSettings(r.settings); setPublicKey(r.publicKey); setSmtp(r.smtp); }).catch(e => setMsg({ type: "err", text: errorText(e) }));
|
||||
api<AuditRow[]>("/api/admin/audit").then(setAudit).catch(() => {});
|
||||
// Open the tab named in the address (#email), so a reload or a link lands in the same place.
|
||||
const fromHash = window.location.hash.slice(1);
|
||||
if (TABS.some(t => t.key === fromHash)) setTab(fromHash as Tab);
|
||||
}, []);
|
||||
|
||||
const auditShown = useMemo(() => audit.filter(a => matches(auditQuery, a.action.replace(/_/g, " "), a.actor?.name, a.target, a.metadata ? JSON.stringify(a.metadata) : "")), [audit, auditQuery]);
|
||||
const auditPaged = usePaged(auditShown, auditQuery, 30);
|
||||
|
||||
if (!settings) return msg ? <Message msg={msg} /> : <Loading />;
|
||||
|
||||
const openTab = (t: Tab) => {
|
||||
setTab(t);
|
||||
setMsg(null);
|
||||
window.history.replaceState(null, "", `#${t}`);
|
||||
};
|
||||
|
||||
const save = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
@@ -93,23 +116,25 @@ export default function SettingsPage() {
|
||||
return (
|
||||
<>
|
||||
<PageTitle title="Settings" />
|
||||
<div className="mb-4"><Message msg={msg} /></div>
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
<form onSubmit={save} className="card space-y-4">
|
||||
<h2 className="font-semibold">Releases and alerts</h2>
|
||||
{FIELDS.map(f => (
|
||||
<div key={f.key}>
|
||||
<label className="label" htmlFor={f.key}>{f.label}</label>
|
||||
<input id={f.key} className="input" type={f.type || "text"} value={settings[f.key] ?? ""} onChange={e => setSettings({ ...settings, [f.key]: e.target.value })} />
|
||||
<p className="mt-1 text-xs text-slate-500">{f.hint}</p>
|
||||
</div>
|
||||
))}
|
||||
<button className="btn-primary">Save settings</button>
|
||||
</form>
|
||||
<Tabs tabs={TABS} active={tab} onChange={openTab} />
|
||||
{msg && <div className="mb-4"><Message msg={msg} /></div>}
|
||||
|
||||
<div className="space-y-6">
|
||||
<form onSubmit={saveSmtp} className="card space-y-3">
|
||||
<h2 className="font-semibold">Email (SMTP)</h2>
|
||||
<div role="tabpanel" id={`panel-${tab}`} aria-labelledby={`tab-${tab}`}>
|
||||
{tab === "alerts" && (
|
||||
<form onSubmit={save} className="card max-w-2xl space-y-4">
|
||||
{FIELDS.map(f => (
|
||||
<div key={f.key}>
|
||||
<label className="label" htmlFor={f.key}>{f.label}</label>
|
||||
<input id={f.key} className="input" type={f.type || "text"} value={settings[f.key] ?? ""} onChange={e => setSettings({ ...settings, [f.key]: e.target.value })} />
|
||||
<p className="mt-1 text-xs text-slate-500">{f.hint}</p>
|
||||
</div>
|
||||
))}
|
||||
<button className="btn-primary">Save settings</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{tab === "email" && (
|
||||
<form onSubmit={saveSmtp} className="card max-w-2xl space-y-3">
|
||||
<p className="text-sm text-slate-600">The mail server alert emails are sent through. The password is stored encrypted.</p>
|
||||
{!smtp && <p className="rounded-lg bg-amber-50 p-3 text-sm text-amber-900">Email isn't set up, so alerts are only logged.</p>}
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
@@ -136,38 +161,47 @@ export default function SettingsPage() {
|
||||
<p className="mt-1 text-xs text-slate-500">Tries what's in the form, saved or not. Blank sends to the alert email.</p>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<div className="card space-y-2">
|
||||
<h2 className="font-semibold">Licence signing key</h2>
|
||||
<p className="text-sm text-slate-600">Installs check licences with this public key (built into Cross Events: <code>backend/src/hub/publicKey.js</code>). The private key stays on this server only — keep a backup.</p>
|
||||
<pre className="overflow-x-auto rounded-lg bg-slate-50 p-3 text-xs">{publicKey}</pre>
|
||||
</div>
|
||||
{tab === "security" && (
|
||||
<div className="max-w-2xl space-y-6">
|
||||
<form onSubmit={changePassword} className="card space-y-3">
|
||||
<h2 className="font-semibold">Your login</h2>
|
||||
<div><label className="label" htmlFor="current_password">Current password</label><input id="current_password" type="password" className="input" autoComplete="current-password" value={pw.currentPassword} onChange={e => setPw({ ...pw, currentPassword: e.target.value })} required /></div>
|
||||
<div><label className="label" htmlFor="new_password">New password (12+ characters)</label><input id="new_password" type="password" className="input" autoComplete="new-password" minLength={12} value={pw.newPassword} onChange={e => setPw({ ...pw, newPassword: e.target.value })} required /></div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button className="btn-secondary">Change password</button>
|
||||
<button type="button" className="btn-danger" onClick={signOutEverywhere}>Sign out everywhere</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form onSubmit={changePassword} className="card space-y-3">
|
||||
<h2 className="font-semibold">Your login</h2>
|
||||
<div><label className="label">Current password</label><input type="password" className="input" autoComplete="current-password" value={pw.currentPassword} onChange={e => setPw({ ...pw, currentPassword: e.target.value })} required /></div>
|
||||
<div><label className="label">New password (12+ characters)</label><input type="password" className="input" autoComplete="new-password" minLength={12} value={pw.newPassword} onChange={e => setPw({ ...pw, newPassword: e.target.value })} required /></div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button className="btn-secondary">Change password</button>
|
||||
<button type="button" className="btn-danger" onClick={signOutEverywhere}>Sign out everywhere</button>
|
||||
<div className="card space-y-2">
|
||||
<h2 className="font-semibold">Licence signing key</h2>
|
||||
<p className="text-sm text-slate-600">Installs check licences with this public key (built into Cross Events: <code>backend/src/hub/publicKey.js</code>). The private key stays on this server only — keep a backup.</p>
|
||||
<pre className="overflow-x-auto rounded-lg bg-slate-50 p-3 text-xs">{publicKey}</pre>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card mt-6">
|
||||
<h2 className="mb-3 font-semibold">Audit log</h2>
|
||||
{audit.length === 0 ? <p className="text-sm text-slate-500">Nothing yet.</p> : (
|
||||
<ul className="space-y-1 text-sm">
|
||||
{audit.map(a => (
|
||||
<li key={a.id} className="flex flex-wrap gap-2">
|
||||
<span className="w-40 shrink-0 text-xs text-slate-500">{fmtDate(a.createdAt)}</span>
|
||||
<span className="font-medium">{a.actor?.name || "—"}</span>
|
||||
<span>{a.action.replace(/_/g, " ")}</span>
|
||||
{a.metadata ? <span className="text-xs text-slate-400 break-all">{JSON.stringify(a.metadata)}</span> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{tab === "audit" && (
|
||||
<>
|
||||
<SearchInput className="mb-3 w-full sm:w-72" value={auditQuery} onChange={setAuditQuery} placeholder="Search who or what" />
|
||||
<div className="card p-0">
|
||||
{audit.length === 0 ? <p className="p-5 text-sm text-slate-500">Nothing yet.</p> : auditShown.length === 0 ? <p className="p-5 text-sm text-slate-500">Nothing matches.</p> : (
|
||||
<ul className="space-y-1 p-5 text-sm">
|
||||
{auditPaged.rows.map(a => (
|
||||
<li key={a.id} className="flex flex-wrap gap-2">
|
||||
<span className="w-40 shrink-0 text-xs text-slate-500">{fmtDate(a.createdAt)}</span>
|
||||
<span className="font-medium">{a.actor?.name || "—"}</span>
|
||||
<span>{a.action.replace(/_/g, " ")}</span>
|
||||
{a.metadata ? <span className="text-xs text-slate-400 break-all">{JSON.stringify(a.metadata)}</span> : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<Pager {...auditPaged} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { ChevronLeft, ChevronRight, Search } from "lucide-react";
|
||||
import type { LicenceStatus, Problem } from "@/lib/types";
|
||||
|
||||
const STATUS_TONE: Record<string, string> = {
|
||||
@@ -71,3 +72,50 @@ export function Stat({ label, value, tone }: { label: string; value: React.React
|
||||
export function Loading() {
|
||||
return <p className="text-sm text-slate-400">Loading…</p>;
|
||||
}
|
||||
|
||||
export function SearchInput({ value, onChange, placeholder = "Search", className = "" }: { value: string; onChange: (v: string) => void; placeholder?: string; className?: string }) {
|
||||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400" aria-hidden="true" />
|
||||
<input type="search" className="input pl-9" aria-label={placeholder} placeholder={placeholder} value={value} onChange={e => onChange(e.target.value)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** "21–40 of 132" with previous/next, under a paged table. Hidden when everything fits on one page. */
|
||||
export function Pager({ page, pages, setPage, total, pageSize }: { page: number; pages: number; setPage: (p: number) => void; total: number; pageSize: number }) {
|
||||
if (pages <= 1) return null;
|
||||
const from = (page - 1) * pageSize + 1;
|
||||
return (
|
||||
<nav aria-label="Pages" className="flex flex-wrap items-center justify-between gap-2 border-t border-slate-200 px-3 py-2 text-sm text-slate-600">
|
||||
<span className="tabular-nums">{from}–{Math.min(page * pageSize, total)} of {total}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<button type="button" className="btn-secondary px-2 py-1" disabled={page <= 1} onClick={() => setPage(page - 1)} aria-label="Previous page"><ChevronLeft className="h-4 w-4" /></button>
|
||||
<span className="tabular-nums">Page {page} of {pages}</span>
|
||||
<button type="button" className="btn-secondary px-2 py-1" disabled={page >= pages} onClick={() => setPage(page + 1)} aria-label="Next page"><ChevronRight className="h-4 w-4" /></button>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
/** A row of tabs; the panel is whatever the page renders for the active one. */
|
||||
export function Tabs<K extends string>({ tabs, active, onChange }: { tabs: { key: K; label: string }[]; active: K; onChange: (k: K) => void }) {
|
||||
return (
|
||||
<div role="tablist" className="mb-6 flex gap-1 overflow-x-auto border-b border-slate-200">
|
||||
{tabs.map(t => (
|
||||
<button
|
||||
key={t.key}
|
||||
type="button"
|
||||
role="tab"
|
||||
id={`tab-${t.key}`}
|
||||
aria-selected={active === t.key}
|
||||
aria-controls={`panel-${t.key}`}
|
||||
onClick={() => onChange(t.key)}
|
||||
className={`-mb-px whitespace-nowrap border-b-2 px-3 py-2 text-sm ${active === t.key ? "border-indigo-600 font-medium text-indigo-700" : "border-transparent text-slate-600 hover:text-slate-900"}`}
|
||||
>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
/** True when every word of the query appears in one of the fields (case-insensitive). */
|
||||
export function matches(query: string, ...fields: (string | number | null | undefined)[]) {
|
||||
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
||||
if (!words.length) return true;
|
||||
const hay = fields.filter(f => f != null).join(" ").toLowerCase();
|
||||
return words.every(w => hay.includes(w));
|
||||
}
|
||||
|
||||
/**
|
||||
* One page of a list. Goes back to the first page when `resetKey` changes (the search or filter),
|
||||
* but not when the same list is reloaded.
|
||||
*/
|
||||
export function usePaged<T>(items: T[], resetKey: unknown, pageSize = 25) {
|
||||
const [page, setPage] = useState(1);
|
||||
const pages = Math.max(1, Math.ceil(items.length / pageSize));
|
||||
useEffect(() => { setPage(1); }, [resetKey]);
|
||||
const current = Math.min(page, pages);
|
||||
const rows = useMemo(() => items.slice((current - 1) * pageSize, current * pageSize), [items, current, pageSize]);
|
||||
return { rows, page: current, pages, setPage, total: items.length, pageSize };
|
||||
}
|
||||
Reference in New Issue
Block a user