defmodule MvWeb.MemberLive.Show.DeactivateComponent do @moduledoc """ LiveComponent owning the member deactivate/reactivate sub-flow on the member show page. ## Features - Deactivate control (shown when the member has no exit_date) - Reactivate control (shown when the member has an exit_date) - Date-selection modal (default: today, future dates allowed) for deactivation - Routes both actions through `Membership.update_member/2` with the real user actor, inheriting the `exit_date > join_date` validation and the cycle-regeneration hook. Controls are gated on `:update` permission for the member. On success the component notifies the parent with `{:member_updated, member}`, which the parent already handles. """ use MvWeb, :live_component import MvWeb.Authorization, only: [can?: 3] alias Mv.Membership alias MvWeb.Helpers.MemberHelpers @impl true def render(assigns) do ~H"""
{gettext( "This member is deactivated (exit date set). Reactivating clears the exit date." )}
<.button id="reactivate-member-trigger" data-testid="member-reactivate" variant="primary" phx-click="reactivate" phx-target={@myself} aria-label={ gettext("Reactivate member %{name}", name: MemberHelpers.display_name(@member)) } > <.icon name="hero-arrow-uturn-left" class="size-4" /> {gettext("Reactivate member")} <% else %>{gettext( "Deactivating this member records an exit date. You can reactivate them later." )}
<.button id="deactivate-member-trigger" data-testid="member-deactivate" variant="outline" phx-click="open_modal" phx-target={@myself} aria-label={ gettext("Deactivate member %{name}", name: MemberHelpers.display_name(@member)) } > <.icon name="hero-arrow-right-on-rectangle" class="size-4" /> {gettext("Deactivate member")} <% end %>