-
Notifications
You must be signed in to change notification settings - Fork 0
feat: tables page #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| defmodule GalliumWeb.BackOffice.TablesLive.Index do | ||
| @moduledoc """ | ||
| LiveView showing seating arrangement: one rectangle per table with avatars | ||
| for each person around it. | ||
| """ | ||
| use GalliumWeb, :live_view | ||
|
|
||
| import GalliumWeb.BackOffice.Components.BackofficeLayout | ||
|
|
||
| alias Gallium.Ticketing | ||
|
|
||
| attr :name, :string, required: true | ||
| attr :people, :list, required: true | ||
|
|
||
| def table_card(assigns) do | ||
| {top, bottom} = split_people(assigns.people) | ||
| assigns = assigns |> assign(:top, top) |> assign(:bottom, bottom) | ||
|
|
||
| ~H""" | ||
| <div class="bg-white rounded-xl border border-gray-200 shadow-sm px-6 py-8"> | ||
| <div class="flex flex-col items-center gap-3"> | ||
| <div class="flex justify-center gap-3 min-h-10"> | ||
| <.avatar :for={person <- @top} person={person} /> | ||
| </div> | ||
|
|
||
| <div class="w-full max-w-md h-28 rounded-lg bg-olive text-white flex items-center justify-center shadow-inner"> | ||
| <span class="font-amarante text-2xl uppercase tracking-widest">{@name}</span> | ||
| </div> | ||
|
|
||
| <div class="flex justify-center gap-3 min-h-10"> | ||
| <.avatar :for={person <- @bottom} person={person} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| """ | ||
| end | ||
|
|
||
| attr :person, :map, required: true | ||
|
|
||
| defp avatar(assigns) do | ||
| ~H""" | ||
| <div class="relative group"> | ||
| <div | ||
| class="w-10 h-10 rounded-full bg-olive-100 text-olive-700 border border-olive-200 flex items-center justify-center font-amarante text-sm font-bold cursor-default select-none" | ||
| title={@person.full_name} | ||
| > | ||
| {@person.initials} | ||
| </div> | ||
| <span class="pointer-events-none absolute left-1/2 -translate-x-1/2 -top-9 whitespace-nowrap rounded bg-gray-900 text-white text-xs px-2 py-1 opacity-0 group-hover:opacity-100 transition-opacity font-cormorant z-10"> | ||
| {@person.full_name} | ||
| </span> | ||
| </div> | ||
| """ | ||
| end | ||
|
|
||
| defp split_people(people) do | ||
| count = length(people) | ||
| half = div(count + 1, 2) | ||
| Enum.split(people, half) | ||
| end | ||
|
|
||
| def mount(_params, _session, socket) do | ||
| tables = | ||
| Ticketing.list_tables_with_attendees() | ||
| |> Enum.map(fn {name, people} -> | ||
| %{ | ||
| name: name, | ||
| people: Enum.map(people, fn p -> Map.put(p, :initials, initials(p.full_name)) end) | ||
| } | ||
| end) | ||
|
|
||
| socket = | ||
| socket | ||
| |> assign(:current_page, :tables) | ||
| |> assign(:sidebar_open, false) | ||
| |> assign(:tables, tables) | ||
|
|
||
| {:ok, socket} | ||
| end | ||
|
|
||
| def handle_event("toggle_sidebar", _params, socket) do | ||
| {:noreply, assign(socket, :sidebar_open, !socket.assigns.sidebar_open)} | ||
| end | ||
|
|
||
| defp initials(nil), do: "?" | ||
|
|
||
| defp initials(full_name) do | ||
| parts = | ||
| full_name | ||
| |> String.split(~r/\s+/, trim: true) | ||
| |> Enum.reject(&(&1 == "")) | ||
|
|
||
| case parts do | ||
| [] -> | ||
| "?" | ||
|
|
||
| [one] -> | ||
| String.upcase(String.slice(one, 0, 1)) | ||
|
|
||
| list -> | ||
| String.upcase(String.slice(List.first(list), 0, 1) <> String.slice(List.last(list), 0, 1)) | ||
| end | ||
| end | ||
| end |
25 changes: 25 additions & 0 deletions
25
lib/gallium_web/live/backoffice/tables_live/index.html.heex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <.backoffice_layout sidebar_open={@sidebar_open} current_page={@current_page} flash={@flash}> | ||
| <div class="w-full"> | ||
| <div class="flex flex-col gap-6"> | ||
| <div class="mb-2"> | ||
| <h1 class="text-4xl font-bold text-gray-content font-amarante">Mesas</h1> | ||
| <p class="text-gray mt-2 font-cormorant"> | ||
| Distribuição de convidados por mesa. | ||
| </p> | ||
| </div> | ||
|
|
||
| <%= if @tables == [] do %> | ||
| <div class="flex flex-col items-center justify-center py-24 text-gray-300 font-cormorant bg-white rounded-xl border border-gray-200 shadow-sm"> | ||
| <.icon name="hero-rectangle-group" class="size-14 mb-4" /> | ||
| <p class="text-lg">Ainda não há mesas atribuídas.</p> | ||
| </div> | ||
| <% else %> | ||
| <div class="grid grid-cols-1 lg:grid-cols-2 gap-10"> | ||
| <%= for table <- @tables do %> | ||
| <.table_card name={table.name} people={table.people} /> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
| </.backoffice_layout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.