Add components to change the book edition.
This commit is contained in:
@@ -37,16 +37,13 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
<.input field={@form[:page_count]} type="number" label="Page count" />
|
||||
<div>
|
||||
<.input field={@form[:publisher_id]} type="text" label="Publisher" type="hidden" />
|
||||
<.selected_publisher
|
||||
publisher_form={@form[:publisher_id]}
|
||||
notify_component={@myself}
|
||||
/>
|
||||
<.selected_publisher publisher_form={@form[:publisher_id]} notify_component={@myself} />
|
||||
</div>
|
||||
<.input field={@form[:published]} type="date" label="Published" />
|
||||
<div>
|
||||
<.input field={@form[:book_editions_registry_id]} type="hidden" label="Book Editions" />
|
||||
<.selected_book_edition book_editions_registry_form={@form[:book_editions_registry_id]} notify_component={@myself} />
|
||||
</div>
|
||||
<.input
|
||||
field={@form[:published]}
|
||||
type="date"
|
||||
label="Published"
|
||||
/>
|
||||
<% end %>
|
||||
<%= if @form.source.type == :update do %>
|
||||
<.input field={@form[:title]} type="text" label="Title" />
|
||||
@@ -67,16 +64,13 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
<.input field={@form[:page_count]} type="number" label="Page count" />
|
||||
<div>
|
||||
<.input field={@form[:publisher_id]} type="text" label="Publisher" type="hidden" />
|
||||
<.selected_publisher
|
||||
publisher_form={@form[:publisher_id]}
|
||||
notify_component={@myself}
|
||||
/>
|
||||
<.selected_publisher publisher_form={@form[:publisher_id]} notify_component={@myself} />
|
||||
</div>
|
||||
<.input field={@form[:published]} type="date" label="Published" />
|
||||
<div>
|
||||
<.input field={@form[:book_editions_registry_id]} type="hidden" label="Book Editions" />
|
||||
<.selected_book_edition book_editions_registry_form={@form[:book_editions_registry_id]} notify_component={@myself} />
|
||||
</div>
|
||||
<.input
|
||||
field={@form[:published]}
|
||||
type="date"
|
||||
label="Published"
|
||||
/>
|
||||
<% end %>
|
||||
|
||||
<:actions>
|
||||
@@ -103,6 +97,20 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<.modal
|
||||
:if={@select_book_edition_open? == true}
|
||||
id="select-book-edition-modal"
|
||||
show
|
||||
on_cancel={JS.push("close-select-book-edition", target: @myself)}
|
||||
>
|
||||
<.live_component
|
||||
id="select-book-edition"
|
||||
module={SelectBookEdition}
|
||||
current_user={@current_user}
|
||||
notify_component={@myself}
|
||||
/>
|
||||
</.modal>
|
||||
|
||||
<.modal
|
||||
:if={@select_author_open? == true}
|
||||
id="select-author-modal"
|
||||
@@ -302,6 +310,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
|> assign(assigns)
|
||||
|> assign(:select_publisher_open?, false)
|
||||
|> assign(:select_author_open?, false)
|
||||
|> assign(:select_book_edition_open?, false)
|
||||
|> assign(:form_path, nil)
|
||||
|> assign_form()}
|
||||
end
|
||||
@@ -448,4 +457,32 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event("select-book-edition", %{"book-edition" => book_edition_id}, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> update(:form, fn form ->
|
||||
form
|
||||
|> AshPhoenix.Form.update_params(&Map.put(&1, "book_editions_registry_id", book_edition_id))
|
||||
end)
|
||||
|> assign(:select_book_edition_open?, false)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event("open-select-book-edition", _params, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(:select_book_edition_open?, true)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event("close-select-book-edition", _params, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(:select_book_edition_open?, false)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user