From 1e09b652dcf3606fa8b0ab9d2712b8796d360d03 Mon Sep 17 00:00:00 2001 From: ngqile Date: Wed, 2 Dec 2026 17:29:51 +0800 Subject: [PATCH] feat(pages): copy button for page addresses The Pages list and the page editor show a copy button next to the page address. It copies the full URL (this site's origin plus the path) and reuses the existing copy labels, so no new labels or SQL are needed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs --- .../app/components/pages/CopyAddress.tsx | 36 +++++++++++++++++++ .../app/components/pages/PageEditor.test.tsx | 9 +++++ .../app/components/pages/PageEditor.tsx | 4 ++- solvway-admin-portal/app/pages/page.test.tsx | 17 +++++++++ solvway-admin-portal/app/pages/page.tsx | 3 +- 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 solvway-admin-portal/app/components/pages/CopyAddress.tsx diff --git a/solvway-admin-portal/app/components/pages/CopyAddress.tsx b/solvway-admin-portal/app/components/pages/CopyAddress.tsx new file mode 100644 index 0000000..06e4f14 --- /dev/null +++ b/solvway-admin-portal/app/components/pages/CopyAddress.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { useState } from "react"; +import { Check, Copy } from "lucide-react"; +import { Button } from "@/app/components/ui/button"; +import { useT } from "@/app/lib/i18n/MessagesProvider"; + +/** A page address with a button that copies its full URL (this site's origin plus the path). */ +export function CopyAddress({ address }: { address: string }) { + const t = useT(); + const [state, setState] = useState<"idle" | "copied" | "failed">("idle"); + + async function copy() { + try { + await navigator.clipboard.writeText(`${window.location.origin}${address}`); + setState("copied"); + setTimeout(() => setState("idle"), 2000); + } catch { + setState("failed"); + } + } + + return ( + + {address} + + {state !== "idle" ? ( + + {t(state === "copied" ? "QrCopied" : "CopyFailed")} + + ) : null} + + ); +} diff --git a/solvway-admin-portal/app/components/pages/PageEditor.test.tsx b/solvway-admin-portal/app/components/pages/PageEditor.test.tsx index b8da06a..902188f 100644 --- a/solvway-admin-portal/app/components/pages/PageEditor.test.tsx +++ b/solvway-admin-portal/app/components/pages/PageEditor.test.tsx @@ -35,6 +35,15 @@ beforeEach(() => { }); describe("PageEditor", () => { + it("copies the saved page's full address", async () => { + const user = userEvent.setup(); + render(); + await screen.findByLabelText("Event"); + const write = vi.spyOn(navigator.clipboard, "writeText"); + await user.click(screen.getByRole("button", { name: "Copy link /p/INS/hotel" })); + expect(write).toHaveBeenCalledWith(`${window.location.origin}/p/INS/hotel`); + }); + it("names the rich text box after its field label", async () => { const user = userEvent.setup(); render(); diff --git a/solvway-admin-portal/app/components/pages/PageEditor.tsx b/solvway-admin-portal/app/components/pages/PageEditor.tsx index 0be7fa8..2e08c7a 100644 --- a/solvway-admin-portal/app/components/pages/PageEditor.tsx +++ b/solvway-admin-portal/app/components/pages/PageEditor.tsx @@ -14,6 +14,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@ import { ApiError } from "@/app/lib/clientApi"; import { useAdminAuth } from "@/app/lib/AdminAuthContext"; import { useCompanyScope } from "@/app/lib/CompanyScope"; +import { CopyAddress } from "./CopyAddress"; import { BLOCK_LABELS, BLOCK_TYPES, emptyBlock, emptyPage, pageAddress, pageBody, withTitle, type CmsBlock, type CmsPageDraft, type PageStatus } from "@/app/lib/cmsPages"; import { deletePage, getPage, savePage, uploadPageImage } from "@/app/lib/services/adminPages"; import { listAdminEvents } from "@/app/lib/services/adminEvents"; @@ -198,7 +199,8 @@ export function PageEditor({ pageId }: { pageId?: number }) { return (
-
+
+ {saved && code ? : null} {draft.id != null ? (