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 f9c43ee..35e540e 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 @@ -48,6 +48,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do <:actions> <.button phx-disable-with="Saving...">Save Author + <.button phx-click="cancel" phx-target={@myself} class="me-auto">Cancel @@ -84,6 +85,17 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do end end + def handle_event("cancel", _params, socket) do + author = socket.assigns.author + author_id = if author == nil, do: nil, else: author.id + + socket = + socket + |> push_redirect(to: patch_url(socket.assigns.action, author_id)) + + {:noreply, socket} + end + defp notify_parent(msg), do: send(self(), {__MODULE__, msg}) defp assign_form(%{assigns: %{author: author}} = socket) do