defmodule VigilWeb.ProjectLive.Show do
@moduledoc """
A project's page. Until its issues arrive (slice 3) it is the setup
guide: the DSN and a snippet for its platform.
"""
use VigilWeb, :live_view
alias Vigil.Accounts.Scope
alias Vigil.Projects
alias Vigil.Projects.Platforms
@impl true
def mount(_params, _session, socket) do
project = socket.assigns.project
key = project |> Projects.list_keys() |> Enum.find(& &1.active)
dsn = key && Projects.dsn(key, project)
{:ok,
socket
|> assign(:page_title, project.name)
|> assign(:dsn, dsn)
|> assign(:snippet, dsn && Platforms.snippet(project.platform, dsn))}
end
@impl true
def render(assigns) do
~H"""
<Layouts.app flash={@flash} current_scope={@current_scope} active={:projects}>
<.header>
{@project.name}
<:subtitle>
{Platforms.name(@project.platform)} · <span class="font-mono">{@project.slug}</span>
</:subtitle>
<:actions>
<.link
:if={Scope.can?(@current_scope, "project:write")}
navigate={
~p"/orgs/#{@current_scope.organization.slug}/projects/#{@project.slug}/settings"
}
class="btn btn-ghost btn-sm"
id="project-settings"
>
<.icon name="hero-cog-6-tooth-micro" class="size-4" /> Settings
</.link>
</:actions>
</.header>
<section id="setup" class="space-y-4 rounded-box border border-base-300 bg-base-100 p-5">
<div class="flex items-center gap-2">
<span class={[
"size-2.5 rounded-full",
if(@project.first_event_at,
do: "bg-success",
else: "bg-warning motion-safe:animate-pulse"
)
]} />
<h2 class="font-semibold">
{if @project.first_event_at, do: "Receiving events", else: "Waiting for the first event"}
</h2>
</div>
<%= if @dsn do %>
<div>
<p class="mb-1 text-sm text-base-content/70">DSN</p>
<div class="join w-full">
<input
id="dsn"
type="text"
readonly
value={@dsn}
class="input input-sm join-item min-w-0 flex-1 font-mono text-xs"
aria-label="DSN"
/>
<button
id="copy-dsn"
type="button"
class="btn btn-sm btn-primary join-item"
phx-click={JS.dispatch("phx:copy", to: "#dsn")}
>
<.icon name="hero-clipboard-document-micro" class="size-4" /> Copy
</button>
</div>
</div>
<pre
id="snippet"
class="overflow-x-auto rounded-box bg-base-200 p-4 font-mono text-xs leading-relaxed"
><code>{@snippet}</code></pre>
<% else %>
<p class="text-sm text-warning">
This project has no active key. Make one in its settings.
</p>
<% end %>
</section>
</Layouts.app>
"""
end
end
neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions queued · Badges · Packages
⭐
Log in to mark this repository.
3.1 KiB · text
History
573fef1