- <%= label f, :price, class: "form-label" %>
-
-
- <%= label f, :description, class: "form-label" %>
-
- <%= submit "Save", phx_disable_with: "Saving...", class: "btn btn-primary" %>
+
+
<% end %>
diff --git a/lib/bones73k_web/live/user_management/delete_component.ex b/lib/bones73k_web/live/user_management/delete_component.ex
new file mode 100644
index 0000000..548f749
--- /dev/null
+++ b/lib/bones73k_web/live/user_management/delete_component.ex
@@ -0,0 +1,44 @@
+defmodule Bones73kWeb.UserManagement.DeleteComponent do
+ use Bones73kWeb, :live_component
+
+ alias Bones73k.Accounts
+
+ @impl true
+ def update(assigns, socket) do
+ socket
+ |> assign(assigns)
+ |> live_okreply()
+ end
+
+ @impl true
+ def handle_event("cancel", _, socket) do
+ {:noreply, push_event(socket, "modal-please-hide", %{})}
+ end
+
+ @impl true
+ def handle_event("confirm", %{"id" => id, "email" => email}, socket) do
+ id
+ |> Accounts.get_user()
+ |> Accounts.delete_user()
+ |> case do
+ {:ok, _} ->
+ flash = {:info, "User deleted successfully: \"#{email}\""}
+ send(self(), {:put_flash_message, flash})
+
+ socket
+ |> push_event("modal-please-hide", %{})
+ |> live_noreply()
+
+ {:error, _} ->
+ flash =
+ {:error,
+ "Some error trying to delete user \"#{email}\". Possibly already deleted? Reloading list..."}
+
+ send(self(), {:put_flash_message, flash})
+
+ socket
+ |> push_event("modal-please-hide", %{})
+ |> live_noreply()
+ end
+ end
+end
diff --git a/lib/bones73k_web/live/user_management/delete_component.html.leex b/lib/bones73k_web/live/user_management/delete_component.html.leex
new file mode 100644
index 0000000..b2d3390
--- /dev/null
+++ b/lib/bones73k_web/live/user_management/delete_component.html.leex
@@ -0,0 +1,16 @@
+
+
+ Are you sure you want to delete "<%= @delete_user.email %>"?
+
+
+
diff --git a/lib/bones73k_web/live/user_management/form_component.ex b/lib/bones73k_web/live/user_management/form_component.ex
index 6da64e1..e786654 100644
--- a/lib/bones73k_web/live/user_management/form_component.ex
+++ b/lib/bones73k_web/live/user_management/form_component.ex
@@ -10,7 +10,6 @@ defmodule Bones73kWeb.UserManagement.FormComponent do
socket
|> assign(assigns)
|> init_changeset(assigns)
- |> assign(:role_id, 1)
|> live_okreply()
end
@@ -40,7 +39,7 @@ defmodule Bones73kWeb.UserManagement.FormComponent do
&Routes.user_confirmation_url(socket, :confirm, &1)
)
- flash = {:success, "User created successfully: #{user.email}"}
+ flash = {:info, "User created successfully: #{user.email}"}
send(self(), {:put_flash_message, flash})
socket
@@ -81,6 +80,11 @@ defmodule Bones73kWeb.UserManagement.FormComponent do
save_user(socket, user_params)
end
+ @impl true
+ def handle_event("cancel", _, socket) do
+ {:noreply, push_event(socket, "modal-please-hide", %{})}
+ end
+
def role_description(role) when is_atom(role) do
Keyword.get(User.roles(), role)
end
diff --git a/lib/bones73k_web/live/user_management/form_component.html.leex b/lib/bones73k_web/live/user_management/form_component.html.leex
index 0dad565..2f0c208 100644
--- a/lib/bones73k_web/live/user_management/form_component.html.leex
+++ b/lib/bones73k_web/live/user_management/form_component.html.leex
@@ -4,64 +4,69 @@
phx_submit: "save"
], fn f -> %>
-
- <%= label f, :email, class: "form-label" %>
-