add admin CRUD for custom CMS pages
All checks were successful
deploy / deploy (push) Successful in 1m21s

New settings form for creating and editing custom page metadata
(title, slug, meta description, published, nav settings). Pages
index shows custom pages section with draft badges and delete.
Editor shows settings button for custom pages, hides reset to
defaults. 20 new tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-28 09:43:03 +00:00
parent bb6b28a163
commit 045be2ed7e
8 changed files with 473 additions and 8 deletions

View File

@@ -14,20 +14,43 @@ defmodule BerrypodWeb.Admin.Pages.Index do
@impl true
def mount(_params, _session, socket) do
pages = Pages.list_pages() |> Map.new(&{&1.slug, &1})
custom_pages = Pages.list_custom_pages()
{:ok,
socket
|> assign(:page_title, "Pages")
|> assign(:pages, pages)
|> assign(:custom_pages, custom_pages)
|> assign(:page_groups, @page_groups)}
end
@impl true
def handle_event("delete_custom_page", %{"slug" => slug}, socket) do
case Pages.get_page_struct(slug) do
%{type: "custom"} = page ->
{:ok, _} = Pages.delete_custom_page(page)
{:noreply,
socket
|> assign(:custom_pages, Pages.list_custom_pages())
|> put_flash(:info, "Page deleted")}
_ ->
{:noreply, put_flash(socket, :error, "Page not found")}
end
end
@impl true
def render(assigns) do
~H"""
<.header>
Pages
<:subtitle>Customise the layout and content of every page on your shop.</:subtitle>
<:actions>
<.link navigate={~p"/admin/pages/new"} class="admin-btn admin-btn-sm admin-btn-primary">
<.icon name="hero-plus" class="size-4" /> New page
</.link>
</:actions>
</.header>
<div class="page-list">
@@ -54,6 +77,42 @@ defmodule BerrypodWeb.Admin.Pages.Index do
</.link>
</div>
</div>
<div :if={@custom_pages != []} class="page-group">
<h3 class="page-group-title">Custom pages</h3>
<div class="page-group-cards">
<div :for={page <- @custom_pages} class="page-card page-card-custom">
<.link navigate={~p"/admin/pages/#{page.slug}"} class="page-card-link">
<span class="page-card-icon">
<.icon name="hero-document" class="size-5" />
</span>
<span class="page-card-info">
<span class="page-card-title">
{page.title}
<span :if={!page.published} class="admin-badge admin-badge-warning ml-2">
Draft
</span>
</span>
<span class="page-card-meta">
/{page.slug} · {length(page.blocks)} {if length(page.blocks) == 1,
do: "block",
else: "blocks"}
</span>
</span>
<.icon name="hero-chevron-right-mini" class="size-4 page-card-arrow" />
</.link>
<button
phx-click="delete_custom_page"
phx-value-slug={page.slug}
data-confirm={"Delete \"#{page.title}\"? This cannot be undone."}
class="page-card-delete"
aria-label={"Delete #{page.title}"}
>
<.icon name="hero-trash" class="size-4" />
</button>
</div>
</div>
</div>
</div>
"""
end