style: consistent back button and some translations
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
91cf7cca6a
commit
0f12befd11
26 changed files with 747 additions and 710 deletions
|
|
@ -34,14 +34,20 @@ defmodule MvWeb.UserLive.Show do
|
|||
~H"""
|
||||
<Layouts.app flash={@flash} current_user={@current_user}>
|
||||
<.header>
|
||||
<:leading>
|
||||
<.button
|
||||
navigate={~p"/users"}
|
||||
variant="neutral"
|
||||
aria-label={gettext("Back to users list")}
|
||||
>
|
||||
<.icon name="hero-arrow-left" class="size-4" />
|
||||
{gettext("Back")}
|
||||
</.button>
|
||||
</:leading>
|
||||
{gettext("User")} {@user.email}
|
||||
<:subtitle>{gettext("This is a user record from your database.")}</:subtitle>
|
||||
|
||||
<:actions>
|
||||
<.button navigate={~p"/users"} variant="neutral" aria-label={gettext("Back to users list")}>
|
||||
<.icon name="hero-arrow-left" />
|
||||
<span class="sr-only">{gettext("Back to users list")}</span>
|
||||
</.button>
|
||||
<%= if can?(@current_user, :update, @user) do %>
|
||||
<.button
|
||||
variant="primary"
|
||||
|
|
@ -99,7 +105,8 @@ defmodule MvWeb.UserLive.Show do
|
|||
phx-click="delete"
|
||||
phx-value-id={@user.id}
|
||||
data-confirm={
|
||||
gettext("Are you sure you want to delete the user %{email}? This action cannot be undone.",
|
||||
gettext(
|
||||
"Are you sure you want to delete the user %{email}? This action cannot be undone.",
|
||||
email: @user.email
|
||||
)
|
||||
}
|
||||
|
|
@ -141,33 +148,32 @@ defmodule MvWeb.UserLive.Show do
|
|||
user = socket.assigns.user
|
||||
actor = current_actor(socket)
|
||||
|
||||
if to_string(id) != to_string(user.id) do
|
||||
{:noreply, put_flash(socket, :error, gettext("User not found"))}
|
||||
else
|
||||
if Mv.Helpers.SystemActor.system_user?(user) do
|
||||
cond do
|
||||
to_string(id) != to_string(user.id) ->
|
||||
{:noreply, put_flash(socket, :error, gettext("User not found"))}
|
||||
|
||||
Mv.Helpers.SystemActor.system_user?(user) ->
|
||||
{:noreply, put_flash(socket, :error, gettext("System user cannot be deleted."))}
|
||||
|
||||
true ->
|
||||
handle_user_delete_destroy(socket, user, actor)
|
||||
end
|
||||
end
|
||||
|
||||
defp handle_user_delete_destroy(socket, user, actor) do
|
||||
case Ash.destroy(user, domain: Mv.Accounts, actor: actor) do
|
||||
:ok ->
|
||||
{:noreply,
|
||||
put_flash(socket, :error, gettext("System user cannot be deleted."))}
|
||||
else
|
||||
case Ash.destroy(user, domain: Mv.Accounts, actor: actor) do
|
||||
:ok ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:success, gettext("User deleted successfully"))
|
||||
|> push_navigate(to: ~p"/users")}
|
||||
socket
|
||||
|> put_flash(:success, gettext("User deleted successfully"))
|
||||
|> push_navigate(to: ~p"/users")}
|
||||
|
||||
{:error, %Ash.Error.Forbidden{}} ->
|
||||
{:noreply,
|
||||
put_flash(
|
||||
socket,
|
||||
:error,
|
||||
gettext("You do not have permission to delete this user")
|
||||
)}
|
||||
{:error, %Ash.Error.Forbidden{}} ->
|
||||
{:noreply,
|
||||
put_flash(socket, :error, gettext("You do not have permission to delete this user"))}
|
||||
|
||||
{:error, error} ->
|
||||
{:noreply,
|
||||
put_flash(socket, :error, format_ash_error(error))}
|
||||
end
|
||||
end
|
||||
{:error, error} ->
|
||||
{:noreply, put_flash(socket, :error, format_ash_error(error))}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue