defmodule MvWeb.ImportLive.Components do @moduledoc """ Function components for the Import LiveView: import form, progress, results, custom fields notice, and template links. Keeps the main LiveView focused on mount/handle_event/handle_info and glue code. """ use Phoenix.Component use Gettext, backend: MvWeb.Gettext import MvWeb.CoreComponents use Phoenix.VerifiedRoutes, endpoint: MvWeb.Endpoint, router: MvWeb.Router, statics: MvWeb.static_paths() @doc """ Renders the info box explaining that data fields must exist before import and linking to Manage Member Data (custom fields). """ def custom_fields_notice(assigns) do ~H"""
{gettext( "Use the data field name as the CSV column header in your file. Data fields must exist in Mila before importing, because unknown data field columns will be ignored." )}
{gettext( "Groups column (recognized headers): Groups, Gruppen, Gruppe. Comma-separated group names are supported and missing groups are created automatically." )}
{gettext( "Fee type column (recognized headers): Fee Type, fee type, fee_type, membership_fee_type, Beitragsart. Unknown fee types fall back to the default." )}
{gettext( "Fee status columns (Membership Fee Status, Bezahlstatus, Mitgliedsbeitragsstatus) are always ignored and cannot be imported." )}
{gettext("Download CSV templates:")}
| {gettext("Role")} | {gettext("Column")} | {gettext("Row 1")} | {gettext("Row 2")} | {gettext("Row 3")} |
|---|---|---|---|---|
| {role_label(role)} | {header} | <%= for sample <- samples do %>{sample} | <% end %>
{gettext("These groups will be created automatically: %{names}", names: Enum.join(@import_state.groups_to_create, ", ") )}
{gettext("Unknown fee types (members get the default): %{names}", names: Enum.join(@import_state.fee_type_warnings, ", ") )}
<.link navigate={~p"/membership_fee_settings/new_fee_type"} class="link link-primary text-sm" > {gettext("Create fee type")}{gettext("Rows with an empty fee type will get the default fee type.")}
{gettext("Processing chunk %{current} of %{total}...", current: @import_progress.current_chunk, total: @import_progress.total_chunks )}
<% end %> <%= if @import_progress.status == :done or @import_status == :error do %> <.import_results {assigns} /> <% end %><.icon name="hero-check-circle" class="size-4 inline mr-1" aria-hidden="true" /> {gettext("Successfully inserted: %{count} member(s)", count: @import_progress.inserted )}
<%= if @import_progress.failed > 0 do %><.icon name="hero-exclamation-circle" class="size-4 inline mr-1" aria-hidden="true" /> {gettext("Failed: %{count} row(s)", count: @import_progress.failed)}
<% end %> <%= if @import_progress.errors_truncated? do %><.icon name="hero-information-circle" class="size-4 inline mr-1" aria-hidden="true" /> {gettext("Error list truncated to %{count} entries", count: @max_errors)}
<% end %>