All checks were successful
deploy / deploy (push) Successful in 1m27s
Replace individual shop LiveViews with a single Shop.Page that dispatches to page modules based on live_action. This enables patch navigation between pages, preserving socket state (including editor state) across transitions. Changes: - Add Shop.Page unified LiveView with handle_params dispatch - Extract page logic into Shop.Pages.* modules (Home, Product, Collection, etc.) - Update router to use Shop.Page with live_action for all shop routes - Change navigate= to patch= in shop component links - Add maybe_sync_editing_blocks to reload editor state when page changes - Track editor_page_slug to detect cross-page navigation while editing - Fix picture element height when hover image disabled - Extract ThemeEditor components for shared use Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
73 lines
2.0 KiB
Elixir
73 lines
2.0 KiB
Elixir
defmodule BerrypodWeb.Shop.Pages.Contact do
|
|
@moduledoc """
|
|
Contact page handler for the unified Shop.Page LiveView.
|
|
"""
|
|
|
|
import Phoenix.Component, only: [assign: 3]
|
|
import Phoenix.LiveView, only: [push_navigate: 2, put_flash: 3]
|
|
|
|
alias Berrypod.{ContactNotifier, Orders}
|
|
alias Berrypod.Orders.OrderNotifier
|
|
alias Berrypod.Pages
|
|
alias BerrypodWeb.OrderLookupController
|
|
|
|
def init(socket, _params, _uri) do
|
|
page = Pages.get_page("contact")
|
|
|
|
socket =
|
|
socket
|
|
|> assign(:page_title, "Contact")
|
|
|> assign(
|
|
:page_description,
|
|
"Get in touch with us for any questions or help with your order."
|
|
)
|
|
|> assign(:og_url, BerrypodWeb.Endpoint.url() <> "/contact")
|
|
|> assign(:tracking_state, :idle)
|
|
|> assign(:page, page)
|
|
|
|
{:noreply, socket}
|
|
end
|
|
|
|
def handle_params(_params, _uri, socket) do
|
|
{:noreply, socket}
|
|
end
|
|
|
|
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() <> "/orders/verify/#{token}"
|
|
OrderNotifier.deliver_order_lookup(email, link)
|
|
:sent
|
|
end
|
|
|
|
{:noreply, assign(socket, :tracking_state, state)}
|
|
end
|
|
|
|
def handle_event("send_contact", params, socket) do
|
|
case ContactNotifier.deliver_contact_message(params) do
|
|
{:ok, _} ->
|
|
{:noreply,
|
|
socket
|
|
|> put_flash(:info, "Message sent! We'll get back to you soon.")
|
|
|> push_navigate(to: "/contact")}
|
|
|
|
{:error, :invalid_params} ->
|
|
{:noreply, put_flash(socket, :error, "Please fill in all required fields.")}
|
|
|
|
{:error, _} ->
|
|
{:noreply, put_flash(socket, :error, "Sorry, something went wrong. Please try again.")}
|
|
end
|
|
end
|
|
|
|
def handle_event("reset_tracking", _params, socket) do
|
|
{:noreply, assign(socket, :tracking_state, :idle)}
|
|
end
|
|
|
|
def handle_event(_event, _params, _socket), do: :cont
|
|
end
|