defmodule VigilWeb.HomeLive do
@moduledoc """
The front page, for everyone. Signed out, it says how to get in (an
invite, or NEIAM); signed in, it's the starting point.
"""
use VigilWeb, :live_view
alias Vigil.{Accounts, Organizations}
@impl true
def mount(_params, _session, socket) do
memberships =
case socket.assigns.current_scope do
%{user: %{} = user} -> Organizations.list_memberships(user)
_ -> []
end
{:ok,
socket
|> assign(:page_title, "Home")
|> assign(:no_orgs?, memberships == [])
|> stream(:memberships, memberships)}
end
@impl true
def render(assigns) do
~H"""
<Layouts.app flash={@flash} current_scope={@current_scope} active={:home}>
<%= if @current_scope && @current_scope.user do %>
<section id="home-signed-in" class="space-y-6">
<div class="space-y-1">
<p class="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Vigil</p>
<h1 class="text-2xl font-extrabold tracking-tight sm:text-3xl">
Welcome back, {Accounts.display_name(@current_scope.user)}.
</h1>
</div>
<ul id="home-orgs" phx-update="stream" class="grid gap-4 sm:grid-cols-2">
<li :for={{dom_id, m} <- @streams.memberships} id={dom_id}>
<.home_card
id={"#{dom_id}-link"}
navigate={~p"/orgs/#{m.organization.slug}"}
icon="hero-building-office-2"
title={m.organization.name}
>
Its projects and issues.
</.home_card>
</li>
</ul>
<div class="grid gap-4 sm:grid-cols-2">
<.home_card
id="home-new-org"
navigate={~p"/orgs"}
icon="hero-plus"
title={if @no_orgs?, do: "Start an organization", else: "Organizations"}
>
Projects live in organizations: make one, or switch between yours.
</.home_card>
<.home_card
id="home-tokens"
navigate={~p"/users/tokens"}
icon="hero-key"
title="API tokens"
>
For sentry-cli: releases, deploys and sourcemaps.
</.home_card>
<.home_card
id="home-invites"
navigate={~p"/users/invites"}
icon="hero-envelope"
title="Invites"
>
Bring someone in: make a one-time sign-up link and hand it over.
</.home_card>
<.home_card
id="home-settings"
navigate={~p"/users/settings"}
icon="hero-cog-6-tooth"
title="Settings"
>
Your email, password and linked NEIAM account.
</.home_card>
</div>
</section>
<% else %>
<section id="landing" class="mx-auto max-w-2xl space-y-6 py-12 text-center">
<span class="mx-auto grid size-14 place-items-center rounded-2xl bg-primary text-primary-content shadow-lg">
<.icon name="hero-eye-solid" class="size-7" />
</span>
<div class="space-y-2">
<h1 class="text-3xl font-extrabold tracking-tight sm:text-4xl">Vigil</h1>
<p class="text-base-content/70">
<%= if Accounts.registration_open?() do %>
Make an account, or log in to the one you have.
<% else %>
Sign-up is by invite: open the link you were sent, or log in.
<% end %>
</p>
</div>
<div class="flex flex-wrap justify-center gap-2">
<.link navigate={~p"/users/log-in"} class="btn btn-primary" id="landing-log-in">
Log in
</.link>
<.link
:if={Accounts.registration_open?() and NeiamAuth.local_login_enabled?()}
navigate={~p"/users/register"}
class="btn btn-ghost"
id="landing-register"
>
Register
</.link>
</div>
</section>
<% end %>
</Layouts.app>
"""
end
attr :id, :string, required: true
attr :navigate, :string, required: true
attr :icon, :string, required: true
attr :title, :string, required: true
slot :inner_block, required: true
defp home_card(assigns) do
~H"""
<.link
id={@id}
navigate={@navigate}
class="group flex items-start gap-4 rounded-box border border-base-300 bg-base-100 p-5 transition hover:-translate-y-0.5 hover:border-primary/50 hover:shadow-md"
>
<span class="grid size-10 shrink-0 place-items-center rounded-lg bg-primary/10 text-primary transition-transform group-hover:-rotate-6">
<.icon name={@icon} class="size-5" />
</span>
<div class="space-y-1">
<p class="font-semibold">{@title}</p>
<p class="text-sm text-base-content/70">{render_slot(@inner_block)}</p>
</div>
</.link>
"""
end
end
neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
⭐
Log in to mark this repository.
4.9 KiB · text
History
7bff5e7