towerops/lib/towerops_web/live/org_live/index.html.heex
Graham McIntire c56496f7cc
fix: org switching now correctly updates session
The select_org LiveView event was updating default_organization_id in
the database but not the session's current_organization_id. Since
load_default_organization prioritizes the session value, users would
always get redirected back to the stale org.

Replaced with a controller POST action that updates both the session
and DB default before redirecting.
2026-03-04 17:04:49 -06:00

50 lines
1.8 KiB
Text

<Layouts.authenticated
flash={@flash}
current_scope={@current_scope}
>
<.header>
{@page_title}
<:actions>
<.button navigate={~p"/orgs/new"} variant="primary">
<.icon name="hero-plus" class="h-5 w-5" /> New Organization
</.button>
</:actions>
</.header>
<div :if={@organizations != []} class="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
<form
:for={org <- @organizations}
method="post"
action={~p"/orgs/switch"}
>
<input type="hidden" name="_csrf_token" value={Phoenix.Controller.get_csrf_token()} />
<input type="hidden" name="org_id" value={org.id} />
<button
type="submit"
class="relative w-full overflow-hidden rounded-lg border border-gray-200 bg-white p-6 shadow-sm hover:shadow-md transition-shadow dark:border-white/10 dark:bg-gray-800/50 cursor-pointer text-left"
>
<h2 class="text-xl font-semibold text-gray-900 dark:text-white">{org.name}</h2>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">
{Enum.find(org.memberships, &(&1.user_id == @current_scope.user.id)).role
|> to_string()
|> String.capitalize()}
</p>
</button>
</form>
</div>
<div :if={@organizations == []} class="text-center py-16">
<.icon name="hero-building-office" class="mx-auto h-12 w-12 text-gray-400 dark:text-gray-600" />
<h3 class="mt-4 text-lg font-semibold text-gray-900 dark:text-white">
{t("No organizations")}
</h3>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">
{t("Get started by creating a new organization.")}
</p>
<div class="mt-6">
<.button navigate={~p"/orgs/new"} variant="primary">
<.icon name="hero-plus" class="h-5 w-5" /> New Organization
</.button>
</div>
</div>
</Layouts.authenticated>