2022-02-12 02:28:27 -05:00
|
|
|
defmodule CanneryWeb.Components.InviteCard do
|
|
|
|
@moduledoc """
|
|
|
|
Display card for an invite
|
|
|
|
"""
|
|
|
|
|
|
|
|
use CanneryWeb, :component
|
2022-11-09 21:17:16 -05:00
|
|
|
alias Cannery.Invites.Invite
|
2022-02-12 02:28:27 -05:00
|
|
|
alias CanneryWeb.Endpoint
|
|
|
|
|
2022-11-09 21:17:16 -05:00
|
|
|
attr :invite, Invite, required: true
|
|
|
|
slot(:inner_block)
|
|
|
|
slot(:code_actions)
|
|
|
|
|
2022-02-12 02:28:27 -05:00
|
|
|
def invite_card(assigns) do
|
2022-11-09 21:17:16 -05:00
|
|
|
assigns = assigns |> assign_new(:code_actions, fn -> [] end)
|
|
|
|
|
2022-02-12 02:28:27 -05:00
|
|
|
~H"""
|
2022-11-19 13:16:13 -05:00
|
|
|
<div
|
|
|
|
id={"invite-#{@invite.id}"}
|
|
|
|
class="mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center space-y-4
|
2022-02-15 23:20:18 -05:00
|
|
|
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
|
2022-11-19 13:16:13 -05:00
|
|
|
transition-all duration-300 ease-in-out"
|
|
|
|
>
|
2022-02-12 02:28:27 -05:00
|
|
|
<h1 class="title text-xl">
|
|
|
|
<%= @invite.name %>
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
<%= if @invite.disabled_at |> is_nil() do %>
|
|
|
|
<h2 class="title text-md">
|
2023-01-26 00:39:16 -05:00
|
|
|
<%= if @invite.uses_left do %>
|
|
|
|
<%= gettext(
|
|
|
|
"Uses Left: %{uses_left}",
|
|
|
|
uses_left: @invite.uses_left
|
|
|
|
) %>
|
|
|
|
<% else %>
|
|
|
|
<%= gettext("Uses Left: Unlimited") %>
|
|
|
|
<% end %>
|
2022-02-12 02:28:27 -05:00
|
|
|
</h2>
|
|
|
|
<% else %>
|
|
|
|
<h2 class="title text-md">
|
|
|
|
<%= gettext("Invite Disabled") %>
|
|
|
|
</h2>
|
|
|
|
<% end %>
|
|
|
|
|
2023-01-26 00:46:25 -05:00
|
|
|
<.qr_code
|
|
|
|
content={Routes.user_registration_url(Endpoint, :new, invite: @invite.token)}
|
|
|
|
filename={@invite.name}
|
|
|
|
/>
|
|
|
|
|
2022-02-15 23:52:44 -05:00
|
|
|
<div class="flex flex-row flex-wrap justify-center items-center">
|
|
|
|
<code
|
|
|
|
id={"code-#{@invite.id}"}
|
|
|
|
class="mx-2 my-1 text-xs px-4 py-2 rounded-lg text-center break-all text-gray-100 bg-primary-800"
|
2022-11-11 21:36:57 -05:00
|
|
|
phx-no-format
|
|
|
|
><%= Routes.user_registration_url(Endpoint, :new, invite: @invite.token) %></code>
|
2022-11-09 21:17:16 -05:00
|
|
|
<%= render_slot(@code_actions) %>
|
2022-02-15 19:50:48 -05:00
|
|
|
</div>
|
2022-02-12 02:28:27 -05:00
|
|
|
|
|
|
|
<%= if @inner_block do %>
|
|
|
|
<div class="flex space-x-4 justify-center items-center">
|
|
|
|
<%= render_slot(@inner_block) %>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|