feat: account live view - basic functionality

This commit is contained in:
Moritz 2025-07-17 22:07:44 +02:00 committed by moritz
parent fd8c853879
commit df9966bb12
9 changed files with 389 additions and 42 deletions

View file

@ -7,12 +7,34 @@ defmodule MvWeb.UserLive.Form do
<Layouts.app flash={@flash}>
<.header>
{@page_title}
<:subtitle>Use this form to manage user records in your database.</:subtitle>
<:subtitle>{gettext("Use this form to manage user records in your database.")}</:subtitle>
</.header>
<.form for={@form} id="user-form" phx-change="validate" phx-submit="save">
<.button phx-disable-with="Saving..." variant="primary">Save User</.button>
<.button navigate={return_path(@return_to, @user)}>Cancel</.button>
<.input field={@form[:email]} label={gettext("Email")} required type="email" />
<%= if @user do %>
<div class="mt-4 p-4 bg-blue-50 rounded-lg">
<p class="text-sm text-blue-800">
<strong>{gettext("Note")}:</strong> {gettext(
"Password can only be changed through authentication functions."
)}
</p>
</div>
<% else %>
<div class="mt-4 p-4 bg-yellow-50 rounded-lg">
<p class="text-sm text-yellow-800">
<strong>{gettext("Note")}:</strong> {gettext(
"Users created here will need to set their password through the authentication system."
)}
</p>
</div>
<% end %>
<.button phx-disable-with={gettext("Saving...")} variant="primary">
{gettext("Save User")}
</.button>
<.button navigate={return_path(@return_to, @user)}>{gettext("Cancel")}</.button>
</.form>
</Layouts.app>
"""
@ -23,11 +45,11 @@ defmodule MvWeb.UserLive.Form do
user =
case params["id"] do
nil -> nil
id -> Ash.get!(Mv.Accounts.User, id)
id -> Ash.get!(Mv.Accounts.User, id, domain: Mv.Accounts)
end
action = if is_nil(user), do: "New", else: "Edit"
page_title = action <> " " <> "User"
action = if is_nil(user), do: gettext("New"), else: gettext("Edit")
page_title = action <> " " <> gettext("User")
{:ok,
socket
@ -67,9 +89,12 @@ defmodule MvWeb.UserLive.Form do
defp assign_form(%{assigns: %{user: user}} = socket) do
form =
if user do
AshPhoenix.Form.for_update(user, :update, as: "user")
AshPhoenix.Form.for_update(user, :update_user, domain: Mv.Accounts, as: "user")
else
AshPhoenix.Form.for_create(Mv.Accounts.User, :create, as: "user")
AshPhoenix.Form.for_create(Mv.Accounts.User, :create_user,
domain: Mv.Accounts,
as: "user"
)
end
assign(socket, form: to_form(form))