shift73k/lib/shift73k_web/live/user_management/delete_component.ex

42 lines
995 B
Elixir
Raw Permalink Normal View History

2021-03-05 19:23:32 -05:00
defmodule Shift73kWeb.UserManagement.DeleteComponent do
use Shift73kWeb, :live_component
2021-03-05 19:23:32 -05:00
alias Shift73k.Accounts
@impl true
def update(assigns, socket) do
socket |> assign(assigns) |> live_okreply()
end
@impl true
def handle_event("confirm", %{"id" => id, "email" => email} = params, socket) do
IO.inspect(params)
user = Accounts.get_user(id)
IO.inspect(user)
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