"use client"; import { useRouter } from "next/navigation"; import { useActionState, useEffect } from "react"; import type { OperatorSettings } from "@/lib/global-settings"; import type { SchedulerStatus } from "@/lib/scheduler-status"; import { saveOperatorSettingsAction, sendTestAlertAction, type SaveOperatorSettingsState, type SendTestAlertState, } from "./actions"; const saveInitialState: SaveOperatorSettingsState = { error: null, saved: false }; const testInitialState: SendTestAlertState = { result: null }; function Toggle({ name, label, hint, defaultChecked }: { name: string; label: string; hint?: string; defaultChecked: boolean }) { return ( ); } export function OperatorSettingsForm({ initial, status }: { initial: OperatorSettings; status: SchedulerStatus }) { const router = useRouter(); const [saveState, saveAction, isSaving] = useActionState(saveOperatorSettingsAction, saveInitialState); const [testState, testAction, isTesting] = useActionState(sendTestAlertAction, testInitialState); useEffect(() => { if (saveState.saved) router.refresh(); }, [saveState, router]); return (

Monitoring & scheduler

{initial.alertEmail ? ( Alerts on ) : ( Alerts off )}

The Manager calls every business's notification cron, checks its /api/health and runs scheduled backups itself. Alerts are emailed with the SMTP settings above; a business must fail two checks in a row before you hear about it.

{saveState.error && (

{saveState.error}

)} {saveState.saved && !saveState.error &&

Saved.

} {saveState.rollout && saveState.rollout.length > 0 && (

The alert address was sent to your businesses so they can email you about server errors:

    {saveState.rollout.map((r) => (
  • {r.slug}: {r.ok ? (r.unchanged ? "already set" : "updated and restarted") : `failed — ${r.error}`}
  • ))}
)}
{testState.result && (

{testState.result.message}

)}

Scheduler status

Last tick: {status.heartbeatAt ? new Date(status.heartbeatAt).toLocaleString() : "never (scheduler not running?)"}

{status.rows.length > 0 && ( {status.rows.map(({ key, state }) => ( ))}
Task Last run Result
{key} {state.lastFinishedAt ? new Date(state.lastFinishedAt).toLocaleString() : "running / never"} {state.lastMessage ?? "—"}
)}
); }