From 0dac93ec0bbbb50981dfebaaaad02804b09d6033 Mon Sep 17 00:00:00 2001 From: jamey Date: Thu, 12 Feb 2026 14:17:38 +0000 Subject: [PATCH] add admin dashboard with setup checklist and stats Dashboard at /admin shows setup progress (when not live), stat cards (orders, revenue, products), and recent paid orders table. Replaces the old AdminController redirect. Add Dashboard to sidebar nav as first item, update admin bar and theme editor links to /admin. Co-Authored-By: Claude Opus 4.6 --- PROGRESS.md | 15 +- lib/simpleshop_theme/orders.ex | 10 + .../components/layouts.ex | 4 + .../components/layouts/admin.html.heex | 10 +- .../components/layouts/shop.html.heex | 2 +- .../live/admin/dashboard.ex | 207 ++++++++++++++++++ .../live/admin/theme/index.html.heex | 2 +- lib/simpleshop_theme_web/router.ex | 8 +- .../live/admin/dashboard_test.exs | 70 ++++++ .../live/admin/layout_test.exs | 14 +- 10 files changed, 321 insertions(+), 21 deletions(-) create mode 100644 lib/simpleshop_theme_web/live/admin/dashboard.ex create mode 100644 test/simpleshop_theme_web/live/admin/dashboard_test.exs diff --git a/PROGRESS.md b/PROGRESS.md index 68483c8..ab81ec8 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -37,15 +37,14 @@ Plans: [admin-redesign.md](docs/plans/admin-redesign.md) | [setup-wizard.md](doc | ~~9~~ | ~~`Setup.setup_status/0` helper~~ | 2, 3 | 30m | done | | ~~10~~ | ~~ThemeHook gate (redirect to coming soon)~~ | 2, 8 | 30m | done | | ~~14~~ | ~~Go live / take offline toggle (on settings page)~~ | 2 | 30m | done | -| | **Admin shell chain (priority)** | | | | -| 1 | Filesystem restructure (consolidate live/ directories) | — | 2h | | -| 6 | Admin shell component (sidebar nav, header) | 1 | 2-3h | | -| 7 | Admin root + child layout templates | 1 | 1h | | -| 11 | Theme editor back-to-admin link | 6 | 30m | | -| 12 | Consolidate settings page | 6, 7 | 2-3h | | +| ~~1~~ | ~~Filesystem restructure (consolidate live/ directories)~~ | — | 2h | done | +| ~~6~~ | ~~Admin shell component (sidebar nav, header)~~ | 1 | 2-3h | done | +| ~~7~~ | ~~Admin root + child layout templates~~ | 1 | 1h | done | +| ~~11~~ | ~~Theme editor back-to-admin link~~ | 6 | 30m | done | +| ~~4~~ | ~~Admin bar on shop pages~~ | — | 1h | done | +| ~~12~~ | ~~Consolidate settings page~~ | 6, 7 | 2-3h | done | +| | **Next up** | | | | | 13 | Admin dashboard (+ setup checklist) | 6, 7, 9 | 2h | | -| | **Independent** | | | | -| 4 | Admin bar on shop pages | — | 1h | | | 5 | Search (functional search with results) | — | 3-4h | | | | **Needs admin stable** | | | | | 15 | Setup wizard + admin tests | 13 | 1.5h | | diff --git a/lib/simpleshop_theme/orders.ex b/lib/simpleshop_theme/orders.ex index 1375f60..6a51673 100644 --- a/lib/simpleshop_theme/orders.ex +++ b/lib/simpleshop_theme/orders.ex @@ -50,6 +50,16 @@ defmodule SimpleshopTheme.Orders do |> Map.new() end + @doc """ + Returns total revenue (in minor units) from paid orders. + """ + def total_revenue do + Order + |> where(payment_status: "paid") + |> select([o], sum(o.total)) + |> Repo.one() || 0 + end + @doc """ Creates an order with line items from hydrated cart data. diff --git a/lib/simpleshop_theme_web/components/layouts.ex b/lib/simpleshop_theme_web/components/layouts.ex index e350040..ae0c816 100644 --- a/lib/simpleshop_theme_web/components/layouts.ex +++ b/lib/simpleshop_theme_web/components/layouts.ex @@ -46,6 +46,10 @@ defmodule SimpleshopThemeWeb.Layouts do end @doc false + def admin_nav_active?(current_path, "/admin") do + if current_path == "/admin", do: "active", else: nil + end + def admin_nav_active?(current_path, link_path) do if String.starts_with?(current_path, link_path), do: "active", else: nil end diff --git a/lib/simpleshop_theme_web/components/layouts/admin.html.heex b/lib/simpleshop_theme_web/components/layouts/admin.html.heex index c4230db..a1811dd 100644 --- a/lib/simpleshop_theme_web/components/layouts/admin.html.heex +++ b/lib/simpleshop_theme_web/components/layouts/admin.html.heex @@ -34,7 +34,7 @@