From 1133c048d1a74982b1a26de43f648ad198cc618d Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 26 Mar 2025 11:57:11 +0200 Subject: [PATCH] Update the Author form to redirect to Index or Show LiveView. --- .../live/author_live/form_component.ex | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/decentralised_book_index_web/live/author_live/form_component.ex b/lib/decentralised_book_index_web/live/author_live/form_component.ex index b8081de..f9c43ee 100644 --- a/lib/decentralised_book_index_web/live/author_live/form_component.ex +++ b/lib/decentralised_book_index_web/live/author_live/form_component.ex @@ -32,6 +32,18 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do /> <% end %> <%= if @form.source.type == :update do %> + <.input field={@form[:name]} type="text" label="Name" /> + <.input field={@form[:avatar_url]} type="text" label="Cover image url" /> + <.input + field={@form[:description]} + type="text" + label="Description" + /> + <.input + field={@form[:author_alias_registry_id]} + type="text" + label="Author alias registry" + /> <% end %> <:actions> @@ -63,7 +75,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do socket = socket |> put_flash(:info, "Author #{socket.assigns.form.source.type}d successfully") - |> push_patch(to: socket.assigns.patch) + |> push_redirect(to: patch_url(socket.assigns.action, author.id)) {:noreply, socket} @@ -90,4 +102,12 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do assign(socket, form: to_form(form)) end + + defp patch_url(action, author_id) do + case action do + :edit -> ~p"/authors/#{author_id}" + :new -> ~p"/authors" + _ -> ~p"/authors" + end + end end