diff --git a/solvway-admin-portal/app/components/pages/PageEditor.draft.test.tsx b/solvway-admin-portal/app/components/pages/PageEditor.draft.test.tsx index cc5f488..68b96bb 100644 --- a/solvway-admin-portal/app/components/pages/PageEditor.draft.test.tsx +++ b/solvway-admin-portal/app/components/pages/PageEditor.draft.test.tsx @@ -56,8 +56,13 @@ describe("PageEditor drafts", () => { expect(screen.queryByText(/Visitors still see the published version/)).not.toBeInTheDocument(); await user.clear(screen.getByLabelText("Title")); await user.type(screen.getByLabelText("Title"), "Hotel week"); + const scroll = vi.fn(); + Element.prototype.scrollIntoView = scroll; await user.click(screen.getByRole("button", { name: "Save" })); expect(await screen.findByText(/Visitors still see the published version/)).toBeInTheDocument(); + // Save sits at the bottom of a long form: the banner is brought into view. + await waitFor(() => expect(scroll).toHaveBeenCalled()); + expect(scroll.mock.contexts[0]).toHaveTextContent(/Visitors still see the published version/); expect(screen.getByLabelText("Title")).toHaveValue("Hotel week"); await user.click(screen.getByRole("button", { name: "Publish changes" })); diff --git a/solvway-admin-portal/app/components/pages/PageEditor.tsx b/solvway-admin-portal/app/components/pages/PageEditor.tsx index 51dfaee..782216b 100644 --- a/solvway-admin-portal/app/components/pages/PageEditor.tsx +++ b/solvway-admin-portal/app/components/pages/PageEditor.tsx @@ -70,6 +70,12 @@ export function PageEditor({ pageId, fromId, initialBlocks }: { pageId?: number; const [confirmDiscard, setConfirmDiscard] = useState(false); // A published page's edits are saved as a draft; visitors see the live version until Publish changes. const [hasDraft, setHasDraft] = useState(false); + // Bumped when a save leaves a draft: Save sits below a long form, so the banner is scrolled into view. + const [revealDraft, setRevealDraft] = useState(0); + const draftBanner = useRef(null); + useEffect(() => { + if (revealDraft) draftBanner.current?.scrollIntoView?.({ behavior: "smooth", block: "nearest" }); + }, [revealDraft]); const [events, setEvents] = useState([]); const nextKey = useRef(0); const toRows = (blocks: CmsBlock[]) => blocks.map((block) => ({ key: ++nextKey.current, block })); @@ -185,6 +191,7 @@ export function PageEditor({ pageId, fromId, initialBlocks }: { pageId?: number; setDraft((d) => ({ ...d, id: page.id, companyId: page.companyId })); setSaved({ slug: page.slug, status: page.status }); setHasDraft(!!page.draft); + if (page.draft) setRevealDraft((n) => n + 1); setDirty(false); setNotice("PagesSaved"); if (isNew) router.replace(`/pages/${page.id}?saved=1`); @@ -277,7 +284,7 @@ export function PageEditor({ pageId, fromId, initialBlocks }: { pageId?: number; {summary &&

{summary}

} {notice &&

{t(notice)}

} {hasDraft && draft.status === "PUBLISHED" ? ( -
+

{t("PagesDraftBanner")}