diff --git a/lib/decentralised_book_index_web/live/book_live/form_component.ex b/lib/decentralised_book_index_web/live/book_live/form_component.ex
index b930228..de9b92c 100644
--- a/lib/decentralised_book_index_web/live/book_live/form_component.ex
+++ b/lib/decentralised_book_index_web/live/book_live/form_component.ex
@@ -55,7 +55,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
label="Description"
/>
<.bids_inputs form={@form} myself={@myself} />
- <.author_roles_inputs form={@form} myself={@myself} />
+ <.author_roles_inputs form={@form} myself={@myself} notify_component={@myself} />
<.input field={@form[:format]} type="text" label="Format" />
<.input
field={@form[:language]}
@@ -100,6 +100,21 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
notify_component={@myself}
/>
+
+ <.modal
+ :if={@select_author_open? == true}
+ id="select-author-modal"
+ show
+ on_cancel={JS.push("close-select-author", target: @myself)}
+ >
+ <.live_component
+ id="select-author"
+ module={SelectAuthor}
+ current_user={@current_user}
+ notify_component={@myself}
+ form_path={@form_path}
+ />
+
"""
end
@@ -213,6 +228,11 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
<.input field={author_roles_form[:author_id]} />
+ <.selected_author
+ author_form={author_roles_form[:author_id]}
+ notify_component={@notify_component}
+ form_path={author_roles_form.name}
+ />
|
@@ -279,6 +299,8 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
socket
|> assign(assigns)
|> assign(:select_publisher_open?, false)
+ |> assign(:select_author_open?, false)
+ |> assign(:form_path, nil)
|> assign_form()}
end
@@ -370,4 +392,37 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
{:noreply, socket}
end
+
+ def handle_event("select-author", %{"author" => author_id, "path" => path}, socket) do
+ socket =
+ socket
+ |> update(:form, fn form ->
+ form
+ |> AshPhoenix.Form.update_form(path, fn nested_form ->
+ params = Map.put(nested_form.params, "author_id", author_id)
+ AshPhoenix.Form.validate(nested_form, params)
+ end)
+ end)
+ |> assign(:select_author_open?, false)
+
+ {:noreply, socket}
+ end
+
+ def handle_event("open-select-author", %{"path" => path, "value" => value}, socket) do
+ socket =
+ socket
+ |> assign(:select_author_open?, true)
+ |> assign(:form_path, path)
+
+ {:noreply, socket}
+ end
+
+ def handle_event("close-select-author", _params, socket) do
+ socket =
+ socket
+ |> assign(:select_author_open?, false)
+ |> assign(:form_path, nil)
+
+ {:noreply, socket}
+ end
end
|