add order status lookup for customers
All checks were successful
deploy / deploy (push) Successful in 1m17s

Magic link flow on contact page: customer enters email, gets a
time-limited signed link, clicks through to /orders showing all their
paid orders and full detail pages with thumbnails and product links.

- OrderLookupController generates/verifies Phoenix.Token signed links
- Contact LiveView handles lookup_orders + reset_tracking events
- Orders and OrderDetail LiveViews gated by session email
- Order detail shows thumbnails, links to products still available
- .themed-button gets base padding/font-weight so all usages are consistent
- order-summary-card sticky scoped to .cart-grid (was leaking to orders list)
- 27 new tests (1095 total)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-24 08:40:08 +00:00
parent 4e36b654d3
commit 01ff8decd5
19 changed files with 1030 additions and 8 deletions

View File

@@ -1,6 +1,10 @@
defmodule BerrypodWeb.Shop.Contact do
use BerrypodWeb, :live_view
alias Berrypod.Orders
alias Berrypod.Orders.OrderNotifier
alias BerrypodWeb.OrderLookupController
@impl true
def mount(_params, _session, socket) do
{:ok,
@@ -10,7 +14,30 @@ defmodule BerrypodWeb.Shop.Contact do
:page_description,
"Get in touch with us for any questions or help with your order."
)
|> assign(:og_url, BerrypodWeb.Endpoint.url() <> "/contact")}
|> assign(:og_url, BerrypodWeb.Endpoint.url() <> "/contact")
|> assign(:tracking_state, :idle)}
end
@impl true
def handle_event("lookup_orders", %{"email" => email}, socket) do
orders = Orders.list_orders_by_email(email)
state =
if orders == [] do
:not_found
else
token = OrderLookupController.generate_token(email)
link = BerrypodWeb.Endpoint.url() <> ~p"/orders/verify/#{token}"
OrderNotifier.deliver_order_lookup(email, link)
:sent
end
{:noreply, assign(socket, :tracking_state, state)}
end
@impl true
def handle_event("reset_tracking", _params, socket) do
{:noreply, assign(socket, :tracking_state, :idle)}
end
@impl true

View File

@@ -0,0 +1,55 @@
defmodule BerrypodWeb.Shop.OrderDetail do
use BerrypodWeb, :live_view
alias Berrypod.Orders
alias Berrypod.Products
alias Berrypod.Products.ProductImage
@impl true
def mount(_params, session, socket) do
{:ok, assign(socket, :lookup_email, session["order_lookup_email"])}
end
@impl true
def handle_params(%{"order_number" => order_number}, _uri, socket) do
email = socket.assigns.lookup_email
order = Orders.get_order_by_number(order_number)
normalised = fn e -> String.downcase(String.trim(e || "")) end
if order && order.payment_status == "paid" &&
email && normalised.(order.customer_email) == normalised.(email) do
variant_ids = Enum.map(order.items, & &1.variant_id)
variants = Products.get_variants_with_products(variant_ids)
thumbnails =
Map.new(variants, fn {id, variant} ->
thumb =
case variant.product.images do
[first | _] -> ProductImage.thumbnail_url(first)
_ -> nil
end
slug = if variant.product.visible, do: variant.product.slug, else: nil
{id, %{thumb: thumb, slug: slug}}
end)
{:noreply,
socket
|> assign(:page_title, "Order #{order_number}")
|> assign(:order, order)
|> assign(:thumbnails, thumbnails)}
else
{:noreply, push_navigate(socket, to: ~p"/orders")}
end
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.order_detail {assigns} />
"""
end
end

View File

@@ -0,0 +1,34 @@
defmodule BerrypodWeb.Shop.Orders do
use BerrypodWeb, :live_view
alias Berrypod.Orders
@impl true
def mount(_params, session, socket) do
email = session["order_lookup_email"]
socket =
socket
|> assign(:page_title, "Your orders")
|> assign(:lookup_email, email)
socket =
if email do
assign(socket, :orders, Orders.list_orders_by_email(email))
else
assign(socket, :orders, nil)
end
{:ok, socket}
end
@impl true
def handle_params(_params, _uri, socket), do: {:noreply, socket}
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.orders {assigns} />
"""
end
end