Skip to content

Commit 7221ef1

Browse files
committed
Improve admin UI
1 parent be7f1c7 commit 7221ef1

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/password_example_web/live/admin_live.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ defmodule PasswordExampleWeb.AdminLive do
1010
end
1111

1212
@impl true
13-
def handle_event("change_hash_type", %{"value" => hash_type}, socket) do
14-
hash_type = String.to_atom(hash_type)
13+
def handle_event("change_hash_type", %{"change_hash_type" => %{"hash_type" => hash_type_str}}, socket) do
14+
hash_type = String.to_atom(hash_type_str)
1515
HashingAlgorithmChoice.set(hash_type)
16+
socket = socket
17+
|> assign(hash_type: hash_type)
18+
|> put_flash(:info, "Changed hash type to " <> hash_type_str)
19+
{:noreply, socket}
20+
end
21+
22+
@impl true
23+
def handle_event("delete_all_users", _, socket) do
1624
User.delete_all()
17-
{:noreply, assign(socket, hash_type: hash_type)}
25+
{:noreply, socket}
1826
end
1927
end
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<h1>Admin</h1>
22

3-
<%= select :hash_type, :hash_type, HashingAlgorithmChoice.choices, value: @hash_type, phx_blur: "change_hash_type" %>
4-
<button type="button">Delete Users and Change Hash Type</button>
3+
<%= f = form_for :change_hash_type, "#", [phx_submit: "change_hash_type", style: "display: flex; gap: 1rem"] %>
4+
<label>
5+
Current hash type:
6+
<%= select f, :hash_type, HashingAlgorithmChoice.choices, value: @hash_type %>
7+
</label>
8+
<%= submit "Change hash type" %>
9+
</form>
10+
11+
<%= form_for :delete_all_users, "#", [phx_submit: "delete_all_users"] %>
12+
<%= submit "Delete all users" %>
13+
</form>
514

615
<%= live_component @socket, UsersTableComponent, id: :users_table %>

0 commit comments

Comments
 (0)