memEx/lib/memex_web/components/invite_card.ex

73 lines
2.2 KiB
Elixir
Raw Normal View History

2022-07-25 19:31:54 -04:00
defmodule MemexWeb.Components.InviteCard do
2022-02-25 21:52:17 -05:00
@moduledoc """
Display card for an invite
"""
2022-07-25 19:31:54 -04:00
use MemexWeb, :component
2023-02-04 17:22:06 -05:00
alias Memex.Accounts.{Invite, Invites, User}
alias MemexWeb.Endpoint
2022-02-25 21:52:17 -05:00
2023-02-04 17:22:06 -05:00
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)
2023-01-26 00:36:15 -05:00
2022-02-25 21:52:17 -05:00
~H"""
2023-02-14 01:04:15 -05:00
<div class="px-8 py-4 flex flex-col justify-center items-center space-y-4
bg-primary-900
2022-02-25 21:52:17 -05:00
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
2022-05-05 21:07:02 -04:00
transition-all duration-300 ease-in-out">
2022-02-25 21:52:17 -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:36:15 -05:00
<%= if @invite.uses_left do %>
<%= gettext(
2023-02-04 17:22:06 -05:00
"uses left: %{uses_left_count}",
uses_left_count: @invite.uses_left
2023-01-26 00:36:15 -05:00
) %>
<% else %>
<%= gettext("uses left: unlimited") %>
<% end %>
2022-02-25 21:52:17 -05:00
</h2>
<% else %>
<h2 class="title text-md">
2022-11-17 22:30:01 -05:00
<%= gettext("invite disabled") %>
2022-02-25 21:52:17 -05:00
</h2>
<% end %>
2023-01-26 00:46:27 -05:00
<.qr_code
content={Routes.user_registration_url(Endpoint, :new, invite: @invite.token)}
filename={@invite.name}
/>
2023-02-04 17:22:06 -05:00
<h2 :if={@use_count != 0} class="title text-md">
<%= gettext("uses: %{uses_count}", uses_count: @use_count) %>
</h2>
2022-02-25 21:52:17 -05:00
<div class="flex flex-row flex-wrap justify-center items-center">
<code
id={"code-#{@invite.id}"}
2023-02-14 01:04:15 -05:00
class="mx-2 my-1 text-xs px-4 py-2 rounded-lg text-center break-all
text-primary-400 bg-primary-800"
2023-01-26 00:36:15 -05:00
phx-no-format
><%= Routes.user_registration_url(Endpoint, :new, invite: @invite.token) %></code>
<%= render_slot(@code_actions) %>
2022-02-25 21:52:17 -05:00
</div>
2023-02-04 11:29:06 -05:00
<div :if={@inner_block} class="flex space-x-4 justify-center items-center">
<%= render_slot(@inner_block) %>
</div>
2022-02-25 21:52:17 -05:00
</div>
"""
end
end