add setup onboarding page, dashboard launch checklist, provider registry

- new /setup page with three-section onboarding (account, provider, payments)
- dashboard launch checklist with progress bar, go-live, dismiss
- provider registry on Provider module (single source of truth for metadata)
- payments registry for Stripe
- setup context made provider-agnostic (provider_connected, theme_customised, etc.)
- admin provider pages now fully registry-driven (no hardcoded provider names)
- auth flow: fresh installs redirect to /setup, signed_in_path respects setup state
- removed old /admin/setup wizard
- 840 tests, 0 failures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-20 00:34:06 +00:00
parent 989c5cd4df
commit c2caeed64d
33 changed files with 1927 additions and 1053 deletions

View File

@@ -4,8 +4,9 @@ defmodule BerrypodWeb.Admin.Providers.Form do
alias Berrypod.Products
alias Berrypod.Products.ProviderConnection
alias Berrypod.Providers
alias Berrypod.Providers.Provider
@supported_types ~w(printify printful)
@supported_types Enum.map(Provider.available(), & &1.type)
@impl true
def mount(params, _session, socket) do
@@ -14,10 +15,12 @@ defmodule BerrypodWeb.Admin.Providers.Form do
defp apply_action(socket, :new, params) do
provider_type = validated_type(params["type"])
provider = Provider.get(provider_type)
socket
|> assign(:page_title, "Connect to #{provider_label(provider_type)}")
|> assign(:page_title, "Connect to #{provider.name}")
|> assign(:provider_type, provider_type)
|> assign(:provider, provider)
|> assign(:connection, %ProviderConnection{provider_type: provider_type})
|> assign(:form, to_form(ProviderConnection.changeset(%ProviderConnection{}, %{})))
|> assign(:testing, false)
@@ -27,10 +30,12 @@ defmodule BerrypodWeb.Admin.Providers.Form do
defp apply_action(socket, :edit, %{"id" => id}) do
connection = Products.get_provider_connection!(id)
provider = Provider.get(connection.provider_type)
socket
|> assign(:page_title, "#{provider_label(connection.provider_type)} settings")
|> assign(:page_title, "#{provider.name} settings")
|> assign(:provider_type, connection.provider_type)
|> assign(:provider, provider)
|> assign(:connection, connection)
|> assign(:form, to_form(ProviderConnection.changeset(connection, %{})))
|> assign(:testing, false)
@@ -89,7 +94,7 @@ defmodule BerrypodWeb.Admin.Providers.Form do
{:ok, _connection} ->
{:noreply,
socket
|> put_flash(:info, "Connected to #{provider_label(provider_type)}!")
|> put_flash(:info, "Connected to #{socket.assigns.provider.name}!")
|> push_navigate(to: ~p"/admin/settings")}
{:error, %Ecto.Changeset{} = changeset} ->
@@ -132,7 +137,8 @@ defmodule BerrypodWeb.Admin.Providers.Form do
end
defp maybe_add_name(params, type, _result) do
Map.put_new(params, "name", provider_label(type))
provider = Provider.get(type)
Map.put_new(params, "name", provider && provider.name || type)
end
defp encrypt_api_key(api_key) do
@@ -147,9 +153,6 @@ defmodule BerrypodWeb.Admin.Providers.Form do
# Shared helpers used by the template
defp provider_label("printful"), do: "Printful"
defp provider_label(_), do: "Printify"
defp connection_name({:ok, %{shop_name: name}}), do: name
defp connection_name({:ok, %{store_name: name}}), do: name
defp connection_name(_), do: nil

View File

