Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Carry the webhook settings changes into embedded signing

Claudefd0601289522
diff --git a/src/app/api/admin/embed-origins/route.ts b/src/app/api/admin/embed-origins/route.ts
index ceb2e95..9468f5f 100644
--- a/src/app/api/admin/embed-origins/route.ts
+++ b/src/app/api/admin/embed-origins/route.ts
@@ -9,6 +9,7 @@ import {
import {
handleWebhookAdmin,
noStore,
+ notAJsonObject,
readJsonObject,
type AdminRouteWords,
} from "@/lib/webhooks/admin-route";
@@ -52,6 +53,10 @@ export function POST(request: Request) {
async (actor) => {
const body = await readJsonObject(request);
+ if (!body) {
+ return notAJsonObject();
+ }
+
try {
const origin = await addEmbedOrigin(actor, body.origin);
diff --git a/src/components/settings/embedding-panel.tsx b/src/components/settings/embedding-panel.tsx
index 2c38f67..9a0b264 100644
--- a/src/components/settings/embedding-panel.tsx
+++ b/src/components/settings/embedding-panel.tsx
@@ -21,6 +21,9 @@ export function EmbeddingPanel() {
const [origins, setOrigins] = useState<string[] | null>(null);
const [value, setValue] = useState("");
const [error, setError] = useState<string | null>(null);
+ // Why the list did not load, kept apart from the errors of a change so
+ // that adding or removing a site does not hide it, with a way to retry.
+ const [listError, setListError] = useState<string | null>(null);
// What is being changed, so each button names only its own change.
const [pending, setPending] = useState<Change | null>(null);
const [revision, setRevision] = useState(0);
@@ -38,13 +41,14 @@ export function EmbeddingPanel() {
if (!cancelled) {
if (response.ok && payload?.origins) {
setOrigins(payload.origins.map((entry) => entry.origin));
+ setListError(null);
} else {
- setError(payload?.error ?? GENERIC_ERROR_MESSAGE);
+ setListError(payload?.error ?? GENERIC_ERROR_MESSAGE);
}
}
} catch {
if (!cancelled) {
- setError(GENERIC_ERROR_MESSAGE);
+ setListError(GENERIC_ERROR_MESSAGE);
}
}
})();
@@ -156,6 +160,26 @@ export function EmbeddingPanel() {
</p>
) : null}
+ {listError ? (
+ <div
+ className="notice notice-danger flex max-w-2xl flex-wrap items-center justify-between gap-2"
+ role="alert"
+ >
+ <span>
+ {origins === null
+ ? `The allowed sites could not be loaded. ${listError}`
+ : `The list may be out of date. ${listError}`}
+ </span>
+ <button
+ className="btn-quiet"
+ onClick={() => setRevision((current) => current + 1)}
+ type="button"
+ >
+ Try again
+ </button>
+ </div>
+ ) : null}
+
{origins === null ? null : origins.length === 0 ? (
<p className="text-sm text-(--secondary)">
No sites yet, so embedded signing is off.