- <.icon name={@icon} class="size-5 text-base-content/60" />
+
+
+ <.icon name={@icon} class="size-5" />
-
{@value}
-
{@label}
+
{@value}
+
+ {@label}
+
@@ -132,19 +274,19 @@ defmodule BerrypodWeb.Admin.Dashboard do
defp fulfilment_pill(assigns) do
{color, label} =
case assigns.status do
- "unfulfilled" -> {"bg-base-200 text-base-content/60", "unfulfilled"}
- "submitted" -> {"bg-blue-50 text-blue-700", "submitted"}
- "processing" -> {"bg-amber-50 text-amber-700", "processing"}
- "shipped" -> {"bg-purple-50 text-purple-700", "shipped"}
- "delivered" -> {"bg-green-50 text-green-700", "delivered"}
- "failed" -> {"bg-red-50 text-red-700", "failed"}
- _ -> {"bg-base-200 text-base-content/60", assigns.status || "—"}
+ "unfulfilled" -> {"var(--color-base-200, #e5e5e5)", "unfulfilled"}
+ "submitted" -> {"#dbeafe", "submitted"}
+ "processing" -> {"#fef3c7", "processing"}
+ "shipped" -> {"#f3e8ff", "shipped"}
+ "delivered" -> {"#dcfce7", "delivered"}
+ "failed" -> {"#fee2e2", "failed"}
+ _ -> {"var(--color-base-200, #e5e5e5)", assigns.status || "—"}
end
assigns = assign(assigns, color: color, label: label)
~H"""
-
+
{@label}
"""
@@ -154,6 +296,10 @@ defmodule BerrypodWeb.Admin.Dashboard do
# Helpers
# ==========================================================================
+ defp show_checklist?(setup) do
+ not setup.site_live and not setup.checklist_dismissed
+ end
+
defp format_revenue(amount_pence) when is_integer(amount_pence) do
Cart.format_price(amount_pence)
end
diff --git a/lib/berrypod_web/live/admin/providers/form.ex b/lib/berrypod_web/live/admin/providers/form.ex
index c15e1e1..0280287 100644
--- a/lib/berrypod_web/live/admin/providers/form.ex
+++ b/lib/berrypod_web/live/admin/providers/form.ex
@@ -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
diff --git a/lib/berrypod_web/live/admin/providers/form.html.heex b/lib/berrypod_web/live/admin/providers/form.html.heex
index 9e75fa7..4671c1d 100644
--- a/lib/berrypod_web/live/admin/providers/form.html.heex
+++ b/lib/berrypod_web/live/admin/providers/form.html.heex
@@ -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"}
<%= if @live_action == :new do %>
- {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.
- <%= if @provider_type == "printify" do %>
-
-
Get your API key from Printify:
-
- -
-
- Log in to Printify
-
- (or create a free account)
-
- - Click Account (top right)
- - Select Connections from the dropdown
- - Find API tokens and click Generate
- -
- Enter a name (e.g. "My Shop"), keep all scopes
- selected, and click Generate token
-
- - Click Copy to clipboard and paste it below
-
-
- <% else %>
-
-
Get your API key from Printful:
-
- -
-
- Log in to Printful
-
- (or create a free account)
-
- - Go to Settings → API access
- - Click Create API key
- - Give it a name and select all scopes
- - Copy the token and paste it below
-
-
- <% end %>
+
+
Get your API key from {@provider.name}:
+
+ -
+
+ Log in to {@provider.name}
+
+ (or create a free account)
+
+ -
+ {raw(step)}
+
+
+
<% 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} -> %>
<.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}
<% {:error, reason} -> %>
@@ -124,7 +81,7 @@
<.button type="submit" disabled={@testing}>
{if @live_action == :new,
- do: "Connect to #{provider_label(@provider_type)}",
+ do: "Connect to #{@provider.name}",
else: "Save changes"}
<.link navigate={~p"/admin/providers"} class="admin-btn admin-btn-ghost">
diff --git a/lib/berrypod_web/live/admin/providers/index.ex b/lib/berrypod_web/live/admin/providers/index.ex
index 7938000..424e1d2 100644
--- a/lib/berrypod_web/live/admin/providers/index.ex
+++ b/lib/berrypod_web/live/admin/providers/index.ex
@@ -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)
diff --git a/lib/berrypod_web/live/admin/providers/index.html.heex b/lib/berrypod_web/live/admin/providers/index.html.heex
index 2e05d30..1a44aa4 100644
--- a/lib/berrypod_web/live/admin/providers/index.html.heex
+++ b/lib/berrypod_web/live/admin/providers/index.html.heex
@@ -6,11 +6,8 @@
<.icon name="hero-plus" class="size-4 mr-1" /> Connect provider
- -
- <.link navigate={~p"/admin/providers/new?type=printify"}>Printify
-
- -
- <.link navigate={~p"/admin/providers/new?type=printful"}>Printful
+
-
+ <.link navigate={~p"/admin/providers/new?type=#{provider.type}"}>{provider.name}
@@ -22,15 +19,14 @@
<.icon name="hero-cube" class="size-16 mx-auto mb-4 text-base-content/30" />
Connect a print-on-demand provider
- Connect your Printify or Printful account to import products
- and start selling.
+ Connect your account to import products and start selling.
- <.button navigate={~p"/admin/providers/new?type=printify"}>
- Connect Printify
-
- <.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}
<.status_indicator status={connection.sync_status} enabled={connection.enabled} />
- {String.capitalize(connection.provider_type)}
+ {provider_name(connection.provider_type)}