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 ? (