Away mode, and critical alerts through quiet hours

For a one-person homelab, "on call" is when you can be reached. Settings ->
Notifications -> When -> Away holds notifications while you are away (a banner on
every page says so) and sends one digest when it ends, at its time or when you say
you are back. Critical alerts can still come through. Quiet hours get the same
"still send critical alerts" option. Escalation steps marked to send in quiet hours
are sent while away too. What is held for one reason is not released while the
other still holds it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-22 19:14:29 +02:00
1 parent 3b31b16796
commit 16b24f5436
21 files changed
+737 -50

No files matched your search

+163
View File
@@ -0,0 +1,163 @@
import { useEffect, useState } from "react";
import { api, type AwayView } from "../../api/client";
import TimeAgo from "../../components/TimeAgo";
import { confirmDialog } from "../../utils/dialogs";
import { formatDateTime } from "../../utils/date";
import { readableError } from "../../utils/errors";
import { toast } from "../../utils/toast";
/** "2026-10-25T18:00" for a datetime-local input, from a moment. */
function wall(ms: number): string {
const d = new Date(ms);
const p = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(d.getHours())}:${p(d.getMinutes())}`;
}
/** Tomorrow, next Sunday, in a week — at 18:00, which is about when most people are home again. */
function presets(): { label: string; value: string }[] {
const at18 = (offsetDays: number) => {
const d = new Date();
d.setDate(d.getDate() + offsetDays);
d.setHours(18, 0, 0, 0);
return wall(d.getTime());
};
const untilSunday = (7 - new Date().getDay()) % 7 || 7;
return [
{ label: "Until tomorrow evening", value: at18(1) },
{ label: "Until Sunday evening", value: at18(untilSunday) },
{ label: "A week", value: at18(7) },
{ label: "Two weeks", value: at18(14) },
];
}
/**
* "I'm away until Sunday." Notifications are held while it lasts and sent as one digest when it ends (at its time, or when you say you are back); critical alerts can still come
* through. Everyone sees that somebody is away; an administrator sets it. The times are the clock of the screen it is set on.
*/
export default function AwayCard({ canEdit }: { canEdit: boolean }) {
const [view, setView] = useState<AwayView | null>(null);
const [until, setUntil] = useState("");
const [from, setFrom] = useState("");
const [critical, setCritical] = useState(true);
const [note, setNote] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
function load() {
api.away
.get()
.then((v) => {
setView(v);
setCritical(v.away.criticalThrough);
})
.catch((err) => setError(readableError(err)));
}
useEffect(load, []);
async function start(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
try {
// What is typed is the clock on this screen, so it is sent as the exact moment it means.
const v = await api.away.start({ until: new Date(until).toISOString(), from: from ? new Date(from).toISOString() : null, criticalThrough: critical, note });
setView(v);
toast.success(v.away.state === "planned" ? "Away mode planned." : "Away mode is on — notifications are held.");
window.dispatchEvent(new Event("away-changed"));
setUntil("");
setFrom("");
setNote("");
} catch (err) {
setError(readableError(err));
} finally {
setBusy(false);
}
}
async function end() {
const planned = view?.away.state === "planned";
if (!planned && view && view.held > 0 && !(await confirmDialog({ title: "Back already?", message: `${view.held} notification${view.held === 1 ? " was" : "s were"} held. They are sent now as one digest.`, confirmLabel: "I'm back" }))) return;
setBusy(true);
try {
const v = await api.away.end();
setView(v);
toast.success(planned ? "Cancelled." : v.sent ? `Welcome back — ${v.sent} held notification${v.sent === 1 ? "" : "s"} sent.` : "Welcome back.");
window.dispatchEvent(new Event("away-changed"));
} catch (err) {
setError(readableError(err));
} finally {
setBusy(false);
}
}
const a = view?.away;
const on = a && a.state !== "none";
return (
<div className="card h-100">
<div className="card-header">
<h3 className="card-title">Away</h3>
</div>
<div className="card-body">
<p className="text-secondary">
Going away? Say until when. Notifications are held while you are gone and sent as one digest when it ends, so a week of warnings is one message to read rather than a buzzing phone. Critical alerts can still come
through. Quiet hours below are for every night; this is for a stretch.
</p>
{error && <div className="alert alert-danger py-2">{error}</div>}
{on && a ? (
<div className="border rounded p-3 mb-2">
<div className="fw-bold">{a.state === "planned" ? "Planned" : "Away"} until {formatDateTime(new Date(a.until!))}</div>
<div className="text-secondary small">
{a.state === "planned" && a.from ? (
<>
Starts {formatDateTime(new Date(a.from))} (<TimeAgo value={a.from} />).{" "}
</>
) : null}
{a.criticalThrough ? "Critical alerts are still sent." : "Everything is held, critical alerts too."}
{a.note ? ` “${a.note}”` : ""} {a.state === "active" ? `${view!.held} held so far.` : ""}
</div>
{canEdit && (
<button className="btn btn-sm btn-primary mt-2" onClick={() => void end()} disabled={busy}>
{a.state === "planned" ? "Cancel it" : "I'm back"}
</button>
)}
</div>
) : null}
{canEdit && (
<form onSubmit={start}>
<div className="d-flex flex-wrap gap-2 mb-2">
{presets().map((p) => (
<button key={p.label} type="button" className={`btn btn-sm ${until === p.value ? "btn-primary" : "btn-outline-secondary"}`} onClick={() => setUntil(p.value)}>
{p.label}
</button>
))}
</div>
<div className="row g-2 mb-2">
<div className="col-sm-6">
<label className="form-label" htmlFor="away-until">
{on ? "Change to: back at" : "Back at"}
</label>
<input id="away-until" type="datetime-local" className="form-control" required value={until} onChange={(e) => setUntil(e.target.value)} />
</div>
<div className="col-sm-6">
<label className="form-label" htmlFor="away-from">
Starting (blank = now)
</label>
<input id="away-from" type="datetime-local" className="form-control" value={from} onChange={(e) => setFrom(e.target.value)} />
</div>
</div>
<input className="form-control mb-2" maxLength={200} placeholder="A note to yourself, e.g. Holiday in Spain (optional)" aria-label="Note" value={note} onChange={(e) => setNote(e.target.value)} />
<label className="form-check mb-3">
<input type="checkbox" className="form-check-input" checked={critical} onChange={(e) => setCritical(e.target.checked)} />
<span className="form-check-label">Still send critical alerts (a server down, a disk full, mains power lost)</span>
</label>
<button className="btn btn-primary" disabled={busy || until === ""}>
{busy ? "Saving…" : on ? "Change it" : "Start away mode"}
</button>
</form>
)}
{!canEdit && !on && <div className="text-secondary">Nobody is away. An administrator can set it.</div>}
</div>
</div>
);
}
@@ -1,3 +1,4 @@
import AwayCard from "./AwayCard";
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { useSearchParams } from "react-router-dom";
import AlertActionsCard from "./AlertActionsCard";
@@ -71,7 +72,7 @@ const DEFAULT_NOTIFICATIONS: NotificationEvents = {
integrationFailureAlerts: true,
integrationFailureThreshold: 3,
};
const DEFAULT_QUIET_HOURS: QuietHoursSettings = { enabled: false, start: "22:00", end: "07:00" };
const DEFAULT_QUIET_HOURS: QuietHoursSettings = { enabled: false, start: "22:00", end: "07:00", criticalThrough: false };
const DEFAULT_DIGEST: DigestSettings = { enabled: false, day: 1, time: "08:00" };
// Monday first, as a week reads; the numbers are what the server keeps (0 = Sunday).
const DIGEST_DAYS: { value: number; label: string }[] = [
@@ -280,7 +281,7 @@ export default function NotificationSettings() {
setRouting(rt);
setEscalation(es);
setNotifications(s.notifications);
setQuietHours(s.quietHours);
setQuietHours({ ...DEFAULT_QUIET_HOURS, ...s.quietHours });
setHealthChecks(s.healthChecks);
const d = s.digest ?? DEFAULT_DIGEST;
setDigest(d);
@@ -963,6 +964,13 @@ export default function NotificationSettings() {
</div>
</div>
<div className="form-hint mb-3">A start time later than the end time (e.g. 22:00 → 07:00) is treated as spanning midnight.</div>
<label className="form-check mb-3">
<input type="checkbox" className="form-check-input" checked={quietHours.criticalThrough} disabled={!quietHours.enabled} onChange={(e) => setQuietHours((q) => ({ ...q, criticalThrough: e.target.checked }))} />
<span className="form-check-label">
Still send critical alerts
<span className="form-hint d-block">A server down or a disk full at 03:00 is sent at once; everything else waits for the digest. Off, nothing gets through until the window ends.</span>
</span>
</label>
{queuedCount !== null && queuedCount > 0 && (
<div className="alert alert-info d-flex align-items-center justify-content-between mb-0">
<span>
@@ -978,6 +986,10 @@ export default function NotificationSettings() {
</div>
</div>
<div className="col-md-6">
<AwayCard canEdit />
</div>
<div className="col-12">
<div className="card">
<div className="card-header">