defmodule MemexWeb.Components.InviteCard do @moduledoc """ Display card for an invite """ use MemexWeb, :component alias Memex.Accounts.{Invite, Invites, User} alias MemexWeb.Endpoint attr :invite, Invite, required: true attr :current_user, User, required: true slot(:inner_block) slot(:code_actions) def invite_card(%{invite: invite, current_user: current_user} = assigns) do assigns = assigns |> assign(:use_count, Invites.get_use_count(invite, current_user)) |> assign_new(:code_actions, fn -> [] end) ~H"""

<%= @invite.name %>

<%= if @invite.disabled_at |> is_nil() do %>

<%= if @invite.uses_left do %> <%= gettext( "uses left: %{uses_left_count}", uses_left_count: @invite.uses_left ) %> <% else %> <%= gettext("uses left: unlimited") %> <% end %>

<% else %>

<%= gettext("invite disabled") %>

<% end %> <.qr_code content={Routes.user_registration_url(Endpoint, :new, invite: @invite.token)} filename={@invite.name} />

<%= gettext("uses: %{uses_count}", uses_count: @use_count) %>

<%= Routes.user_registration_url(Endpoint, :new, invite: @invite.token) %> <%= render_slot(@code_actions) %>
<%= render_slot(@inner_block) %>
""" end end