Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Tell a signer their decline was recorded instead of 'This link has expired'
Claudeb302a5bfd007
diff --git a/e2e/signing-flow.spec.ts b/e2e/signing-flow.spec.tsindex cb2b550..f07e469 100644--- a/e2e/signing-flow.spec.ts+++ b/e2e/signing-flow.spec.ts@@ -1216,6 +1216,128 @@ test("a signer signs with a qualified signature in their own name, through the s});});+test("a signer who declines is told the decline was recorded, not that the link expired", async ({+ browser,+ page,+}, testInfo) => {+ const runId = String(Date.now());+ const signerEmail = `decliner+${runId}@example.com`;+ const database = new pg.Client({ connectionString: e2eDatabaseUrl });+ let adminEmail = "";++ await database.connect();++ try {+ const admin = await database.query<{ email: string }>(+ `select email from public."user" where role = 'admin' limit 1`,+ );++ adminEmail = admin.rows[0]?.email ?? "";+ } finally {+ await database.end();+ }++ expect(adminEmail).not.toBe("");++ let envelopeId = "";++ await test.step("the sender sends a document to one signer", async () => {+ const pdfPath = await writeSamplePdf(testInfo.outputPath("terms.pdf"));++ await page.goto("/login");+ await page.getByLabel("Email").fill(adminEmail);+ await page.getByLabel("Password").fill(PASSWORD);+ await page.getByRole("button", { name: "Log in" }).click();+ await expect(page).toHaveURL(/\/dashboard$/);++ await page.goto("/envelopes/new");+ await page.getByLabel("Envelope title").fill("Terms to decline");+ await page.getByLabel("Upload PDF").setInputFiles(pdfPath);+ await page.getByRole("button", { name: "Next ->" }).click();+ await expect(page).toHaveURL(/\/envelopes\/[^/]+\/signers$/);+ envelopeId = /\/envelopes\/([^/]+)\/signers$/.exec(page.url())?.[1] ?? "";++ await page.getByLabel("Signer 1 name").fill("Dana Decliner");+ await page.getByLabel("Signer 1 email").fill(signerEmail);+ await page.getByRole("button", { name: "Next →" }).click();+ await expect(page).toHaveURL(/\/prepare$/);++ await page.getByRole("button", { exact: true, name: "Signature" }).click();++ const placementTarget = page.getByLabel("Place Signature on page 1");+ const box = await placementTarget.boundingBox();++ await placementTarget.click({+ position: { x: box!.width * 0.3, y: box!.height * 0.6 },+ });+ await expect(page.getByRole("status")).toHaveText("Saved");+ await page.getByRole("button", { name: "Next →" }).click();+ await expect(page).toHaveURL(/\/review$/);+ await page.getByRole("button", { name: "Send envelope" }).click();++ const confirmation = page.getByRole("dialog", {+ name: "Send this envelope?",+ });++ await confirmation.getByRole("checkbox").check();+ await confirmation.getByRole("button", { name: "Send now" }).click();+ await expect(page).toHaveURL(new RegExp(`/envelopes/${envelopeId}$`));+ });++ await test.step("the signer declines and sees that it was recorded", async () => {+ const invitation = await waitForEmail({+ template: "signing_invitation",+ to: signerEmail,+ });+ const signerContext = await browser.newContext({+ viewport: { height: 900, width: 1440 },+ });+ const signerPage = await signerContext.newPage();++ await signerPage.goto(extractLink(invitation.text, "/sign/"));++ const consent = signerPage.getByRole("dialog", { name: "Before you sign" });++ await consent+ .getByRole("checkbox", {+ name: "I agree to use electronic records and signatures",+ })+ .check();+ await consent.getByRole("button", { name: "Agree and continue" }).click();+ await signerPage+ .getByRole("button", { exact: true, name: "Decline" })+ .click();++ const decline = signerPage.getByRole("dialog", {+ name: "Decline to sign?",+ });++ await decline+ .getByLabel("Reason (optional)")+ .fill("Terms in section 2 are not what we agreed.");+ await decline.getByRole("button", { name: "Decline to sign" }).click();++ await expect(+ signerPage.getByRole("heading", { name: "You declined to sign" }),+ ).toBeVisible();+ await expect(signerPage.getByText("This link has expired")).toHaveCount(0);+ await expect(+ signerPage.getByText(/Request a new signing link/),+ ).toHaveCount(0);+ await signerContext.close();+ });++ await test.step("the sender sees the decline and its reason", async () => {+ await waitForEmail({ template: "decline_notification", to: adminEmail });+ await page.goto(`/envelopes/${envelopeId}`);+ await expect(+ page.getByText(+ "Decline reason: Terms in section 2 are not what we agreed.",+ ),+ ).toBeVisible();+ });+});+test("two-step sign-in: an administrator sets it up and requires it of everyone", async ({browser,page,diff --git a/src/components/signing/signing-live-shell.tsx b/src/components/signing/signing-live-shell.tsxindex fd488a4..f7f2eec 100644--- a/src/components/signing/signing-live-shell.tsx+++ b/src/components/signing/signing-live-shell.tsx@@ -41,6 +41,7 @@ import {import { Checkbox } from "@/components/ui/checkbox";import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";import { Textarea } from "@/components/ui/textarea";+import { SigningStateScreen } from "@/components/signing/signing-state-screen";import {type SigningCurrentField,type SigningPayload,@@ -84,6 +85,12 @@ const defaultSubmitErrorMessage ="We couldn't finish signing right now. Reload the page or request a fresh signing link from the sender.";const defaultDeclineErrorMessage ="We couldn't record your decline right now. Reload the page or request a fresh signing link from the sender.";+/** What a signer sees once their decline is recorded. */+export const declinedConfirmation = {+ description:+ "Your decline has been recorded and the sender has been told. No further action is needed, and this link no longer opens the document.",+ title: "You declined to sign",+};const compactFieldHeightThreshold = 0.045;const compactFieldWidthThreshold = 0.12;@@ -455,6 +462,7 @@ export function SigningLiveShell({record: SigningPayload;signatureProblem?: ProviderSignatureProblem | null;}) {+ const [hasDeclined, setHasDeclined] = useState(false);const [activePage, setActivePage] = useState(record.currentSignerFields[0]?.page ??record.visibleFields[0]?.page ??@@ -745,7 +753,10 @@ export function SigningLiveShell({return;}- window.location.reload();+ // Not a reload: a decline retires this link, so reloading would land+ // on "This link has expired" instead of saying the decline was+ // recorded (issue #55).+ setHasDeclined(true);} catch {setDeclineError(defaultDeclineErrorMessage);setIsDeclining(false);@@ -784,6 +795,15 @@ export function SigningLiveShell({}}+ if (hasDeclined) {+ return (+ <SigningStateScreen+ description={declinedConfirmation.description}+ title={declinedConfirmation.title}+ />+ );+ }+return (<div className="flex min-h-screen flex-col"><header className="sticky top-0 z-20 bg-[rgba(243,244,248,0.88)] backdrop-blur-md">diff --git a/src/components/signing/signing-shell.tsx b/src/components/signing/signing-shell.tsxindex db0d842..b675f84 100644--- a/src/components/signing/signing-shell.tsx+++ b/src/components/signing/signing-shell.tsx@@ -1,14 +1,11 @@"use client";-import { FileTextIcon } from "lucide-react";--import { Brand } from "@/components/layout/brand";-import { PublicLegalFooter } from "@/components/layout/public-legal-links";import type {SigningPayload,SigningVerificationState,} from "@/lib/schemas/signing";import { SignerVerificationScreen } from "./signer-verification-screen";+import { SigningStateScreen } from "./signing-state-screen";import {SigningLiveShell,type ProviderSignatureProblem,@@ -75,47 +72,9 @@ export function SigningShell({const tokenState = tokenStateCopy[initialState ?? "error"];return (- <StandaloneStateScreen+ <SigningStateScreendescription={tokenState.description}title={tokenState.title}/>);}--function StandaloneStateScreen({- description,- title,-}: {- description: string;- title: string;-}) {- return (- <div className="flex min-h-screen flex-col">- <header>- <div className="page-width flex items-center py-4">- <Brand href="/" />- </div>- </header>- <main className="page-width flex flex-1 items-center justify-center py-10">- <section- className="panel w-full max-w-[640px] px-6 py-12 text-center sm:px-12 sm:py-14"- data-animate="enter"- >- <span- aria-hidden="true"- className="mx-auto inline-flex size-14 items-center justify-center rounded-2xl bg-(--accent-soft) text-(--accent)"- >- <FileTextIcon className="size-6" strokeWidth={2.2} />- </span>- <h1 className="mt-6 text-[clamp(1.625rem,4vw,2.125rem)] font-extrabold leading-tight tracking-[-0.03em] text-(--fg)">- {title}- </h1>- <p className="mx-auto mt-3 max-w-[460px] text-base leading-7 text-(--secondary)">- {description}- </p>- </section>- </main>- <PublicLegalFooter />- </div>- );-}diff --git a/src/components/signing/signing-state-screen.tsx b/src/components/signing/signing-state-screen.tsxnew file mode 100644index 0000000..032ac60--- /dev/null+++ b/src/components/signing/signing-state-screen.tsx@@ -0,0 +1,45 @@+"use client";++import { FileTextIcon } from "lucide-react";++import { Brand } from "@/components/layout/brand";+import { PublicLegalFooter } from "@/components/layout/public-legal-links";++/** A signing link's end state: a heading and one line, with no document. */+export function SigningStateScreen({+ description,+ title,+}: {+ description: string;+ title: string;+}) {+ return (+ <div className="flex min-h-screen flex-col">+ <header>+ <div className="page-width flex items-center py-4">+ <Brand href="/" />+ </div>+ </header>+ <main className="page-width flex flex-1 items-center justify-center py-10">+ <section+ className="panel w-full max-w-[640px] px-6 py-12 text-center sm:px-12 sm:py-14"+ data-animate="enter"+ >+ <span+ aria-hidden="true"+ className="mx-auto inline-flex size-14 items-center justify-center rounded-2xl bg-(--accent-soft) text-(--accent)"+ >+ <FileTextIcon className="size-6" strokeWidth={2.2} />+ </span>+ <h1 className="mt-6 text-[clamp(1.625rem,4vw,2.125rem)] font-extrabold leading-tight tracking-[-0.03em] text-(--fg)">+ {title}+ </h1>+ <p className="mx-auto mt-3 max-w-[460px] text-base leading-7 text-(--secondary)">+ {description}+ </p>+ </section>+ </main>+ <PublicLegalFooter />+ </div>+ );+}