defmodule PhoenixKitWeb.Components.UserDashboardNav do @moduledoc """ User dashboard navigation components for the PhoenixKit user dashboard. Provides navigation elements specifically for user dashboard pages. """ use PhoenixKitWeb, :html alias PhoenixKit.Modules.Languages alias PhoenixKit.Modules.Languages.DialectMapper alias PhoenixKit.Settings alias PhoenixKit.Users.Auth.Scope alias PhoenixKit.Utils.Routes alias PhoenixKitWeb.Components.Core.LanguageSwitcher # Guest dropdown link catalog. Each entry is # `{key, path, icon, label_fn, setting_gate_fn}`; `label_fn`/`gate_fn` # are zero-arity so gettext + settings are evaluated at render time # (per-request locale / live setting), not at compile time. @guest_link_catalog [ {:login, "/users/log-in", "hero-arrow-right-on-rectangle"}, {:register, "/users/register", "hero-user-plus"}, {:reset, "/users/reset-password", "hero-key"}, {:magic_link, "/users/magic-link", "hero-sparkles"} ] @doc """ Renders the user widget for dashboard navigation. For authenticated visitors this is the avatar dropdown (email, Admin/Dashboard/Settings, language switcher, log out). For anonymous visitors the same dropdown *shape* is rendered with a generic "not signed in" icon and guest-relevant links (log in, sign up, forgot password, magic link) plus the same language switcher — so a single widget covers both states and always offers a language switcher. ## Attributes * `:scope` — current scope; `nil`/unauthenticated renders the guest dropdown. * `:current_path` — used for active-link highlighting and locale-switch URLs. * `:current_locale` — base code of the active locale (highlighted in the list). * `:show_language_switcher` — include the in-menu language list (default `true`). Set `false` when the host renders a standalone switcher elsewhere to avoid a duplicate. Applies to both the signed-in and guest states. * `:guest_links` — which guest links may appear, e.g. `[:login, :register, :reset, :magic_link]` (default: all). Links are also gated by the `allow_registration` / `magic_link_login_enabled` settings, so this list can only narrow, never force-enable a disabled feature. """ attr(:scope, :any, default: nil) attr(:current_path, :string, default: "") attr(:current_locale, :string, default: "en") attr(:admin_edit_url, :string, default: nil) attr(:admin_edit_label, :string, default: nil) attr(:show_language_switcher, :boolean, default: true) attr(:guest_links, :list, default: [:login, :register, :reset, :magic_link]) def user_dropdown(assigns) do user = Scope.user(assigns.scope) assigns = assigns |> assign(:user, user) ~H""" <%= if @scope && PhoenixKit.Users.Auth.Scope.authenticated?(@scope) do %> <% else %> <.guest_dropdown current_path={@current_path} current_locale={@current_locale} guest_links={@guest_links} show_language_switcher={@show_language_switcher} /> <% end %> """ end # Guest counterpart to the authenticated avatar dropdown: same shape and # styling, a generic "not signed in" trigger icon, guest-relevant links, # and the shared language switcher. attr(:current_path, :string, required: true) attr(:current_locale, :string, required: true) attr(:guest_links, :list, required: true) attr(:show_language_switcher, :boolean, required: true) defp guest_dropdown(assigns) do assigns = assign(assigns, :links, visible_guest_links(assigns.guest_links)) ~H""" """ end # Shared, independently scrollable language list used by both the # authenticated and guest dropdowns. Renders nothing when fewer than two # languages are enabled. Anchors are styled directly (no nested daisyUI # `