@@ -1,75 +1,32 @@
<.header>
{if @live_action == :new,
do: "Connect to #{provider_label(@provider_type)}",
else: "#{provider_label(@provider_type)} settings"}
do: "Connect to #{@provider.name}",
else: "#{@provider.name} settings"}
</.header>
<div class="max-w-xl mt-6">
<%= if @live_action == :new do %>
<div class="prose prose-sm mb-6">
<p>
{provider_label(@provider_type)} is a print-on-demand service that prints and ships products for you.
{@provider.name} is a print-on-demand service that prints and ships products for you.
Connect your account to automatically import your products into your shop.
</p>
</div>
<%= if @provider_type == "printify" do %>
<div class="rounded-lg bg-base-200 p-4 mb-6 text-sm">
<p class="font-medium mb-2">Get your API key from Printify:</p>
<ol class="list-decimal list-inside space-y-1 text-base-content/80">
<li>
<a
href="https://printify.com/app/auth/login"
target="_blank"
rel="noopener"
class="admin-link"
>
Log in to Printify
</a>
(or <a
href="https://printify.com/app/auth/register"
target="_blank"
rel="noopener"
class="admin-link"
>create a free account</a>)
</li>
<li>Click <strong>Account</strong> (top right)</li>
<li>Select <strong>Connections</strong> from the dropdown</li>
<li>Find <strong>API tokens</strong> and click <strong>Generate</strong></li>
<li>
Enter a name (e.g. "My Shop"), keep <strong>all scopes</strong>
selected, and click <strong>Generate token</strong>
</li>
<li>Click <strong>Copy to clipboard</strong> and paste it below</li>
</ol>
</div>
<% else %>
<div class="rounded-lg bg-base-200 p-4 mb-6 text-sm">
<p class="font-medium mb-2">Get your API key from Printful:</p>
<ol class="list-decimal list-inside space-y-1 text-base-content/80">
<li>
<a
href="https://www.printful.com/auth/login"
target="_blank"
rel="noopener"
class="admin-link"
>
Log in to Printful
</a>
(or <a
href="https://www.printful.com/auth/signup"
target="_blank"
rel="noopener"
class="admin-link"
>create a free account</a>)
</li>
<li>Go to <strong>Settings</strong> &rarr; <strong>API access</strong></li>
<li>Click <strong>Create API key</strong></li>
<li>Give it a name and select <strong>all scopes</strong></li>
<li>Copy the token and paste it below</li>
</ol>
</div>
<% end %>
<div class="rounded-lg bg-base-200 p-4 mb-6 text-sm">
<p class="font-medium mb-2">Get your API key from {@provider.name}:</p>
<ol class="list-decimal list-inside space-y-1 text-base-content/80">
<li>
<a href={@provider.login_url} target="_blank" rel="noopener" class="admin-link">
Log in to {@provider.name}
</a>
(or <a href={@provider.signup_url} target="_blank" rel="noopener" class="admin-link">create a free account</a>)
</li>
<li :for={step <- @provider.setup_steps}>
{raw(step)}
</li>
</ol>
</div>
<% end %>
<.form for={@form} id="provider-form" phx-change="validate" phx-submit="save">
@@ -78,7 +35,7 @@
<.input
field={@form[:api_key]}
type="password"
label={"#{provider_label(@provider_type)} API key"}
label={"#{@provider.name} API key"}
placeholder={
if @live_action == :edit,
do: "Leave blank to keep current key",
@@ -106,7 +63,7 @@
<% {:ok, _info} -> %>
<span class="text-success flex items-center gap-1">
<.icon name="hero-check-circle" class="size-4" />
Connected to {connection_name(@test_result) || provider_label(@provider_type)}
Connected to {connection_name(@test_result) || @provider.name}
</span>
<% {:error, reason} -> %>
<span class="text-error flex items-center gap-1">
@@ -124,7 +81,7 @@
<div class="flex gap-2 mt-6">
<.button type="submit" disabled={@testing}>
{if @live_action == :new,
do: "Connect to #{provider_label(@provider_type)}",
do: "Connect to #{@provider.name}",
else: "Save changes"}
</.button>
<.link navigate={~p"/admin/providers"} class="admin-btn admin-btn-ghost">

View File

@@ -3,6 +3,7 @@ defmodule BerrypodWeb.Admin.Providers.Index do
alias Berrypod.Products
alias Berrypod.Products.ProviderConnection
alias Berrypod.Providers.Provider
@impl true
def mount(_params, _session, socket) do
@@ -11,6 +12,7 @@ defmodule BerrypodWeb.Admin.Providers.Index do
{:ok,
socket
|> assign(:page_title, "Provider connections")
|> assign(:available_providers, Provider.available())
|> stream(:connections, connections)}
end
@@ -85,6 +87,13 @@ defmodule BerrypodWeb.Admin.Providers.Index do
"""
end
defp provider_name(type) do
case Provider.get(type) do
%{name: name} -> name
nil -> String.capitalize(type)
end
end
defp format_relative_time(datetime) do
diff = DateTime.diff(DateTime.utc_now(), datetime, :second)

View File

@@ -6,11 +6,8 @@
<.icon name="hero-plus" class="size-4 mr-1" /> Connect provider
</div>
<ul tabindex="0" class="admin-dropdown-content">
<li>
<.link navigate={~p"/admin/providers/new?type=printify"}>Printify</.link>
</li>
<li>
<.link navigate={~p"/admin/providers/new?type=printful"}>Printful</.link>
<li :for={provider <- @available_providers}>
<.link navigate={~p"/admin/providers/new?type=#{provider.type}"}>{provider.name}</.link>
</li>
</ul>
</div>
@@ -22,15 +19,14 @@
<.icon name="hero-cube" class="size-16 mx-auto mb-4 text-base-content/30" />
<h2 class="text-xl font-medium">Connect a print-on-demand provider</h2>
<p class="mt-2 text-base-content/60 max-w-md mx-auto">
Connect your Printify or Printful account to import products
and start selling.
Connect your account to import products and start selling.
</p>
<div class="flex justify-center gap-3 mt-6">
<.button navigate={~p"/admin/providers/new?type=printify"}>
Connect Printify
</.button>
<.button navigate={~p"/admin/providers/new?type=printful"} variant="outline">
Connect Printful
<.button
:for={provider <- @available_providers}
navigate={~p"/admin/providers/new?type=#{provider.type}"}
>
Connect {provider.name}
</.button>
</div>
</div>
@@ -46,7 +42,7 @@
<div class="flex items-center gap-2">
<.status_indicator status={connection.sync_status} enabled={connection.enabled} />
<h3 class="font-semibold text-lg">
{String.capitalize(connection.provider_type)}
{provider_name(connection.provider_type)}
</h3>
</div>
<p class="text-base-content/70 mt-1">{connection.name}</p>
@@ -65,7 +61,7 @@
<button
phx-click="delete"
phx-value-id={connection.id}
data-confirm={"Disconnect from #{String.capitalize(connection.provider_type)}? Your synced products will remain in your shop."}
data-confirm={"Disconnect from #{provider_name(connection.provider_type)}? Your synced products will remain in your shop."}
class="admin-btn admin-btn-ghost admin-btn-sm text-error"
>
Disconnect