feat: account live view - generated files
This commit is contained in:
parent
25919470d9
commit
4f74d54128
4 changed files with 186 additions and 0 deletions
62
lib/mv_web/live/user_live/index.ex
Normal file
62
lib/mv_web/live/user_live/index.ex
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
defmodule MvWeb.UserLive.Index do
|
||||
use MvWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<Layouts.app flash={@flash}>
|
||||
<.header>
|
||||
Listing Users
|
||||
<:actions>
|
||||
<.button variant="primary" navigate={~p"/users/new"}>
|
||||
<.icon name="hero-plus" /> New User
|
||||
</.button>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.table
|
||||
id="users"
|
||||
rows={@streams.users}
|
||||
row_click={fn {_id, user} -> JS.navigate(~p"/users/#{user}") end}
|
||||
>
|
||||
<:col :let={{_id, user}} label="Id">{user.id}</:col>
|
||||
|
||||
<:col :let={{_id, user}} label="Email">{user.email}</:col>
|
||||
|
||||
<:action :let={{_id, user}}>
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/users/#{user}"}>Show</.link>
|
||||
</div>
|
||||
|
||||
<.link navigate={~p"/users/#{user}/edit"}>Edit</.link>
|
||||
</:action>
|
||||
|
||||
<:action :let={{id, user}}>
|
||||
<.link
|
||||
phx-click={JS.push("delete", value: %{id: user.id}) |> hide("##{id}")}
|
||||
data-confirm="Are you sure?"
|
||||
>
|
||||
Delete
|
||||
</.link>
|
||||
</:action>
|
||||
</.table>
|
||||
</Layouts.app>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:page_title, "Listing Users")
|
||||
|> stream(:users, Ash.read!(Mv.Accounts.User))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, socket) do
|
||||
user = Ash.get!(Mv.Accounts.User, id)
|
||||
Ash.destroy!(user)
|
||||
|
||||
{:noreply, stream_delete(socket, :users, user)}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue