From bc39c24e65324041110195610e28dba745bfe7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lobo?= Date: Mon, 11 May 2026 23:12:39 +0100 Subject: [PATCH 1/3] feat: tables page --- lib/gallium/ticketing.ex | 26 +++++ .../live/backoffice/components/sidebar.ex | 20 ++-- .../live/backoffice/tables_live/index.ex | 104 ++++++++++++++++++ .../backoffice/tables_live/index.html.heex | 25 +++++ lib/gallium_web/router.ex | 3 +- priv/repo/seeds/ticketing.exs | 39 ++++++- 6 files changed, 203 insertions(+), 14 deletions(-) create mode 100644 lib/gallium_web/live/backoffice/tables_live/index.ex create mode 100644 lib/gallium_web/live/backoffice/tables_live/index.html.heex diff --git a/lib/gallium/ticketing.ex b/lib/gallium/ticketing.ex index c47e750..997ee67 100644 --- a/lib/gallium/ticketing.ex +++ b/lib/gallium/ticketing.ex @@ -20,6 +20,32 @@ defmodule Gallium.Ticketing do |> Repo.preload([:payment, :accompany, user: :ticket]) end + @doc """ + Groups attendees (and their accompanies) by `table_preference`. + """ + def list_tables_with_attendees do + Attendee + |> where([a], not is_nil(a.table_preference) and a.table_preference != "") + |> order_by([a], asc: a.table_preference, asc: a.inserted_at) + |> Repo.all() + |> Repo.preload(:accompany) + |> Enum.group_by(& &1.table_preference) + |> Enum.map(fn {table, attendees} -> {table, table_people(attendees)} end) + |> Enum.sort_by(fn {table, _} -> table end) + end + + defp table_people(attendees) do + Enum.flat_map(attendees, &attendee_and_accompany/1) + end + + defp attendee_and_accompany(%Attendee{accompany: nil} = attendee) do + [%{full_name: attendee.full_name}] + end + + defp attendee_and_accompany(%Attendee{accompany: accompany} = attendee) do + [%{full_name: attendee.full_name}, %{full_name: accompany.full_name}] + end + @doc """ Returns the list of accompanies. diff --git a/lib/gallium_web/live/backoffice/components/sidebar.ex b/lib/gallium_web/live/backoffice/components/sidebar.ex index fbc1209..b7175f8 100644 --- a/lib/gallium_web/live/backoffice/components/sidebar.ex +++ b/lib/gallium_web/live/backoffice/components/sidebar.ex @@ -7,17 +7,23 @@ defmodule GalliumWeb.BackOffice.Components.Sidebar do def sidebar(assigns) do menu_items = [ - %{ - action: :members, - icon: "hero-arrow-up-tray", - label: "Adicionar Membros", - path: ~p"/dashboard/members" - }, %{ action: :attendees, icon: "hero-users", label: "Inscrições", path: ~p"/dashboard/attendees" + }, + %{ + action: :tables, + icon: "hero-rectangle-group", + label: "Mesas", + path: ~p"/dashboard/tables" + }, + %{ + action: :members, + icon: "hero-arrow-up-tray", + label: "Sócios", + path: ~p"/dashboard/members" } ] @@ -29,7 +35,7 @@ defmodule GalliumWeb.BackOffice.Components.Sidebar do if(@sidebar_open, do: "translate-x-0", else: "-translate-x-full md:translate-x-0") ]}>
-

Menu

+