Add the cancel button to Author's FormComponent.
This commit is contained in:
@@ -48,6 +48,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
|||||||
|
|
||||||
<:actions>
|
<:actions>
|
||||||
<.button phx-disable-with="Saving...">Save Author</.button>
|
<.button phx-disable-with="Saving...">Save Author</.button>
|
||||||
|
<.button phx-click="cancel" phx-target={@myself} class="me-auto">Cancel</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.simple_form>
|
</.simple_form>
|
||||||
</div>
|
</div>
|
||||||
@@ -84,6 +85,17 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
|||||||
end
|
end
|
||||||
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 notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||||
|
|
||||||
defp assign_form(%{assigns: %{author: author}} = socket) do
|
defp assign_form(%{assigns: %{author: author}} = socket) do
|
||||||
|
|||||||
Reference in New Issue
Block a user