|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
|
|
|
|
use DecentralisedBookIndexWeb, :live_component
|
|
|
|
|
|
|
|
|
|
alias DecentralisedBookIndex.Metadata
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def render(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
@ -101,7 +103,15 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
|
|
|
|
|
|
|
|
|
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
|
|
|
|
|
|
|
|
|
defp assign_form(%{assigns: %{author: author}} = socket) do
|
|
|
|
|
defp assign_form(%{assigns: %{author: author, alternative_author_id: alternative_author_id}} = socket) do
|
|
|
|
|
alias_id =
|
|
|
|
|
if alternative_author_id == nil do
|
|
|
|
|
nil
|
|
|
|
|
else
|
|
|
|
|
alternative_author = Metadata.get_author_by_id!(alternative_author_id)
|
|
|
|
|
alternative_author.author_alias_registry_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
form =
|
|
|
|
|
if author do
|
|
|
|
|
AshPhoenix.Form.for_update(author, :update,
|
|
|
|
@ -109,15 +119,26 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
|
|
|
|
|
actor: socket.assigns.current_user
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
form =
|
|
|
|
|
AshPhoenix.Form.for_create(Metadata.Author, :create,
|
|
|
|
|
as: "author",
|
|
|
|
|
actor: socket.assigns.current_user
|
|
|
|
|
)
|
|
|
|
|
|> set_author_alias_registry_id(alias_id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
assign(socket, form: to_form(form))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp set_author_alias_registry_id(form, alias_id) do
|
|
|
|
|
if alias_id != nil do
|
|
|
|
|
form
|
|
|
|
|
|> AshPhoenix.Form.update_params(&Map.put(&1, "author_alias_registry_id", alias_id))
|
|
|
|
|
else
|
|
|
|
|
form
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp patch_url(action, author_id) do
|
|
|
|
|
case action do
|
|
|
|
|
:edit -> ~p"/authors/#{author_id}"
|
|
|
|
|