Add a test notice button to Site settings
Panel → Site settings → Notices → Send a test notice emails the addresses in the box now and shows where it came from, or Google's reason for refusing, so the Gmail setup can be checked without the journal. Superadmins only (POST /api/admin/panel/test-notice). The docs now say the sender must be a Workspace user: a group can't be acted as through delegation, though it can receive notices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c63478a72a
commit
8fd3a9b15b
5 changed files with 148 additions and 9 deletions
|
|
@ -56,6 +56,10 @@
|
|||
(LinkPreviewInput in MediaLibrary.tsx) that fills the row's empty
|
||||
title, blurb and image through `onPatch`.
|
||||
|
||||
`widget: "testNotice"` is a text box of email addresses with a
|
||||
"Send a test notice" button (TestNoticeInput below), for Site
|
||||
settings → Notices.
|
||||
|
||||
`widget: "image"` is a text box with a preview and upload and
|
||||
library buttons beside it (ImageInput in MediaLibrary.tsx). Its
|
||||
`resolve` option is the media.ts helper for the field's public/
|
||||
|
|
@ -78,6 +82,7 @@
|
|||
import { ArrowUp, ArrowDown, CaretRight } from "@phosphor-icons/react";
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { ApiError, post } from "../../lib/api.ts";
|
||||
import ContentBlocks from "../ContentBlocks.tsx";
|
||||
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
||||
|
||||
|
|
@ -311,6 +316,14 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
onChange={onChange}
|
||||
onPatch={onPatch}
|
||||
/>
|
||||
) : widget === "testNotice" ? (
|
||||
<TestNoticeInput
|
||||
id={id}
|
||||
value={value}
|
||||
locked={locked}
|
||||
className={locked ? inputLocked : common.className}
|
||||
onChange={onChange}
|
||||
/>
|
||||
) : widget === "image" ? (
|
||||
<ImageInput
|
||||
id={id}
|
||||
|
|
@ -709,3 +722,65 @@ function IconButton({ label, onClick, danger = false, disabled = false, children
|
|||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/* Addresses, and a button that emails them a test notice now (the
|
||||
box as typed, saved or not), showing what Google said. */
|
||||
function TestNoticeInput({
|
||||
id,
|
||||
value,
|
||||
locked,
|
||||
className,
|
||||
onChange,
|
||||
}: {
|
||||
id: string;
|
||||
value: string | null | undefined;
|
||||
locked: boolean;
|
||||
className: string;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<{ tone: "ok" | "error"; text: string } | null>(null);
|
||||
|
||||
async function send() {
|
||||
setBusy(true);
|
||||
setNote(null);
|
||||
try {
|
||||
const { sent, from } = await post("/admin/panel/test-notice", { to: value });
|
||||
setNote({ tone: "ok", text: `Sent from ${from} to ${sent.join(", ")}. Check the inbox (and spam).` });
|
||||
} catch (err) {
|
||||
setNote({ tone: "error", text: err instanceof ApiError ? err.message : "Couldn't reach the server." });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<input
|
||||
id={id}
|
||||
type="text"
|
||||
value={value ?? ""}
|
||||
readOnly={locked}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={className}
|
||||
/>
|
||||
{!locked && (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy || !value?.trim()}
|
||||
onClick={send}
|
||||
className="rounded-full border border-brand px-3 py-1 text-sm font-medium text-link transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50"
|
||||
>
|
||||
{busy ? "Sending…" : "Send a test notice"}
|
||||
</button>
|
||||
{note && (
|
||||
<span role="status" className={`text-xs ${note.tone === "ok" ? "text-link" : "text-danger"}`}>
|
||||
{note.text}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue